Skip to content

Commit

Permalink
Merge pull request #2 from EvanNikaloasTheFirst/Complete_project
Browse files Browse the repository at this point in the history
- Code has been reduced with the functionality remaining
  • Loading branch information
EvanNikaloasTheFirst committed Dec 9, 2022
2 parents dc96737 + 8801b68 commit 73bab72
Showing 1 changed file with 46 additions and 53 deletions.
99 changes: 46 additions & 53 deletions src/PokemonGame.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import java.util.Scanner;
import java.util.ArrayList;

public class PokemonGame {

public static void main(String[] args) throws InterruptedException {
ArrayList<String> badges = new ArrayList<>();
// Use of encapsulation via the Pokemon.java class
Pokemon Pikachu = new Pokemon("Pikachu", "Electric", 27,
"Thunderbolt",
"Tackle",
Expand Down Expand Up @@ -38,6 +38,7 @@ public static void main(String[] args) throws InterruptedException {
// Starts game
start(Pikachu, Squirtle, Charmander, Pidgin, Piplup, Garchomp, badges);
}

private static void start(Pokemon Pikachu, Pokemon Squirtle, Pokemon Charmander,
Pokemon Pidgin, Pokemon Garchomp, Pokemon Piplup, ArrayList badges) throws InterruptedException {

Expand All @@ -57,79 +58,71 @@ private static void start(Pokemon Pikachu, Pokemon Squirtle, Pokemon Charmander,
}
}

public static void rollAttack(Pokemon attackingPokemon, Pokemon defendingPokemon) throws InterruptedException {
public static void rollAttack(Pokemon attackingPokemon, Pokemon defendingPokemon, int move) throws InterruptedException {
int attackDamage = (int) (Math.random() * attackingPokemon.getLevel());
if (attackingPokemon.getHealthPoints() > 0) {

System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveOne() + " and caused " + attackDamage + " pts of damage");
defendingPokemon.setHealthPoints(defendingPokemon.getHealthPoints() - attackDamage);
System.out.println(defendingPokemon.getName() + " HP: " + defendingPokemon.getHealthPoints());
Thread.sleep(3000);
System.out.println("-------------------");
switch (move) {
case 1:
System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveOne() + " and caused " + attackDamage + " pts of damage");
break;
case 2:
System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveTwo() + " and caused " + attackDamage + " pts of damage");
break;
case 3:
System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveThree() + " and caused " + attackDamage + " pts of damage");
break;
}
defendingPokemon.setHealthPoints(defendingPokemon.getHealthPoints() - attackDamage);
System.out.println(defendingPokemon.getName() + " HP: " + defendingPokemon.getHealthPoints());
Thread.sleep(3000);
System.out.println("-------------------");
}



public static void rollAttack2(Pokemon attackingPokemon, Pokemon defendingPokemon) throws InterruptedException {
int attackDamage = (int) (Math.random() * attackingPokemon.getLevel());
if (attackingPokemon.getHealthPoints() > 0) {
System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveTwo() + " and caused " + attackDamage + "pts of damage");
defendingPokemon.setHealthPoints(defendingPokemon.getHealthPoints() - attackDamage);
System.out.println(defendingPokemon.getName() + " HP: " + defendingPokemon.getHealthPoints());
Thread.sleep(3000);
System.out.println("-------------------");
}
}


public static void rollAttack3(Pokemon attackingPokemon, Pokemon defendingPokemon) throws InterruptedException {
int attackDamage = (int) (Math.random() * attackingPokemon.getLevel());
if (attackingPokemon.getHealthPoints() > 0) {
System.out.println(attackingPokemon.getName() + " used " + attackingPokemon.getMoveThree() + " and caused " + attackDamage + "pts of damage");
defendingPokemon.setHealthPoints(defendingPokemon.getHealthPoints() - attackDamage);
System.out.println(defendingPokemon.getName() + " HP : " + defendingPokemon.getHealthPoints());
Thread.sleep(3000);
System.out.println("-------------------");
}
}

}

public static void challenges(Pokemon attackingPokemon, Pokemon defendingPokemon, ArrayList badges) throws InterruptedException {
int user;
final int min = 1;
final int max = 3;
Scanner userInput = new Scanner(System.in);
Thread.sleep(1100);
System.out.println(("You are fighting " + defendingPokemon.getName() + ", good luck! "));

// generates a random attack for the enemies Pokémon
while(defendingPokemon.getHealthPoints() > 0) {
int move = (int)Math.floor(Math.random()*(max-min+1)+min);
while (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
System.out.println("Enter 1 to use: " + attackingPokemon.getMoveOne());
System.out.println("Enter 2 to use: " + attackingPokemon.getMoveTwo());
System.out.println("Enter 3 to use: " + attackingPokemon.getMoveThree());
user = userInput.nextInt();
switch (user) {
case 1 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack(attackingPokemon, defendingPokemon);
rollAttack(defendingPokemon, attackingPokemon);


user = userInput.nextInt();
switch (user) {
case 1 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack(attackingPokemon, defendingPokemon, 1);
rollAttack(defendingPokemon, attackingPokemon, move);

}
}
}
case 2 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack2(attackingPokemon, defendingPokemon);
rollAttack2(defendingPokemon, attackingPokemon);
case 2 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack(attackingPokemon, defendingPokemon, 2);
rollAttack(defendingPokemon, attackingPokemon, move);
}
}
}

case 3 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack3(attackingPokemon, defendingPokemon);
rollAttack3(defendingPokemon, attackingPokemon);
case 3 -> {
if (attackingPokemon.getHealthPoints() > 0 && defendingPokemon.getHealthPoints() > 0) {
rollAttack(attackingPokemon, defendingPokemon, 3);
rollAttack(defendingPokemon, attackingPokemon, move);
}
}
}
}

}
if (defendingPokemon.getHealthPoints() <= 0) {
System.out.println("You defated " + defendingPokemon.getName());
System.out.println("You defeated " + defendingPokemon.getName());
badges.add(defendingPokemon.getType() + " badge");
System.out.println("Congratulations, you earned the " + defendingPokemon.getType() + " badge");
Thread.sleep(1100);
Expand All @@ -143,4 +136,4 @@ public static void challenges(Pokemon attackingPokemon, Pokemon defendingPokemon
for (Object badge : badges) System.out.println(badge);
}
}
}
}

0 comments on commit 73bab72

Please sign in to comment.