diff --git a/src/Game/Battle.java b/src/Game/Battle.java index b70f493..cdad210 100644 --- a/src/Game/Battle.java +++ b/src/Game/Battle.java @@ -1,14 +1,40 @@ package Game; +import Entity.Enemy; +import Text.TextEnemy; + public class Battle { - //TODO faire la logique du combat :$ - /* - * les points - * réponses juste - * barre de vie - */ + private Enemy enemy; + TextEnemy textEnemy; + public int lineSpeech = 0; + + public int answer = 0; + private boolean c; + + public Battle(Enemy enemy){ + this.enemy = enemy; + textEnemy = new TextEnemy("enemi"); // should be enemy.name + textEnemy.generateText(); + + //initialize the first line + System.out.println("lll : "+ getLine()); + + } + + public void readNextLine(){ + //change line + lineSpeech++; + } + + public boolean getAttackOn(){ + return textEnemy.lines.get(lineSpeech).attackOn; + } + + public String getLine(){ + return textEnemy.lines.get(lineSpeech).line; + } } diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 55833c5..44d4271 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -4,6 +4,8 @@ package Main; import java.util.Vector; import java.util.Map.Entry; +import org.lwjgl.opencl.CLSampler; + import com.badlogic.gdx.Input; import Control.Controller; @@ -85,7 +87,6 @@ public class PokeMudry extends PortableApplication { sp.sm.zoom = 1; } return; - default: break; } diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index d98fa5b..6d489b1 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -32,33 +32,17 @@ public class ScreenBattle extends RenderingScreen{ private Battle battle; - private TextEnemy textEnemy; - private static int lineSpeech = 0; - private static String lineDialog = ""; - int i = 0; - - private int answer = 0; - - + private Enemy enemy; @Override public void onInit() { - - textEnemy = new TextEnemy("enemi"); - textEnemy.generateText(); - //new battle game - battle = new Battle(); - - + battle = new Battle(enemy); + //display the question generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK); - - //initialize the first line - readNextLine(); - System.out.println(1); } @@ -68,9 +52,7 @@ public class ScreenBattle extends RenderingScreen{ displayDialog(g); - - - + System.out.println(battle.lineSpeech); } @Override @@ -95,8 +77,14 @@ public class ScreenBattle extends RenderingScreen{ g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0); //dialog - g.drawString(15, 245 ,lineDialog , optimus40); + g.drawString(15, 245 ,battle.getLine() , optimus40); + + + } + + public void setEnemy(Enemy enemy){ + this.enemy = enemy; } public void displayEnemy(Enemy e){ @@ -107,42 +95,37 @@ public class ScreenBattle extends RenderingScreen{ //TODO afficher le joueur } - public void readNextLine(){ - //display the speech and change line - lineDialog = textEnemy.lines.get(lineSpeech).line; - lineSpeech++; - - } - - public void manage(Controller c){ if(PokeMudry.front_montant){ - if (c.keyStatus.get(Input.Keys.SPACE)){ - if(textEnemy.lines.get(lineSpeech).attackOn == false){ - readNextLine(); - } - else if (c.keyStatus.get(Input.Keys.NUM_1)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 1; + System.out.println(battle.lineSpeech); + + + if( battle.getAttackOn() == false){ + if (c.keyStatus.get(Input.Keys.SPACE)){ + System.out.println("in"); + battle.readNextLine(); } } - else if (c.keyStatus.get(Input.Keys.NUM_2)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 2; + + + if(battle.getAttackOn() == true){ + if (c.keyStatus.get(Input.Keys.NUM_1)){ + System.out.println("je sui dansakjshfljkahflkasjhfdlkajshflkajshfdlkasjdhfalsdkjfh123412341234"); + battle.readNextLine(); + battle.answer = 1; } - } - else if (c.keyStatus.get(Input.Keys.NUM_3)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 3; + else if (c.keyStatus.get(Input.Keys.NUM_2)){ + battle.readNextLine(); + battle.answer = 2; } - } - else if (c.keyStatus.get(Input.Keys.NUM_4)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 4; + else if (c.keyStatus.get(Input.Keys.NUM_3)){ + battle.readNextLine(); + battle.answer = 3; + } + else if (c.keyStatus.get(Input.Keys.NUM_4)){ + battle.readNextLine(); + battle.answer = 4; + } } @@ -151,7 +134,7 @@ public class ScreenBattle extends RenderingScreen{ } - } + } } diff --git a/src/Screen/ScreenPlayer.java b/src/Screen/ScreenPlayer.java index 7fb0dae..a445491 100644 --- a/src/Screen/ScreenPlayer.java +++ b/src/Screen/ScreenPlayer.java @@ -20,7 +20,7 @@ public class ScreenPlayer { } public void render(GdxGraphics g){ - sb.displayEnemy(e); + sb.setEnemy(e); sm.setPlayer(p); screenManager.render(g); } diff --git a/src/Text/FightData.java b/src/Text/FightData.java index f5a9e5d..88f8b48 100644 --- a/src/Text/FightData.java +++ b/src/Text/FightData.java @@ -11,23 +11,33 @@ public class FightData { private File file; private static final String REGEX = ","; + public int nbre_line =0; + public FightData(String name) { file = new File("./resources/Battle/Fight/" + name + ".csv"); } + + public void readFile() { Attack attack; String line = ""; + try { FileReader f = new FileReader(file); BufferedReader bf = new BufferedReader(f); + + + //add the line in the vector attacks of attack line = bf.readLine(); while(line != null){ String[] a = line.split(REGEX);//change the regex if it is another attack = new Attack(a[0], a[1], a[2], a[3], a[4], Float.valueOf(a[5])); attacks.add(attack); line = bf.readLine(); + //add line + nbre_line++; } bf.close(); @@ -35,10 +45,6 @@ public class FightData { } catch (Exception e) { e.printStackTrace(); } - - - - } //return the vector with all attaks of one enemi diff --git a/src/Text/TextEnemy.java b/src/Text/TextEnemy.java index 3df83eb..1d6e313 100644 --- a/src/Text/TextEnemy.java +++ b/src/Text/TextEnemy.java @@ -1,6 +1,7 @@ package Text; import java.util.Vector; +import java.util.Random; public class TextEnemy { public FightData fightData; @@ -8,12 +9,18 @@ public class TextEnemy { public Vector lines = new Vector(); + public int[] orderAnswer; + public static void main(String[] args) { + TextEnemy t = new TextEnemy("enemi"); + t.generateText(); + for(Line l : t.lines) { System.out.println(l.line); } + } @@ -28,18 +35,49 @@ public class TextEnemy { } + int[] randomGenerate(int max_val){ + int min_val = 0; + int x; + int[] t = new int[max_val-1]; + Random ran = new Random(); + + int i=0; + + + while(i