-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThief.java
More file actions
67 lines (52 loc) · 1.54 KB
/
Thief.java
File metadata and controls
67 lines (52 loc) · 1.54 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
public class Thief extends Hero
{
public Thief()
{
super("Thief", Details.getThiefDetails());
}//end constructor
public void Attack(DungeonCharacter opponent)
{
double surprise = Math.random();
int numTurns = super.getNumTurns();
if (surprise <= .4)
{
System.out.println("Surprise attack was successful!\n" +
getName() + " gets an additional turn.");
super.setNumTurns(numTurns + 1);
Attack(opponent);
}//end surprise
else if (surprise >= .9)
{
System.out.println("Uh oh! " + opponent.getName() + " saw you and" +
" blocked your attack!");
}
else
Attack(opponent);
}//end surpriseAttack method
public void battleChoices(DungeonCharacter opponent)
{
super.battleChoices(opponent);
int choice;
int numTurns = super.getNumTurns();
do
{
System.out.println("1. Attack Opponent");
System.out.println("2. Surprise Attack");
System.out.print("Choose an option: ");
choice = Keyboard.readInt();
System.out.println("--------------------------------------------------\n");
switch (choice)
{
case 1: attack(opponent);
break;
case 2: Attack(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);
}
}