Final Project Documentation
Final Project Documentation
Group Members:
1. Meneses, Jojo
2. Bautista, Merabel
3. Soriano, Rowiljay
PROJECT DESCRIPTION
Objective of the Game:
The goal of the game is to defeat the opponent (CPU) by reducing their
health points (HP) to zero while managing your own HP strategically.
Players must carefully choose their action attack, defend, or use a special
skill to outlast and overcome the CPU.
Game Concept:
- Warrior: Deals double damage on their next attack using their special
skill.
Both the player and the CPU take turns choosing actions, such as
attacking for damage, defending to block attacks, or using special skills
(with a cool-down period). Victory is achieved when an opponent’s HP
drops to zero.
FEATURES
Core Features:
1. Player Specialties:
I. Warrior: Specializes in delivering powerful attacks by doubling
damage.
II. Mage: Focuses on survival by healing 20 HP using their special
skill.
2. Damage System: Randomized attack damage ranges between 6 to
12 points for balanced and unpredictable gameplay.
3. Cool down System: Special skills require a 5-turn cooldown,
encouraging strategic timing and decision-making.
4. Winning Condition: The game ends when either the player or the
CPU’s HP drops to zero, determining the winner.
Optional Features:
GAME DESIGN
Game Flow Chart:
YES
Input a
player name
Is the
CPU’s Is the Player’s
action NO
HP ≤ 0 or
valid?
CPU’s HP ≤ 0?
Select a specialty NO
1. Warrior
2. Mage
YES
CPU’s Turn
Announce the
NO
YES Winner
Is the
Player’s
Specialty
Valid? Is the
Player’s
action
valid?
YES NO END
Player’s Turn
Game Rules
IMPLEMENTATION
Code Overview
Lesson Learned:
Future Improvements:
1 import java.util.Scanner;
2 import java.util.Random;
3
4 public class JavaINFINTY {
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 Random random = new Random();
8
9 // Initialize player and CPU stats
10 System.out.print("Enter your name: ");
11 String playerName = scanner.nextLine();
12 System.out.println("Choose your specialty:");
13 System.out.println("1. Warrior (Double damage in next attack)");
14 System.out.println("2. Mage (Recover 20 HP)");
15
16 // Loop until the player chooses a valid specialty
17 // player special skill
18 int playerSkillChoice = 0;
19 while (playerSkillChoice != 1 && playerSkillChoice != 2) {
20 System.out.print("Enter your choice (1 or 2): ");
21 playerSkillChoice = scanner.nextInt();
22 System.out.println("");
23
24 if (playerSkillChoice == 1) {
25 System.out.println(playerName + " chose Warrior.");
26
27 } else if (playerSkillChoice == 2) {
28 System.out.println(playerName + " chose Mage.");
29 } else {
30 System.out.println("Invalid choice. Please select 1 for Warrior or 2 for
Mage.");
31 }
32 }
33
34 // cpu special skill
35 int cpuSkillChoice = random.nextInt(2) + 1; // printing cpu choice
36 if (cpuSkillChoice == 1){
37 System.out.println("Cpu chose Warrior");
38 }else{
39 System.out.println("Cpu chose Mage");
40 }
41 System.out.println("\
n---------------------------------------------------------------------------------------------------");
42
43 // declaring HP and special skill cooldown
44 int playerHp = 100;
45 int cpuHp = 100;
46 int playerSkillCooldown = 0;
47 int cpuSkillCooldown = 0;
48 boolean playerUsedSkill = false;
49 boolean cpuUsedSkill = false;
50
51
52 System.out.println("\nLet the battle begin!");
53
54 while (playerHp > 0 && cpuHp > 0) { // loop until player or cpu hp comes down
to 0
55 // Display player options
56 System.out.println("\n" + playerName + "'s Turn:");
57 System.out.println("1. Attack");
58 System.out.println("2. Defend");
59 System.out.println("3. Special Skill (" + (playerSkillCooldown == 0 ? "Ready" :
playerSkillCooldown + " rounds left") + ")");
60
61 // player's action
62 int playerAction = 0;
63 while (true){
64 System.out.print("\nChoose your action: ");
65 playerAction = scanner.nextInt(); // scanner that will accept the player's
action
66
67 if (playerAction == 3 && playerSkillCooldown > 0){ // filter for invalid
actions
68 System.out.println("Special skill is still on cooldown!");
69 } else if (playerAction >= 1 && playerAction <= 3) {
70 break;
71 } else {
72 System.out.println("Invalid choice. Please select a valid option (1, 2, or
3).");
73 }
74 }
75
76 // CPU's action randomizer
77 int cpuAction = random.nextInt(3) + 1;
78 while (cpuAction == 3 && cpuSkillCooldown > 0) { // forces cpu to reselect
action if it chooses the special skill while it's on cooldown.
79 cpuAction = random.nextInt(3) + 1;
80 }
81
82 // initializing variables for DAMAGE and DEFEND
83 int playerDamage = 0;
84 int cpuDamage = 0;
85 boolean playerDefend = false;
86 boolean cpuDefend = false;
87
88 // process of players action
89 switch (playerAction) {
90 case 1 : // attack
91 playerDamage = random.nextInt(7) + 6; // Random damage (6-12)
92 System.out.println(playerName + " attacks and deals " + playerDamage
+ " damage!");
93 break;
94
95 case 2 : // defend
96 System.out.println(playerName + " is defending.");
97 playerDefend = true;
98 break;
99
100 case 3 : // special skill
101 if (playerSkillChoice == 1) {
102 playerDamage = (random.nextInt(7) + 6) * 2;
103 System.out.println(playerName + " uses Warrior's Special Skill and
deals " + playerDamage + " damage!");
104 } else {
105 playerHp = Math.min(playerHp + 20, 100);
106 System.out.println(playerName + " uses Mage's Special Skill and
recovers 20 HP!");
107 }
108 playerUsedSkill = true;
109 playerSkillCooldown = 5;
110 break;
111
112 default :
113 System.out.println("Invalid choice. Skipping turn.");
114
115 }
116
117 // process of Cpu action
118 switch (cpuAction) {
119 case 1 : // attack
120 cpuDamage = random.nextInt(7) + 6; // Random damage (6-12)
121 System.out.println("CPU attacks and deals " + cpuDamage + "
damage!");
122 break;
123
124 case 2 : // defend
125 System.out.println("CPU is defending.");
126 cpuDefend = true;
127 break;
128
129 case 3 : // special skill
130 if (cpuSkillChoice == 1) {
131 cpuDamage = (random.nextInt(7) + 6) * 2;
132 System.out.println("CPU uses Warrior's Special Skill and deals " +
cpuDamage + " damage!");
133 } else {
134 cpuHp = Math.min(cpuHp + 20, 100);
135 System.out.println("CPU uses Mage's Special Skill and recovers 20
HP!");
136 }
137 cpuUsedSkill = true;
138 cpuSkillCooldown = 5;
139 break;
140
141 }
142
143 // defending mechanics
144 if (playerDefend && cpuDamage > 0) {
145 System.out.println(playerName + " negates the CPU's attack!");
146 cpuDamage = 0; // Negate damage if defending
147 }
148 if (cpuDefend && playerDamage > 0) {
149 System.out.println("CPU negates " + playerName + "'s attack!");
150 playerDamage = 0; // Negate damage if defending
151 }
152 if (cpuDefend && playerDefend) {
153 System.out.println("No damage was inflicted");
154 }
155
156
157 // damage
158 cpuHp -= playerDamage;
159 playerHp -= cpuDamage;
160
161
162 // cooldown mechanics
163 if (playerSkillCooldown > 0) {
164 playerSkillCooldown--; // decrease the value of a variable by one
165 }
166 if (cpuSkillCooldown > 0) {
167 cpuSkillCooldown--; // decrease the value of a variable by one
168 }
169
170
171 // display
172 System.out.println("\nRound Summary:");
173 System.out.println(playerName + "'s HP: " + playerHp);
174 System.out.println("CPU's HP: " + cpuHp);
175 if (playerUsedSkill) {
176 System.out.println(playerName + " used their special skill this round!");
177 playerUsedSkill = false;
178 }
179 if (cpuUsedSkill) {
180 System.out.println("CPU used their special skill this round!");
181 cpuUsedSkill = false;
182 }
183 System.out.println("\
n---------------------------------------------------------------------------------------------------");
184 }
185
186 // winning process
187 System.out.println("\nGame Over!");
188 if (playerHp > 0) {
189 System.out.println("Congratulations " + playerName + ", you win!");
190 } else {
191 System.out.println("CPU wins! Better luck next time.");
192 }
193 scanner.close();
194
195 }
196 }