-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemon2.java
More file actions
131 lines (116 loc) · 4.5 KB
/
Pokemon2.java
File metadata and controls
131 lines (116 loc) · 4.5 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
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
import java.util.*;
public class Pokemon2 {
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
Random rand = new Random();
String attackOrPass = "";
int enemyHP = 100;
int yourHP = 100;
int hitOrMiss = 0;
int damage = 0;
int potion = 3;
int potionRestore = 0;
int runAway = 0;
int crit = 0;
/* THOUGHT:
NEED TO FIX DAMAGE TO NOT INCLUDE 0
*/
do
{
System.out.println("Your HP: " + yourHP);
System.out.println("Enemy HP: " + enemyHP);
System.out.println(); // New line
System.out.println("(A)ttack, (P)otion " + potion + ", (R)un");
attackOrPass = in.nextLine();
// Your attack session
// MAYBE ADD AN IF STATEMENT LIKE 'if hp is not less than or equal to zero, perform attack'
if (attackOrPass.equalsIgnoreCase("A"))
{
System.out.println("You chose to attack.");
crit = rand.nextInt(10) + 1; // Check for crit. 10% chance
System.out.println("Crit roll was: " + crit);
hitOrMiss = rand.nextInt(10) + 1; // Generate hit or miss number. If number '2', miss. All others hit
System.out.println("Hit or miss: " + hitOrMiss); // Display hit or miss number
if (hitOrMiss == 2) // If miss
{
System.out.println("Miss");
}
else if (crit == 7) // Else if critical hit
{
damage = rand.nextInt(20) + 1;
System.out.println("Regular Damage: " + damage);
damage = damage * 2;
System.out.println("Critical hit!" + damage);
enemyHP = enemyHP - damage;
System.out.println(); // New line
}
else // Else hit
{
damage = rand.nextInt(21);
System.out.println(damage + " damage to the enemy.");
enemyHP = enemyHP - damage;
System.out.println(); // New line
}
System.out.println(); // New line
} // End 'attack if'
// In case the user wants to use a potion
else if (attackOrPass.equalsIgnoreCase("P"))
{
if (potion <= 0)
{
System.out.println("You have no more potions.");
}
else
{
potionRestore = rand.nextInt(11-5) + 1; // Generate how much HP to be restored.
System.out.println("Restored " + potionRestore + " HP.");
yourHP = Math.min(yourHP + potionRestore, 100); // Add HP back to your health
potion = potion - 1;
System.out.println(); // New line
}
} // End 'potion if'
// In case user wants to run
else if (attackOrPass.equalsIgnoreCase("R"))
{
runAway = rand.nextInt(10) + 1; // 90% chance to get away
if (runAway == 2)
{
System.out.println("You tripped, could not get away.");
System.out.println(); // New line
}
else
{
System.out.println("Got away safely.");
break;
}
}
hitOrMiss = 0; // Reset number
damage = 0; // Reset number
// Enemy attack session
// MAYBE ADD AN IF STATEMENT LIKE 'if hp is not less than or equal to zero, perform attack'
hitOrMiss = rand.nextInt(10) + 1;
System.out.println("Enemy hit or miss: " + hitOrMiss);
if (hitOrMiss == 2)
{
System.out.println("Enemy miss");
}
else
{
damage = rand.nextInt(20) + 1;
System.out.println(damage + " damage to you.");
yourHP = yourHP - damage;
System.out.println();
}
} while (yourHP >= 1 && enemyHP >= 1);
// Display results
if (enemyHP <= 0)
{
System.out.println("You Win!");
}
else if (yourHP <= 0)
{
System.out.println("You lose.");
}
} // End main
}