1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-26 19:13: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;
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;
}
}

View File

@ -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<Enemy> enemies = new Vector<>();
private static Vector<Entity> 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);
}

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

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,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(){
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)

View File

@ -1,65 +1,54 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.Random;
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) {
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;
}
while(i< nbre){
x = r.nextInt(max);
System.out.println(x);
for(int j : a){
if(x==j){
same = true;
break;
}
}
if(same){
same = false;
}
else{
a[i] = x;
i++;
}
}
System.out.println("\n");
for(int j : a){
System.out.println(j);
}
}
testYann(){
super( 800, 800);
}
@Override
public void onInit() {
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;
}
controller.keyStatus.put(keycode, true);
}
}