1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-23 01:43:28 +00:00
This commit is contained in:
Fastium 2022-06-12 12:10:57 +02:00
parent d33945ccf4
commit c121320a04
6 changed files with 125 additions and 71 deletions

View File

@ -1,14 +1,40 @@
package Game; package Game;
import Entity.Enemy;
import Text.TextEnemy;
public class Battle { public class Battle {
//TODO faire la logique du combat :$ private Enemy enemy;
/*
* les points
* réponses juste
* barre de vie
*/
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;
}
} }

View File

@ -4,6 +4,8 @@ package Main;
import java.util.Vector; import java.util.Vector;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.lwjgl.opencl.CLSampler;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import Control.Controller; import Control.Controller;
@ -85,7 +87,6 @@ public class PokeMudry extends PortableApplication {
sp.sm.zoom = 1; sp.sm.zoom = 1;
} }
return; return;
default: default:
break; break;
} }

View File

@ -32,33 +32,17 @@ public class ScreenBattle extends RenderingScreen{
private Battle battle; private Battle battle;
private TextEnemy textEnemy; private Enemy enemy;
private static int lineSpeech = 0;
private static String lineDialog = "";
int i = 0;
private int answer = 0;
@Override @Override
public void onInit() { public void onInit() {
textEnemy = new TextEnemy("enemi");
textEnemy.generateText();
//new battle game //new battle game
battle = new Battle(); battle = new Battle(enemy);
//display the question //display the question
generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK); 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); displayDialog(g);
System.out.println(battle.lineSpeech);
} }
@Override @Override
@ -95,8 +77,14 @@ public class ScreenBattle extends RenderingScreen{
g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0); g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0);
//dialog //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){ public void displayEnemy(Enemy e){
@ -107,42 +95,37 @@ public class ScreenBattle extends RenderingScreen{
//TODO afficher le joueur //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){ public void manage(Controller c){
if(PokeMudry.front_montant){ if(PokeMudry.front_montant){
if (c.keyStatus.get(Input.Keys.SPACE)){ System.out.println(battle.lineSpeech);
if(textEnemy.lines.get(lineSpeech).attackOn == false){
readNextLine();
} if( battle.getAttackOn() == false){
else if (c.keyStatus.get(Input.Keys.NUM_1)){ if (c.keyStatus.get(Input.Keys.SPACE)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){ System.out.println("in");
readNextLine(); battle.readNextLine();
answer = 1;
} }
} }
else if (c.keyStatus.get(Input.Keys.NUM_2)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine(); if(battle.getAttackOn() == true){
answer = 2; 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)){
else if (c.keyStatus.get(Input.Keys.NUM_3)){ battle.readNextLine();
if(textEnemy.lines.get(lineSpeech).attackOn == true){ battle.answer = 2;
readNextLine();
answer = 3;
} }
} else if (c.keyStatus.get(Input.Keys.NUM_3)){
else if (c.keyStatus.get(Input.Keys.NUM_4)){ battle.readNextLine();
if(textEnemy.lines.get(lineSpeech).attackOn == true){ battle.answer = 3;
readNextLine(); }
answer = 4; else if (c.keyStatus.get(Input.Keys.NUM_4)){
battle.readNextLine();
battle.answer = 4;
} }
} }
@ -151,7 +134,7 @@ public class ScreenBattle extends RenderingScreen{
} }
}
} }
} }

View File

@ -20,7 +20,7 @@ public class ScreenPlayer {
} }
public void render(GdxGraphics g){ public void render(GdxGraphics g){
sb.displayEnemy(e); sb.setEnemy(e);
sm.setPlayer(p); sm.setPlayer(p);
screenManager.render(g); screenManager.render(g);
} }

View File

@ -11,23 +11,33 @@ public class FightData {
private File file; private File file;
private static final String REGEX = ","; private static final String REGEX = ",";
public int nbre_line =0;
public FightData(String name) { public FightData(String name) {
file = new File("./resources/Battle/Fight/" + name + ".csv"); file = new File("./resources/Battle/Fight/" + name + ".csv");
} }
public void readFile() { public void readFile() {
Attack attack; Attack attack;
String line = ""; String line = "";
try { try {
FileReader f = new FileReader(file); FileReader f = new FileReader(file);
BufferedReader bf = new BufferedReader(f); BufferedReader bf = new BufferedReader(f);
//add the line in the vector attacks of attack
line = bf.readLine(); line = bf.readLine();
while(line != null){ while(line != null){
String[] a = line.split(REGEX);//change the regex if it is another 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])); attack = new Attack(a[0], a[1], a[2], a[3], a[4], Float.valueOf(a[5]));
attacks.add(attack); attacks.add(attack);
line = bf.readLine(); line = bf.readLine();
//add line
nbre_line++;
} }
bf.close(); bf.close();
@ -35,10 +45,6 @@ public class FightData {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
//return the vector with all attaks of one enemi //return the vector with all attaks of one enemi

View File

@ -1,6 +1,7 @@
package Text; package Text;
import java.util.Vector; import java.util.Vector;
import java.util.Random;
public class TextEnemy { public class TextEnemy {
public FightData fightData; public FightData fightData;
@ -8,12 +9,18 @@ public class TextEnemy {
public Vector<Line> lines = new Vector<Line>(); public Vector<Line> lines = new Vector<Line>();
public int[] orderAnswer;
public static void main(String[] args) { public static void main(String[] args) {
TextEnemy t = new TextEnemy("enemi"); TextEnemy t = new TextEnemy("enemi");
t.generateText(); t.generateText();
for(Line l : t.lines) { for(Line l : t.lines) {
System.out.println(l.line); 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<t.length){
System.out.println(i);
t[i] = ran.nextInt(max_val) + min_val;
for(int j : t){
if(t[i] == j){
t[i] = ran.nextInt(max_val) + min_val;
}
else{
i++;
}
}
}
return t;
}
public void generateText(){ public void generateText(){
int i =1; int i =1;
//introduction line //introduction line
lines.add(new Line(speechData.getSpeechs(0), false)); lines.add(new Line(speechData.getSpeechs(0), false));
orderAnswer = randomGenerate(fightData.nbre_line);
for(int j=0; j<4;j++){ for(int j=0; j<4;j++){
//generate the order of the answer
//attack and answer (number on vector : 1-4) //attack and answer (number on vector : 1-4)
lines.add(new Line( lines.add(new Line(
speechData.getSpeechs(i++) + fightData.getAttack(j).attack + "? ("+fightData.getAttack(j).xp+ ") " + "\n" + speechData.getSpeechs(i++) + fightData.getAttack(orderAnswer[j]).attack + " ? ("+fightData.getAttack(orderAnswer[j]).xp+ ") " + "\n" +
fightData.getAttack(j).answer1 + "\n" + fightData.getAttack(orderAnswer[j]).answer1 + "\n" +
fightData.getAttack(j).answer2 + "\n" + fightData.getAttack(orderAnswer[j]).answer2 + "\n" +
fightData.getAttack(j).answer3 + "\n" + fightData.getAttack(orderAnswer[j]).answer3 + "\n" +
fightData.getAttack(j).answer4, true)); fightData.getAttack(orderAnswer[j]).answer4, true));
// TODO mélanger les attaques aléatoirement // TODO mélanger les attaques aléatoirement
} }
//finish (win and death) //finish (win and death)