-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
209 lines (203 loc) · 7.23 KB
/
Player.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*Name: Michael Bradshaw
Date: October 26, 2020
File Name: Player.java
Description: Holds the class that the player instance will use to play the harry potter game.
*/
//Takes in the random library:
import java.util.Random;
//Class Name: Player
//Description: Holds the class that the player instance uses during the Harry Potter game:
public class Player
{
//Instance varables:
//Gets a instance of the random class
private Random r = new Random();
//This varable holds the name of the player:
private String name;
//This varable holds the health of the player and sets it to 50:
private int health = 50;
//This varable holds the list of spells that can be used for offensive plays:
private String [] offensive_spells = new String[]{"Confundo", "Locomotor Mortis", "Stupefy", "Expelliarmus", "Incendio", "Petrificus Totalus"};
//This varable holds the list of spells that can be used for defenisive plays:
private String [] defensive_spells = new String[]{"Finite Incantum", "Episkey", "Protego", "Expecto Patronum"};
//This method print the health reduction:
public void printHealthReduction(int amountDecreased){
//Prints the health reduction and calls the blankLine method from the game class to print a space after:
System.out.println("Player " + this.getName() + " health decreased by " + amountDecreased); //You can put a string and a varable together thats a integer together.
}
//This method sets the health from the input:
public void setHealth(int value){
this.health = value;
}
//This method returns the health of the player:
public int getHealth(){
//Check if the health of the player is less than or equal to zero if it is it returns 0:
if (this.health <= 0){
return 0;
}
//If not it just returns the health:
else{
return health;
}
}
//This method sets the name of the player:
public void setName(String name){
this.name = name;
}
//This method returns the name of the player:
public String getName(){
return name;
}
//This method when call gets a random integer between 1 and 6 and returns a number plus that random number:
public int roll()
{
//Returns a random integer between 1 and 6 and adds one:
return (r.nextInt(6)+1);
}
//This method when called will get a spell for the number in the roll from the player:
public String getOSpell(int playerRoll)
{
//Returns the offensive spell at the playerRoll - 1 for the index of the list:
return offensive_spells[playerRoll-1];
}
//This method when called will get a spell for the number in the roll from the player:
public String getDSpell(int playerRoll){
if (playerRoll < 3){
//Returns the string no spell if the player rolls a value less than 3
return "no spell";
}
else{
//Returns the defensive spell at the playerRoll - 3 for the rolls after 3
return defensive_spells[playerRoll-3];
}
}
//This method takes in the two players rolls and does damage to the offensePlayer:
public void set_Health_OffensePlayer(int playerRoll, int opponentRoll){
//This runs if the opponent gets a spell that deflects all of the player spells:
if (opponentRoll == 5){
if (playerRoll == 1){
//Reduces health by offense player health by 8
this.health -= 8;
printHealthReduction(8);
}
else if (playerRoll == 2){
//Reduces health by offense player health by 9
this.health -= 9;
printHealthReduction(9);
}
else if (playerRoll == 3){
//Reduces health by offense player health by 10
this.health -= 10;
printHealthReduction(10);
}
else if (playerRoll == 5 || playerRoll == 6){
//Reduces health by offense player health by 12
this.health -= 12;
printHealthReduction(12);
}
}
}
//This method takes in the two players rolls and does damage to the defensePlayer, and prints out the damage done:
public void set_Health_DefensePlayer(int playerRoll, int opponentRoll){
if (opponentRoll < 3){ //Good!
if(playerRoll == 1){
//The health of the defender is reduced by 8:
this.health -= 8;
printHealthReduction(8);
}
else if(playerRoll == 2 || playerRoll == 4){
//The health of the defender is reduced by 9:
this.health -= 9;
printHealthReduction(9);
}
else if(playerRoll == 3){
//The health of the defender is reduced by 10:
this.health -= 10;
printHealthReduction(10);
}
//Runs this if playerRoll is 4 or more:
else{
//The health of the defender is reduced by 12:
this.health -= 12;
printHealthReduction(12);
}
}
//Defends any spell roll 3 and under:
else if (playerRoll <= 3 && opponentRoll == 3){
//Calls the game class and the method blankLine to print a space:
Game.blankLine();
//Prints the following:
System.out.println("Spell was defended!");
//Calls the game class and the method blankLine to print a space:
Game.blankLine();
}
//Defences for attack spells > than 3 and for opponent Roll of 3:
else if (playerRoll > 3){
if (opponentRoll == 3){
if (playerRoll == 4){
//The health of the defender is reduced by 9:
this.health -= 9;
printHealthReduction(9);
}
else if (playerRoll == 5 || playerRoll == 6){
//The health of the defender is reduced by 12:
this.health -= 12;
printHealthReduction(12);
}
}
else if (opponentRoll == 4){
if(playerRoll == 1){
//The health of the defender is reduced by 3:
this.health -= 3;
printHealthReduction(3);
}
else if(playerRoll == 2){
//The health of the defender is reduced by 4:
this.health -= 4;
printHealthReduction(4);
}
else if(playerRoll == 3){
//The health of the defender is reduced by 5:
this.health -= 5;
printHealthReduction(5);
}
else if (playerRoll == 4){
//The health of the defender is reduced by 9:
this.health -= 9;
printHealthReduction(9);
}
else if (playerRoll == 5 || playerRoll == 6){
//The health of the defender is reduced by 7:
this.health -= 7;
printHealthReduction(7);
}
}
else if (opponentRoll == 5){
if (playerRoll == 4){
//The health of the defender is reduced by 9:
this.health -= 9;
printHealthReduction(9);
}
else{
//Calls the game class and the method blankLine to print a space:
Game.blankLine();
//Prints the following:
System.out.println("Spell was deflected back to attacker!");
}
}
else if (opponentRoll == 6){
if (playerRoll == 4){
//The health of the defender is reduced by 9:
this.health -= 9;
printHealthReduction(9);
}
else if (playerRoll == 5 || playerRoll == 6){
//Calls the game class and the method blankLine to print a space:
Game.blankLine();
//Prints the following:
System.out.println("The Spell was defended!");
}
}
}
}
}