-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarrior.java
More file actions
74 lines (54 loc) · 1.73 KB
/
Warrior.java
File metadata and controls
74 lines (54 loc) · 1.73 KB
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
public class Warrior extends Hero
{
public Warrior()
{
super("Warrior", Details.getWarriorDetails());
}//end constructor
public void crushingBlow(DungeonCharacter opponent)
{
if (Math.random() <= .4)
{
int blowPoints = (int)(Math.random() * 76) + 100;
System.out.println(getName() + " lands a CRUSHING BLOW for " + blowPoints
+ " damage!");
opponent.subtractHitPoints(blowPoints, this);
}//end blow succeeded
else
{
System.out.println(getName() + " failed to land a crushing blow");
System.out.println();
}//blow failed
}//end crushingBlow method
public void Attack(DungeonCharacter opponent)
{
System.out.println(getName() + " swings a mighty sword at " +
opponent.getName() + ":");
super.attack(opponent);
}//end override of attack method
public void battleChoices(DungeonCharacter opponent)
{
int choice;
int numTurns = super.getNumTurns();
super.battleChoices(opponent);
do
{
System.out.println("1. Attack Opponent");
System.out.println("2. Crushing Blow on Opponent");
System.out.print("Choose an option: ");
choice = Keyboard.readInt();
System.out.println("--------------------------------------------------\n");
switch (choice)
{
case 1: attack(opponent);
break;
case 2: crushingBlow(opponent);
break;
default:
System.out.println("invalid choice!");
}//end switch
numTurns--;
if (numTurns > 0 && getHitPoints() > 0 && opponent.getHitPoints() > 0 )
System.out.println("Number of turns remaining is: " + numTurns);
} while(numTurns > 0 && getHitPoints() > 0 && opponent.getHitPoints() > 0);
}//end battleChoices method
}