diff --git a/resources/Battle/Fight/enemi.csv b/resources/Battle/Fight/enemi.csv index 253ef70..17a9151 100644 --- a/resources/Battle/Fight/enemi.csv +++ b/resources/Battle/Fight/enemi.csv @@ -1,7 +1,7 @@ -attaque,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,1 -df,sdfs,dfs,df,sdf,10 -sdf,sdf,sd,sdf,sdfs,3 -sdf,sdf,fsd,sdf,dfs,45 -sd,fsdf,fsd,f,dfsd,4 -sdfsf,df,sdf,sdf,fsdf,6 -sdf,sdf,sdf,sdfs,df,3 +attaque1,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,1 +attaque2,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,10 +attaque3,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,3 +attaque4,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,45 +attaque5,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,4 +attaque6,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,6 +attaque7,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,3 diff --git a/resources/Battle/Speech/enemi.txt b/resources/Battle/Speech/enemi.txt index ffb0ac0..0ae5268 100644 --- a/resources/Battle/Speech/enemi.txt +++ b/resources/Battle/Speech/enemi.txt @@ -1,7 +1,7 @@ introduction text -attack 1 -attack 2 -attack 3 -attack 4 +attack 1 : +attack 2 : +attack 3 : +attack 4 : death win \ No newline at end of file diff --git a/src/Entity/Enemy.java b/src/Entity/Enemy.java index cf16b62..a89a5c8 100644 --- a/src/Entity/Enemy.java +++ b/src/Entity/Enemy.java @@ -1,19 +1,16 @@ package Entity; -import com.badlogic.gdx.math.Vector2; - -import Text.TextEnemy; +import com.badlogic.gdx.math.Vector2; public class Enemy extends Character{ private String map; - public TextEnemy textEnemy; + public Enemy(String name, int x, int y, String img, String map) { super(name, x, y, img); //generate his text - this.textEnemy = new TextEnemy("enemi"); //TODO should be name - textEnemy.generateText(); + this.map = map; turn(Character.Direction.DOWN); diff --git a/src/Game/Battle.java b/src/Game/Battle.java new file mode 100644 index 0000000..c71fb08 --- /dev/null +++ b/src/Game/Battle.java @@ -0,0 +1,12 @@ +package Game; + +public class Battle { + + //TODO faire la logique du combat :$ + /* + * les points + * réponses juste + * barre de vie + */ + +} diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index 3ee7029..d8f373a 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -1,9 +1,8 @@ package Screen; -import Main.Settings; - import ch.hevs.gdx2d.components.screen_management.RenderingScreen; import ch.hevs.gdx2d.lib.GdxGraphics; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.files.FileHandle; @@ -11,45 +10,65 @@ 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 Text.Line; +import Text.TextEnemy; +import Main.Settings; 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 boolean attackOn; - private int numAttack =0; - private BitmapFont optimus40; + private TextEnemy textEnemy; + private int lineSpeech = 0; + private String lineDialog = ""; + + private int answer = 0; + + + + @Override public void onInit() { - //display the question - generateFont("resources//font//OptimusPrinceps.ttf", optimus40, 20, Color.BLACK); + textEnemy = new TextEnemy("enemi"); + textEnemy.generateText(); + //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); - g.drawStringCentered(g.getScreenHeight()/2, "attack", optimus40); - g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0); + displayDialog(g); + + } @Override public void dispose() { + optimus40.dispose(); } - public void generateFont(String file, BitmapFont bitmapFont, int height, Color c ){ + public void generateFont(String file, int height, Color c ){ + //Generate font with the file .ttf FileHandle fileHandle = Gdx.files.internal(file); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); @@ -60,22 +79,62 @@ public class ScreenBattle extends RenderingScreen{ } - public void displayEnemy(Enemy e){ - // stock his speech + public void displayDialog(GdxGraphics g){ + //dialog background + g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, 1600, HEIGHT_DIALOG, 0); - //display the person + //dialog + g.drawString(15, 245 ,lineDialog , optimus40); + + } + + public void displayPlayer(Player p){ + //TODO afficher le joueur + } + + public void displayEnemy(Enemy e){ + //TODO display the person } public void readNextLine(){ - //display the speech - + //display the speech and change line + lineDialog = textEnemy.lines.get(lineSpeech).line; + lineSpeech++; + } public void manage(Controller c){ if (c.keyStatus.get(Input.Keys.SPACE)){ - readNextLine(); + if(textEnemy.lines.get(lineSpeech).attackOn == false){ + 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; + } + } + } diff --git a/src/Text/FightData.java b/src/Text/FightData.java index 1575dfe..f5a9e5d 100644 --- a/src/Text/FightData.java +++ b/src/Text/FightData.java @@ -11,16 +11,6 @@ public class FightData { private File file; private static final String REGEX = ","; - /* - public static void main(String[] args) { - FightData d = new FightData("enemi"); - d.readFile(); - for(Attack a : d.attacks){ - System.out.println(a); - } - } - */ - public FightData(String name) { file = new File("./resources/Battle/Fight/" + name + ".csv"); } @@ -42,9 +32,12 @@ public class FightData { bf.close(); - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); - } + } + + + } diff --git a/src/Text/Line.java b/src/Text/Line.java new file mode 100644 index 0000000..535acd5 --- /dev/null +++ b/src/Text/Line.java @@ -0,0 +1,12 @@ +package Text; + +public class Line { + public String line; + public boolean attackOn; + + Line( String line, boolean attackOn){ + this.line = line; + this.attackOn = attackOn; + } + +} diff --git a/src/Text/SpeechData.java b/src/Text/SpeechData.java index abf5462..1597bba 100644 --- a/src/Text/SpeechData.java +++ b/src/Text/SpeechData.java @@ -12,7 +12,7 @@ public class SpeechData { public SpeechData(String name){ - file = new File("./resources/Battle/Fight/" + name + ".csv"); + file = new File("./resources/Battle/Speech/" + name + ".txt"); } public void readFile() { diff --git a/src/Text/TextEnemy.java b/src/Text/TextEnemy.java index c370f29..3df83eb 100644 --- a/src/Text/TextEnemy.java +++ b/src/Text/TextEnemy.java @@ -6,7 +6,16 @@ public class TextEnemy { public FightData fightData; public SpeechData speechData; - Vector line = new Vector(); + public Vector lines = new Vector(); + + public static void main(String[] args) { + TextEnemy t = new TextEnemy("enemi"); + t.generateText(); + for(Line l : t.lines) { + System.out.println(l.line); + } + + } public TextEnemy(String name){ //generate the vector of fight @@ -20,33 +29,24 @@ public class TextEnemy { } public void generateText(){ - int i =0; + int i =1; //introduction line - line.add(new Line(speechData.getSpeechs(i++), false)); - - for(int j=0; i<4;i++){ + lines.add(new Line(speechData.getSpeechs(0), false)); + for(int j=0; j<4;j++){ //attack and answer (number on vector : 1-4) - line.add(new Line( - speechData.getSpeechs(i++) + fightData.getAttack(j).attack + "? ("+fightData.getAttack(j).xp+ ") " + "\n" + - fightData.getAttack(j).answer1 + "\n" + - fightData.getAttack(j).answer2 + "\n" + - fightData.getAttack(j).answer3 + "\n" + - fightData.getAttack(j).answer4, true )); + lines.add(new Line( + speechData.getSpeechs(i++) + fightData.getAttack(j).attack + "? ("+fightData.getAttack(j).xp+ ") " + "\n" + + fightData.getAttack(j).answer1 + "\n" + + fightData.getAttack(j).answer2 + "\n" + + fightData.getAttack(j).answer3 + "\n" + + fightData.getAttack(j).answer4, true)); // TODO mélanger les attaques aléatoirement } //finish (win and death) - line.add(new Line(speechData.getSpeechs(i++), false)); - line.add(new Line(speechData.getSpeechs(i++), false)); + lines.add(new Line(speechData.getSpeechs(5), false)); + lines.add(new Line(speechData.getSpeechs(6), false)); } } -class Line { - String line; - boolean attackOn; - Line( String line, boolean attackOn){ - this.line = line; - this.attackOn = attackOn; - } -} diff --git a/src/testYann.java b/src/testYann.java index 9ea062c..afa7962 100644 --- a/src/testYann.java +++ b/src/testYann.java @@ -22,7 +22,7 @@ public class testYann extends PortableApplication{ } testYann(){ - super(800, 800); + super( 800, 800); } @Override @@ -36,6 +36,13 @@ public class testYann extends PortableApplication{ @Override public void onGraphicRender(GdxGraphics g) { s.render(g); + ((ScreenBattle) s.getActiveScreen()).manage(controller); + } + + @Override + public void onDispose() { + // TODO Auto-generated method stub + super.onDispose(); } @Override