From b944d9be51ce4496284833cd9efa32bc4d941cad Mon Sep 17 00:00:00 2001 From: Fastium <79766552+Fastium@users.noreply.github.com> Date: Wed, 15 Jun 2022 09:53:54 +0200 Subject: [PATCH] xp modification --- src/Entity/Enemy.java | 6 +++++ src/Game/Battle.java | 45 +++++++++++++++++--------------- src/Main/PokeMudry.java | 21 +++++++-------- src/Screen/ScreenBattle.java | 16 +++++++----- src/Screen/ScreenPlayer-MSI.java | 45 -------------------------------- 5 files changed, 50 insertions(+), 83 deletions(-) delete mode 100644 src/Screen/ScreenPlayer-MSI.java diff --git a/src/Entity/Enemy.java b/src/Entity/Enemy.java index 7deea2e..387c158 100644 --- a/src/Entity/Enemy.java +++ b/src/Entity/Enemy.java @@ -41,5 +41,11 @@ public class Enemy extends Character{ public String getBranch(){ return branch; } + + @Override + public int getPv() { + //the pv can go under 0, but his real pv is 0 (for the player) + return (pv<0) ? 0 : pv; + } } diff --git a/src/Game/Battle.java b/src/Game/Battle.java index 06d5146..57a2231 100644 --- a/src/Game/Battle.java +++ b/src/Game/Battle.java @@ -12,9 +12,9 @@ public class Battle { private int lineSpeech; public int answer; - private int newXp; - private int pvEnemy; - private int xpPlayer; + public int newXp; + public int pvEnemy; + public int xpPlayer; public boolean screenBattleOn = true; @@ -23,12 +23,9 @@ public class Battle { textEnemy = new TextEnemy(e); textEnemy.generateText(); } - + pvEnemy = e.getPv(); lineSpeech = 0; newXp = 0; - - System.out.println("lll : "+ getLine()); - } public void readNextLine(){ @@ -44,44 +41,54 @@ public class Battle { int attack = lineSpeech-1; //get number current attack random int currentAttack = textEnemy.getCurrentData().get(attack)[0]; - System.out.println(Arrays.toString(textEnemy.getCurrentData().get(attack))); //get number current answer random int currentAnswer = textEnemy.getCurrentData().get(attack)[answer]; //get the answer of the player String answerPlayer = textEnemy.fightData.getAttack(currentAttack).getAnswer(currentAnswer); - System.out.println("answer player : " + answerPlayer); //get true answer String trueAsnwer = textEnemy.fightData.getAttack(currentAttack).getTrueAnswer(); - System.out.println("true answer : " + trueAsnwer); //check the choice of the player if(answerPlayer == trueAsnwer){ newXp += textEnemy.fightData.getAttack(currentAttack).getXp(); + updatePlayerEnemy(textEnemy.fightData.getAttack(currentAttack).getXp()); System.out.println("it's true !!!!"); } else{ System.out.println("it's false !!!!"); } + System.out.println("pv enemy : " +pvEnemy); + System.out.println("xp player : " + xpPlayer); + System.out.println("xp win " + newXp); - readNextLine(); + + if(lineSpeech < 4) readNextLine(); + } - public void FinishSpeech(int pvEnemy){ + public void updatePlayerEnemy(int xp){ + //add xp for the player + xpPlayer += xp; + //remove pv enemy + pvEnemy -= xp; + + } + + public void FinishSpeech(){ if(pvEnemy>0){ - //alive - readNextLine(); + //alive (speechline = 6) + for(int i=0;i<2;i++)readNextLine();; } else{ - //dead + //dead (speechline = 5) + readNextLine(); } } - - public boolean finish(){ return false; @@ -112,10 +119,6 @@ public class Battle { return newXp; } - public void setPvEnemy(int pv){ - pvEnemy = pv; - } - public void setXpPlayer(int xp){ xpPlayer = xp; } diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 832c4e7..6ad2830 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -1,6 +1,5 @@ package Main; - import java.util.Vector; import com.badlogic.gdx.Input; @@ -66,26 +65,26 @@ public class PokeMudry extends PortableApplication { sp.e = sp.p.lastEnemy; sp.sb = sp.screenManager.getScreenBattle(); if(sp.e == null) System.out.println("sdfsdfsdfsdf"); - + sp.b = new Battle(sp.e); + + //set pv and xp to display + sp.b.setXpPlayer(sp.p.getXp()); + g.resetCamera(); } if(onBattleScreen) sp.sb.manage(controller, sp.b); - //manage battle - if(!sp.b.getScreenBattleOn()){ - sp.p.addXp(sp.b.getNewXp()); - sp.e.removedPv(sp.b.getNewXp()); - sp.b.setPvEnemy(sp.e.getPv()); - sp.b.setXpPlayer(sp.p.getXp()); - } if(!sp.b.getScreenBattleOn() && onBattleScreen){ + //addXp for the player + sp.p.addXp(sp.b.getNewXp()); + //remove pv of the enemy + sp.e.removedPv(sp.b.getNewXp()); + sp.p.onEnemy = false; sp.sm = sp.screenManager.getScreenMap(); - - } // Graphics render diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index b9a319b..f0bcf8d 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -35,6 +35,7 @@ public class ScreenBattle extends RenderingScreen{ //display the question generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK); + } @@ -98,14 +99,21 @@ public class ScreenBattle extends RenderingScreen{ public void manage(Controller c, Battle battle){ if(PokeMudry.front_montant){ System.out.println("manage: " + battle.getLineSpeech()); + + if( battle.getAttackOn() == false){ if (c.keyStatus.get(Input.Keys.SPACE)){ - if(battle.getLineSpeech() <= 5){ + if(battle.getLineSpeech() == 4){ + //dislpay the finish speech + battle.FinishSpeech(); + } + else if(battle.getLineSpeech() > 4){ + //return in the map battle.screenBattleOn = battle.finish(); } else{ - System.out.println("in"); + //fix next line battle.readNextLine(); } @@ -117,19 +125,15 @@ public class ScreenBattle extends RenderingScreen{ if(battle.getAttackOn() == true){ if (c.keyStatus.get(Input.Keys.NUM_1)){ - battle.checkAnswer(1); } else if (c.keyStatus.get(Input.Keys.NUM_2)){ - battle.checkAnswer(2); } else if (c.keyStatus.get(Input.Keys.NUM_3)){ - battle.checkAnswer(3); } else if (c.keyStatus.get(Input.Keys.NUM_4)){ - battle.checkAnswer(4); } diff --git a/src/Screen/ScreenPlayer-MSI.java b/src/Screen/ScreenPlayer-MSI.java deleted file mode 100644 index 04197ed..0000000 --- a/src/Screen/ScreenPlayer-MSI.java +++ /dev/null @@ -1,45 +0,0 @@ -package Screen; - -import Entity.Enemy; -import Entity.Player; -import Game.Battle; -import ch.hevs.gdx2d.lib.GdxGraphics; - -public class ScreenPlayer { - public ManagerOfScreen screenManager = new ManagerOfScreen(); - public Player p = null; - public Enemy e = null; - public Battle b = null; - public ScreenMap sm = null; - public ScreenBattle sb = null; - - public void init(){ - - // One player by ScreenPlayer - p = new Player(8, 15, "desert"); - //p = new Player(4, 2, "21RI"); - - b = new Battle(new Enemy("enemi", 0, 0, "charachter", "desert", 50, "enemi")); - - // Create both type of screen and record for reuse - screenManager.registerScreen(ScreenMap.class); - screenManager.registerScreen(ScreenBattle.class); - sb = screenManager.getScreenBattle(); - sm = screenManager.getScreenMap(); - - } - - public void render(GdxGraphics g){ - if(sm != null){ - sm.setPlayer(p); - } - - if(sb != null){ - sb.setBattle(b); - b.setEnemy(e); - } - - screenManager.render(g); - } - -} \ No newline at end of file