-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBattle.java
80 lines (70 loc) · 2.35 KB
/
Battle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* This class contains logic and information necessary to fasciliate the
* Battle scene in which a player and monster attack each other
* until one dies.
* @author Ross Petridis | [email protected] | 1080249
*
*/
public class Battle {
private Player player;
private Monster monster;
/**
* Battle Class constructor for instatiating a battle between a Monster and a Player
* @param player Player object to fight against the monster
* @param monster Monster object to fight agaisnt the player.
*/
public Battle(Player player, Monster monster){
this.player = player;
this.monster = monster;
}
/**
* Logic for running the battle scene. The player and monster takes turns
* exchanging attacks until either dies. // returns true if player dead, false if monster dead
*/
public boolean runBattleScene(){
System.out.println(player.getName() + " encountered a " + monster.getName() + "!\n");
boolean monsterDead=false, playerDead=false;
while(true) { // while neither are dead yet.
displayStatuses();
// player attack
displayAction(player.getName(), monster.getName(), player.getDamage());
monsterDead = monster.hurt(player.getDamage());
if(monsterDead){
displayWinner(player.getName());
return false;
}
// monster attack.
displayAction(monster.getName(), player.getName(), monster.getDamage());
playerDead = player.hurt(monster.getDamage());
if (playerDead){
displayWinner(monster.getName());
return true;
}
System.out.println("");
}
}
/**
* Outputs winning information.
* @param name a String of the name of the winner
*/
private void displayWinner(String name){
System.out.println(name+" wins!\n");
}
/**
* Display text information for the move made by a player or monster.
* @param attacker The attacker's name (String)
* @param victim The victim's name (String)
* @param damage The damage being dealt (Int)
*/
private void displayAction(String attacker, String victim, int damage){
System.out.println(attacker+" attacks "+victim+" for "+damage+" damage.");
}
/**
* Displays status of player and monster between attacks.
*/
private void displayStatuses(){
player.displayStatus();
System.out.print(" | ");
monster.displayStatus();
}
}