1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-30 04:33:27 +00:00

Merge pull request #16 from Klagarge/battle-game

Master
This commit is contained in:
Rémi Heredero 2022-06-12 14:33:33 +02:00 committed by GitHub
commit 7f7642d728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 223 additions and 139 deletions

View File

@ -1,12 +1,48 @@
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 TextEnemy textEnemy;
* réponses juste private int lineSpeech;
* barre de vie
*/ 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;
}
} }

View File

@ -2,6 +2,10 @@ package Main;
import java.util.Vector; import java.util.Vector;
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;
import Entity.Enemy; import Entity.Enemy;
@ -18,6 +22,8 @@ public class PokeMudry extends PortableApplication {
private static Vector<Enemy> enemies = new Vector<>(); private static Vector<Enemy> enemies = new Vector<>();
private static Vector<Entity> entities = new Vector<>(); private static Vector<Entity> entities = new Vector<>();
public static boolean front_montant = false;
public static void main(String[] args) { public static void main(String[] args) {
new PokeMudry(); new PokeMudry();
@ -51,6 +57,10 @@ public class PokeMudry extends PortableApplication {
@Override @Override
public void onGraphicRender(GdxGraphics g) { public void onGraphicRender(GdxGraphics g) {
g.clear(); 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); boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class);
@ -66,7 +76,6 @@ public class PokeMudry extends PortableApplication {
// Switch screen // Switch screen
if (sp.p.frontOfEnemy && onMapScreen){ if (sp.p.frontOfEnemy && onMapScreen){
sp.e = sp.p.lastEnemy; sp.e = sp.p.lastEnemy;
System.out.println("switch screen");
sp.screenManager.activateNextScreen(); sp.screenManager.activateNextScreen();
g.resetCamera(); g.resetCamera();
} }
@ -77,7 +86,7 @@ public class PokeMudry extends PortableApplication {
@Override @Override
public void onKeyDown(int keycode) { public void onKeyDown(int keycode) {
super.onKeyDown(keycode); super.onKeyDown(keycode);
front_montant = true;
switch (keycode) { switch (keycode) {
case Input.Keys.Z: case Input.Keys.Z:
if (sp.sm.zoom == 1.0) { if (sp.sm.zoom == 1.0) {
@ -86,7 +95,6 @@ public class PokeMudry extends PortableApplication {
sp.sm.zoom = 1; sp.sm.zoom = 1;
} }
return; return;
default: default:
break; break;
} }
@ -96,6 +104,7 @@ public class PokeMudry extends PortableApplication {
@Override @Override
public void onKeyUp(int keycode) { public void onKeyUp(int keycode) {
super.onKeyUp(keycode); super.onKeyUp(keycode);
front_montant = false;
controller.keyStatus.put(keycode, false); controller.keyStatus.put(keycode, false);
sp.screenManager.getActiveScreen().onKeyDown(keycode); sp.screenManager.getActiveScreen().onKeyDown(keycode);
} }

View File

@ -10,14 +10,15 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import Control.Controller; import Control.Controller;
import Entity.Enemy; import Entity.Enemy;
import Entity.Player; import Entity.Player;
import Game.Battle;
import Text.Line; import Text.Line;
import Text.TextEnemy; import Text.TextEnemy;
import Main.PokeMudry;
import Main.Settings; import Main.Settings;
public class ScreenBattle extends RenderingScreen{ public class ScreenBattle extends RenderingScreen{
@ -25,51 +26,38 @@ public class ScreenBattle extends RenderingScreen{
private static int EDGE = 10; private static int EDGE = 10;
private static int HEIGHT_DIALOG = Settings.SIDE / 3; private static int HEIGHT_DIALOG = Settings.SIDE / 3;
private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE; private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE;
private Enemy e;
private boolean attackOn;
private int numAttack =0;
private BitmapFont optimus40; private BitmapFont optimus40;
private TextEnemy textEnemy; private Battle battle;
private int lineSpeech = 0;
private String lineDialog = "";
private int answer = 0;
private Enemy enemy;
@Override @Override
public void onInit() { public void onInit() {
//new battle game
textEnemy = new TextEnemy("enemi"); battle = new Battle(enemy);
textEnemy.generateText();
//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();
} }
@Override @Override
public void onGraphicRender(GdxGraphics g) { public void onGraphicRender(GdxGraphics g) {
g.clear(Color.BLACK); g.clear(Color.BLACK);
displayDialog(g); displayDialog(g);
System.out.println("render: " + battle.getLineSpeech());
} }
@Override @Override
public void dispose() { public void dispose() {
optimus40.dispose(); optimus40.dispose();
} }
public void generateFont(String file, int height, Color c ){ public void generateFont(String file, int height, Color c ){
@ -86,65 +74,67 @@ public class ScreenBattle extends RenderingScreen{
public void displayDialog(GdxGraphics g){ public void displayDialog(GdxGraphics g){
//dialog background //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 //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){ public void displayEnemy(Enemy e){
// stock his speech // TODO affficher l'enemi
} }
public void displayPlayer(Player p){ public void displayPlayer(Player p){
//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){
System.out.println("manage: " + battle.getLineSpeech());
if( battle.getAttackOn() == false){
if (c.keyStatus.get(Input.Keys.SPACE)){ if (c.keyStatus.get(Input.Keys.SPACE)){
if(textEnemy.lines.get(lineSpeech).attackOn == false){ System.out.println("in");
readNextLine(); battle.readNextLine();
} }
} }
if(battle.getAttackOn() == true){
if (c.keyStatus.get(Input.Keys.NUM_1)){ if (c.keyStatus.get(Input.Keys.NUM_1)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){ System.out.println("je sui dansakjshfljkahflkasjhfdlkajshflkajshfdlkasjdhfalsdkjfh123412341234");
readNextLine(); battle.readNextLine();
answer = 1; battle.answer = 1;
} }
else if (c.keyStatus.get(Input.Keys.NUM_2)){
battle.readNextLine();
battle.answer = 2;
} }
if (c.keyStatus.get(Input.Keys.NUM_2)){ else if (c.keyStatus.get(Input.Keys.NUM_3)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){ battle.readNextLine();
readNextLine(); battle.answer = 3;
answer = 2;
} }
} else if (c.keyStatus.get(Input.Keys.NUM_4)){
if (c.keyStatus.get(Input.Keys.NUM_3)){ battle.readNextLine();
if(textEnemy.lines.get(lineSpeech).attackOn == true){ battle.answer = 4;
readNextLine();
answer = 3;
}
}
if (c.keyStatus.get(Input.Keys.NUM_4)){
if(textEnemy.lines.get(lineSpeech).attackOn == false){
readNextLine();
answer = 4;
} }
} }
//mettre le front à false jusqu'à ce que le bouton soit relâché
PokeMudry.front_montant = false;
} }
}
} }

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,13 +9,19 @@ 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);
} }
} }
public TextEnemy(String name){ public TextEnemy(String name){
@ -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<nbre ; j++){
t[j] = -1;
}
//assign 4 different random value between 0 and max
while(i< nbre){
x = r.nextInt(max);
//test if the value is valid
for(int j : t){
if(x==j){
same = true;
break;
}
}
//do again the loop
if(same){
same = false;
}
else{
t[i] = x;
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)

View File

@ -1,65 +1,54 @@
import java.util.Map; import java.util.Random;
import java.util.TreeMap;
import Control.Controller;
import Entity.Enemy;
import Screen.ScreenBattle;
import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.ScreenManager;
public class testYann extends PortableApplication{
private ScreenManager s = new ScreenManager();
public Map<Integer, Boolean> keyStatus = new TreeMap<Integer, Boolean>();
double zoom;
Controller controller = new Controller();
class testYann{
public static void main(String[] args) { 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<nbre ; j++){
a[j] = -1;
} }
testYann(){ while(i< nbre){
super( 800, 800); x = r.nextInt(max);
} System.out.println(x);
for(int j : a){
@Override if(x==j){
public void onInit() { same = true;
s.registerScreen(ScreenBattle.class);
Enemy e = new Enemy("enemi", 50, 50, "resources//lumberjack_sheet32.png", "desert");
}
@Override
public void onGraphicRender(GdxGraphics g) {
s.render(g);
}
@Override
public void onDispose() {
// TODO Auto-generated method stub
super.onDispose();
}
@Override
public void onKeyUp(int keycode) {
super.onKeyUp(keycode);
controller.keyStatus.put(keycode, false);
}
@Override
public void onKeyDown(int keycode) {
super.onKeyDown(keycode);
switch (keycode) {
default:
break; break;
} }
controller.keyStatus.put(keycode, true);
} }
if(same){
same = false;
}
else{
a[i] = x;
i++;
}
}
System.out.println("\n");
for(int j : a){
System.out.println(j);
}
}
} }