diff --git a/src/Game/Battle.java b/src/Game/Battle.java index c71fb08..8dbfc6b 100644 --- a/src/Game/Battle.java +++ b/src/Game/Battle.java @@ -1,12 +1,48 @@ 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; + private int lineSpeech; + + public int answer; + + + public Battle(Enemy enemy){ + this.enemy = enemy; + textEnemy = new TextEnemy("enemi"); // should be enemy.name + textEnemy.generateText(); + + lineSpeech = 0; + answer = 0; + + //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; + } + + public int getLineSpeech() { + return lineSpeech; + } + } diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index da6063b..7fe5f30 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -2,6 +2,10 @@ package Main; import java.util.Vector; +import java.util.Map.Entry; + +import org.lwjgl.opencl.CLSampler; + import com.badlogic.gdx.Input; import Control.Controller; import Entity.Enemy; @@ -18,6 +22,8 @@ public class PokeMudry extends PortableApplication { private static Vector enemies = new Vector<>(); private static Vector entities = new Vector<>(); + public static boolean front_montant = false; + public static void main(String[] args) { new PokeMudry(); @@ -51,6 +57,10 @@ public class PokeMudry extends PortableApplication { @Override public void onGraphicRender(GdxGraphics g) { g.clear(); + sp.p.manageEntity(sp.sm, controller); + sp.sb.manage(controller); + sp.render(g); + //System.out.println(ScreenMap.class); boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); @@ -66,7 +76,6 @@ public class PokeMudry extends PortableApplication { // Switch screen if (sp.p.frontOfEnemy && onMapScreen){ sp.e = sp.p.lastEnemy; - System.out.println("switch screen"); sp.screenManager.activateNextScreen(); g.resetCamera(); } @@ -77,7 +86,7 @@ public class PokeMudry extends PortableApplication { @Override public void onKeyDown(int keycode) { super.onKeyDown(keycode); - + front_montant = true; switch (keycode) { case Input.Keys.Z: if (sp.sm.zoom == 1.0) { @@ -86,7 +95,6 @@ public class PokeMudry extends PortableApplication { sp.sm.zoom = 1; } return; - default: break; } @@ -96,6 +104,7 @@ public class PokeMudry extends PortableApplication { @Override public void onKeyUp(int keycode) { super.onKeyUp(keycode); + front_montant = false; controller.keyStatus.put(keycode, false); sp.screenManager.getActiveScreen().onKeyDown(keycode); } diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index e2eb25b..9d8e94f 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -10,14 +10,15 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; -import com.badlogic.gdx.scenes.scene2d.ui.Dialog; import com.badlogic.gdx.utils.Align; import Control.Controller; import Entity.Enemy; import Entity.Player; +import Game.Battle; import Text.Line; import Text.TextEnemy; +import Main.PokeMudry; import Main.Settings; public class ScreenBattle extends RenderingScreen{ @@ -25,51 +26,38 @@ public class ScreenBattle extends RenderingScreen{ private static int EDGE = 10; private static int HEIGHT_DIALOG = Settings.SIDE / 3; private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE; - private Enemy e; - - private boolean attackOn; - private int numAttack =0; private BitmapFont optimus40; - private TextEnemy textEnemy; - private int lineSpeech = 0; - private String lineDialog = ""; - - private int answer = 0; - + private Battle battle; + private Enemy enemy; @Override public void onInit() { - - textEnemy = new TextEnemy("enemi"); - textEnemy.generateText(); - + //new battle game + battle = new Battle(enemy); + //display the question generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK); - - //initialize the first line - readNextLine(); } + @Override public void onGraphicRender(GdxGraphics g) { g.clear(Color.BLACK); displayDialog(g); - + System.out.println("render: " + battle.getLineSpeech()); } @Override public void dispose() { - optimus40.dispose(); - } public void generateFont(String file, int height, Color c ){ @@ -86,65 +74,67 @@ public class ScreenBattle extends RenderingScreen{ public void displayDialog(GdxGraphics g){ //dialog background - g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, 1600, HEIGHT_DIALOG, 0); + 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 e) { - this.e = e; + + public void setEnemy(Enemy enemy){ + this.enemy = enemy; } public void displayEnemy(Enemy e){ - // stock his speech - } + // TODO affficher l'enemi + } public void displayPlayer(Player p){ - //TODO afficher le joueur - } - - public void readNextLine(){ - //display the speech and change line - lineDialog = textEnemy.lines.get(lineSpeech).line; - lineSpeech++; - + //TODO afficher le joueur } public void manage(Controller c){ - if (c.keyStatus.get(Input.Keys.SPACE)){ - if(textEnemy.lines.get(lineSpeech).attackOn == false){ - readNextLine(); + if(PokeMudry.front_montant){ + System.out.println("manage: " + battle.getLineSpeech()); + + + if( battle.getAttackOn() == false){ + if (c.keyStatus.get(Input.Keys.SPACE)){ + System.out.println("in"); + battle.readNextLine(); + } } - } - if (c.keyStatus.get(Input.Keys.NUM_1)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 1; - } - } - if (c.keyStatus.get(Input.Keys.NUM_2)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 2; - } - } - if (c.keyStatus.get(Input.Keys.NUM_3)){ - if(textEnemy.lines.get(lineSpeech).attackOn == true){ - readNextLine(); - answer = 3; - } - } - if (c.keyStatus.get(Input.Keys.NUM_4)){ - if(textEnemy.lines.get(lineSpeech).attackOn == false){ - readNextLine(); - answer = 4; + + + 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_2)){ + battle.readNextLine(); + battle.answer = 2; + } + 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; + + } } + + //mettre le front à false jusqu'à ce que le bouton soit relâché + PokeMudry.front_montant = false; } + + + } - - - - } 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..53b0d52 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,65 @@ public class TextEnemy { } + int[] randomGenerate(int max_val){ + int max = 8-1; + Random r = new Random(); + + int nbre = 4; + + int[] t = new int[nbre]; + int x; + int i=0; + boolean same = false; + + // initialize array at -1 + for(int j=0; j keyStatus = new TreeMap(); - double zoom; - Controller controller = new Controller(); - + +class testYann{ public static void main(String[] args) { - new testYann(); + int max = 8-1; + Random r = new Random(); + + int nbre = 4; + + int[] a = new int[nbre]; + int x; + int i=0; + boolean same = false; + + for(int j=0; j