2022-06-10 19:33:24 +02:00
|
|
|
package Game;
|
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
import Entity.Enemy;
|
2022-06-16 15:46:34 +02:00
|
|
|
import Entity.Player;
|
2022-06-12 12:10:57 +02:00
|
|
|
import Text.TextEnemy;
|
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
public class Battle {
|
2022-06-12 12:10:57 +02:00
|
|
|
|
2022-06-16 15:46:34 +02:00
|
|
|
public Enemy e;
|
|
|
|
public Player player;
|
|
|
|
|
2022-06-13 23:11:17 +02:00
|
|
|
public TextEnemy textEnemy;
|
2022-06-12 14:26:02 +02:00
|
|
|
private int lineSpeech;
|
2022-06-15 18:20:40 +02:00
|
|
|
|
2022-06-13 20:53:09 +02:00
|
|
|
|
2022-06-15 09:53:54 +02:00
|
|
|
public int newXp;
|
|
|
|
public int pvEnemy;
|
|
|
|
public int xpPlayer;
|
2022-06-13 21:54:05 +02:00
|
|
|
|
2022-06-13 21:58:13 +02:00
|
|
|
public boolean screenBattleOn = true;
|
2022-06-12 14:26:02 +02:00
|
|
|
|
2022-06-13 23:11:17 +02:00
|
|
|
public Battle(Enemy e){
|
2022-06-14 01:14:54 +02:00
|
|
|
if(e != null){
|
|
|
|
textEnemy = new TextEnemy(e);
|
|
|
|
textEnemy.generateText();
|
|
|
|
}
|
2022-06-15 09:53:54 +02:00
|
|
|
pvEnemy = e.getPv();
|
2022-06-12 14:26:02 +02:00
|
|
|
lineSpeech = 0;
|
2022-06-13 23:11:17 +02:00
|
|
|
newXp = 0;
|
2022-06-12 12:10:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void readNextLine(){
|
|
|
|
//change line
|
2022-06-13 21:38:00 +02:00
|
|
|
System.out.println(textEnemy.lines.size());
|
2022-06-15 18:20:40 +02:00
|
|
|
if(lineSpeech < 5){
|
2022-06-13 21:38:00 +02:00
|
|
|
lineSpeech++;
|
|
|
|
}
|
2022-06-15 18:20:40 +02:00
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
}
|
|
|
|
|
2022-06-15 18:20:40 +02:00
|
|
|
public void action(int answer){
|
|
|
|
System.out.println("pv enemy : " +pvEnemy);
|
|
|
|
System.out.println("xp player : " + xpPlayer);
|
|
|
|
System.out.println("xp win " + newXp);
|
2022-06-16 17:15:59 +02:00
|
|
|
|
|
|
|
|
2022-06-15 18:20:40 +02:00
|
|
|
if(getLineSpeech() == 4){
|
|
|
|
FinishSpeech();
|
|
|
|
}
|
|
|
|
else if( getLineSpeech() == 5 || getLineSpeech() == 6){
|
|
|
|
finish();
|
2022-06-16 14:24:20 +02:00
|
|
|
e.recoveredTime = 0;
|
2022-06-15 18:20:40 +02:00
|
|
|
}
|
|
|
|
else if(0 < getLineSpeech() && getLineSpeech() < 4){
|
|
|
|
checkAnswer(answer);
|
2022-06-16 17:15:59 +02:00
|
|
|
|
|
|
|
if(pvEnemy <= 0){
|
|
|
|
FinishSpeech();
|
|
|
|
}
|
2022-06-15 18:20:40 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
readNextLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-13 20:53:09 +02:00
|
|
|
//check the choice answer
|
|
|
|
public void checkAnswer(int answer){
|
|
|
|
int attack = lineSpeech-1;
|
|
|
|
//get number current attack random
|
|
|
|
int currentAttack = textEnemy.getCurrentData().get(attack)[0];
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
//get true answer
|
|
|
|
String trueAsnwer = textEnemy.fightData.getAttack(currentAttack).getTrueAnswer();
|
|
|
|
|
|
|
|
//check the choice of the player
|
|
|
|
if(answerPlayer == trueAsnwer){
|
2022-06-13 23:11:17 +02:00
|
|
|
newXp += textEnemy.fightData.getAttack(currentAttack).getXp();
|
2022-06-15 09:53:54 +02:00
|
|
|
updatePlayerEnemy(textEnemy.fightData.getAttack(currentAttack).getXp());
|
2022-06-13 20:53:09 +02:00
|
|
|
System.out.println("it's true !!!!");
|
2022-06-13 23:11:17 +02:00
|
|
|
|
2022-06-13 20:53:09 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
System.out.println("it's false !!!!");
|
|
|
|
}
|
2022-06-15 18:20:40 +02:00
|
|
|
readNextLine();
|
2022-06-15 09:53:54 +02:00
|
|
|
}
|
2022-06-13 20:53:09 +02:00
|
|
|
|
2022-06-15 09:53:54 +02:00
|
|
|
public void updatePlayerEnemy(int xp){
|
|
|
|
//add xp for the player
|
|
|
|
xpPlayer += xp;
|
|
|
|
//remove pv enemy
|
|
|
|
pvEnemy -= xp;
|
2022-06-16 19:30:07 +02:00
|
|
|
if(pvEnemy<0) pvEnemy =0;
|
2022-06-15 09:53:54 +02:00
|
|
|
|
2022-06-13 20:53:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-15 09:53:54 +02:00
|
|
|
public void FinishSpeech(){
|
2022-06-14 12:51:47 +02:00
|
|
|
if(pvEnemy>0){
|
2022-06-15 09:53:54 +02:00
|
|
|
//alive (speechline = 6)
|
2022-06-16 17:15:59 +02:00
|
|
|
lineSpeech = 6;
|
2022-06-15 18:20:40 +02:00
|
|
|
System.out.println("enemy alive");
|
2022-06-14 12:51:47 +02:00
|
|
|
}
|
|
|
|
else{
|
2022-06-15 09:53:54 +02:00
|
|
|
//dead (speechline = 5)
|
2022-06-16 17:15:59 +02:00
|
|
|
lineSpeech = 5;
|
2022-06-15 18:20:40 +02:00
|
|
|
System.out.println("enemy dead");
|
2022-06-14 12:51:47 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-16 17:15:59 +02:00
|
|
|
|
2022-06-13 21:38:00 +02:00
|
|
|
|
2022-06-15 18:20:40 +02:00
|
|
|
public void finish(){
|
|
|
|
screenBattleOn = false;
|
2022-06-13 21:38:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
public boolean getAttackOn(){
|
|
|
|
return textEnemy.lines.get(lineSpeech).attackOn;
|
|
|
|
}
|
2022-06-11 21:45:45 +02:00
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
public String getLine(){
|
2022-06-14 01:14:54 +02:00
|
|
|
if(e==null) return null;
|
2022-06-12 12:10:57 +02:00
|
|
|
return textEnemy.lines.get(lineSpeech).line;
|
|
|
|
}
|
2022-06-12 14:26:02 +02:00
|
|
|
|
2022-06-14 12:51:47 +02:00
|
|
|
//get the line for the dialog
|
2022-06-12 14:26:02 +02:00
|
|
|
public int getLineSpeech() {
|
|
|
|
return lineSpeech;
|
|
|
|
}
|
2022-06-13 21:54:05 +02:00
|
|
|
|
2022-06-14 12:51:47 +02:00
|
|
|
//return true if the screen is active
|
2022-06-13 21:57:01 +02:00
|
|
|
public boolean getScreenBattleOn(){
|
2022-06-13 21:54:05 +02:00
|
|
|
return screenBattleOn;
|
|
|
|
}
|
2022-06-13 23:11:17 +02:00
|
|
|
|
2022-06-14 12:51:47 +02:00
|
|
|
//get the total xp win in the battle
|
2022-06-13 23:11:17 +02:00
|
|
|
public int getNewXp(){
|
|
|
|
return newXp;
|
|
|
|
}
|
2022-06-14 01:14:54 +02:00
|
|
|
|
2022-06-14 12:51:47 +02:00
|
|
|
public void setXpPlayer(int xp){
|
|
|
|
xpPlayer = xp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set enemy
|
2022-06-14 01:14:54 +02:00
|
|
|
public void setEnemy(Enemy e){
|
|
|
|
this.e = e;
|
|
|
|
}
|
2022-06-16 15:46:34 +02:00
|
|
|
public void setPlayer(Player p){
|
|
|
|
this.player = p;
|
|
|
|
}
|
2022-06-10 19:33:24 +02:00
|
|
|
}
|