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;
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;
}
}

View File

@ -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;
}

View File

@ -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){
System.out.println(battle.lineSpeech);
if( battle.getAttackOn() == false){
if (c.keyStatus.get(Input.Keys.SPACE)){
if(textEnemy.lines.get(lineSpeech).attackOn == false){
readNextLine();
System.out.println("in");
battle.readNextLine();
}
else if (c.keyStatus.get(Input.Keys.NUM_1)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 1;
}
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)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 2;
}
battle.readNextLine();
battle.answer = 2;
}
else if (c.keyStatus.get(Input.Keys.NUM_3)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 3;
}
battle.readNextLine();
battle.answer = 3;
}
else if (c.keyStatus.get(Input.Keys.NUM_4)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 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){
sb.displayEnemy(e);
sb.setEnemy(e);
sm.setPlayer(p);
screenManager.render(g);
}

View File

@ -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

View File

@ -1,6 +1,7 @@
package Text;
import java.util.Vector;
import java.util.Random;
public class TextEnemy {
public FightData fightData;
@ -8,13 +9,19 @@ public class TextEnemy {
public Vector<Line> lines = new Vector<Line>();
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);
}
}
public TextEnemy(String name){
@ -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(){
int i =1;
//introduction line
lines.add(new Line(speechData.getSpeechs(0), false));
orderAnswer = randomGenerate(fightData.nbre_line);
for(int j=0; j<4;j++){
//generate the order of the answer
//attack and answer (number on vector : 1-4)
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));
speechData.getSpeechs(i++) + fightData.getAttack(orderAnswer[j]).attack + " ? ("+fightData.getAttack(orderAnswer[j]).xp+ ") " + "\n" +
fightData.getAttack(orderAnswer[j]).answer1 + "\n" +
fightData.getAttack(orderAnswer[j]).answer2 + "\n" +
fightData.getAttack(orderAnswer[j]).answer3 + "\n" +
fightData.getAttack(orderAnswer[j]).answer4, true));
// TODO mélanger les attaques aléatoirement
}
//finish (win and death)