Question
Please Help with this java assignment I cannot figure out what is wrong with this code AdventureGameFinal.java import java.util.Scanner; import java.util.Random; public class AdventureGameFinal {
Please Help with this java assignment I cannot figure out what is wrong with this code
AdventureGameFinal.java
import java.util.Scanner; import java.util.Random;
public class AdventureGameFinal { public static void main(String[] args) { /*** Objects ***/ Scanner keyboard = new Scanner(System.in); Random randomNum = new Random(); Player player = null; Enemy minion = null; System.out.println(" Adventure Game - Start! "); System.out.println("Here are the characters:"); System.out.println("1. Rogue 2. Paladin 3. Jackie Chan 4. Chuck Norris "); System.out.print("Which character do you choose?: "); int characterChoice = keyboard.nextInt(); // Assumption 1: User will input either 1, 2, 3, or 4 for character. switch (characterChoice) { case 1: // Rogue player = Player.getRogue(); break; case 2: // Paladin player = Player.getPaladin(); break; case 3: // Jackie Chan player = Player.getJackieChan(); break; case 4: // Chuck Norris player = Player.getChuckNorris(); break; default: System.out.printf(" Invalid input for character. %d is not an available option. ", characterChoice); System.exit(0); } System.out.printf("You chose: %s ", player.getName()); System.out.print("The Evil Wizard must be defeated! He is in The Castle. To get to "); System.out.println("The Castle, you must travel through either:"); System.out.println("1. The Forest 2. The Graveyard 3. The Cave "); System.out.print("Which path will you take?: "); int pathChoice = keyboard.nextInt(); int numEnemies = 0; //Assumption 2: User will input either 1, 2, or 3 for path. switch(pathChoice) { case 1: // Forest System.out.println("You chose: The Forest "); minion = Enemy.getGoblin(); numEnemies = minion.getNumGoblins(); System.out.printf("Once you enter The Forest, you encounter %d Goblins! Time for battle! ", numEnemies); break; case 2: // Graveyard System.out.println("You chose: The Graveyard "); minion = Enemy.getSkeleton(); numEnemies = minion.getNumSkeletons(); System.out.printf("Once you enter The Graveyard, you encounter %d Skeletons! Time for battle! ", numEnemies); break; case 3: // Cave System.out.println("You chose: The Cave "); minion = Enemy.getTroll(); numEnemies = minion.getNumTrolls(); System.out.printf("Once you enter The Cave, you encounter %d Trolls! Time for battle! ", numEnemies); break; default: System.out.printf(" Invalid input for path. %d is not an available option. ", pathChoice); System.exit(0); } // Phase 1 battle simulation for (int i = 1; i 0) { System.out.printf("--%s wins the battle!-- ", player.getName()); System.out.println("You win! Congratulations! "); } else { System.out.printf("--%s is defeated in battle!-- GAME OVER ", player.getName()); } } }
Enemy.java
import java.util.Random; public class Enemy { static Random randomNum = new Random(); /*** Attributes ***/ private String name; private int hitPoints; private int strength; private Weapon weapon; /*** Singletons ***/ private static Enemy goblin = null; private static Enemy skeleton = null; private static Enemy troll = null; private static Enemy wizard = null; /*** Methods ***/ // constructor public Enemy(String _name, int _hitPoints, int _strength, Weapon _weapon) { name = _name; hitPoints = _hitPoints; strength = _strength; weapon = _weapon; } public String getName() { return name; } public int getHitPoints() { return hitPoints; } public void resetHitPoints() { hitPoints = 25; } public void increaseHitPoints(int _pointsIncrease) { hitPoints += _pointsIncrease; } public void decreaseHitPoints(int _pointsDecrease) { hitPoints -= _pointsDecrease; } public int getStrength() { return strength; } // enemy attacks player public void attack(Player _player) { int weaponDamage = weapon.getDamage(); int attack = strength + weaponDamage; int playerOldHP = _player.getHitPoints(); _player.decreaseHitPoints(attack); System.out.printf("%s attacks with ATK = %d + %d = %d ", name, strength, weaponDamage, attack); System.out.printf("%s HP is now %d - %d = %d ", _player.getName(), playerOldHP, attack, _player.getHitPoints()); } public boolean isDefeated() { if (hitPoints
Player.java
import java.util.Random; import java.util.Scanner; public class Player { /*** Attributes ***/ private String name; private int hitPoints; private int strength; private Weapon weapon; private int coins; /*** Singletons ***/ private static Player rogue = null; private static Player paladin = null; private static Player jackieChan = null; private static Player chuckNorris = null; /*** Methods ***/ // constructor public Player(String _name, int _hitPoints, int _strength, Weapon _weapon) { name = _name; hitPoints = _hitPoints; strength = _strength; weapon = _weapon; coins = 0; } public String getName() { return name; } public int getHitPoints() { return hitPoints; } public void increaseHitPoints(int _pointsIncrease) { hitPoints += _pointsIncrease; } public void decreaseHitPoints(int _pointsDecrease) { hitPoints -= _pointsDecrease; } public int getStrength() { return strength; } public void increaseStrength(int _strengthIncrease) { strength += _strengthIncrease; } public void setWeapon(Weapon _weapon) { weapon = _weapon; } public int getCoins() { return coins; } public void increaseCoins(int _coins) { coins += _coins; } public void decreaseCoins(int _coins) { coins -= _coins; } public void attack(Enemy _enemy) { int weaponDamage = weapon.getDamage(); int attack = strength + weaponDamage; int enemyOldHP = _enemy.getHitPoints(); _enemy.decreaseHitPoints(attack); System.out.printf("%s attacks with ATK = %d + %d = %d ", name, strength, weaponDamage, attack); System.out.printf("%s HP is now %d - %d = %d ", _enemy.getName(), enemyOldHP, attack, _enemy.getHitPoints()); } public void battleMinion(Enemy _enemy) { while (_enemy.getHitPoints() > 0 && hitPoints > 0) { this.attack(_enemy); if (_enemy.isDefeated()) { break; } _enemy.attack(this); } // end while } public void battleWizard(Enemy _enemy) { Random randomNums = new Random(); Scanner keyboard = new Scanner(System.in); int randomNumAnswer = randomNums.nextInt(6) + 1; System.out.printf("***%s vs The Evil Wizard*** ", name); while (hitPoints > 0 && _enemy.getHitPoints() > 0) { System.out.println("Choose your action: 1. Attack 2. Attempt Spell Cast "); System.out.print("What would you like to do: "); int playerActionChoice = keyboard.nextInt(); System.out.println(); switch(playerActionChoice) { case 1: // Attack this.attack(_enemy); break; case 2: // Attempt spell System.out.print("Enter your guess: "); int randomNumGuess = keyboard.nextInt(); if (randomNumGuess == randomNumAnswer) { System.out.println(" Correct! "); System.out.printf("The %s's spell is cast successfully! The Wizard's HP is now 0! ", name); _enemy.decreaseHitPoints(_enemy.getHitPoints()); } else { System.out.println(" Incorrect! The spell cast fails! "); } break; default: // fail-safe System.out.printf(" Invalid input. %d is not an available option. ", playerActionChoice); System.exit(0); } if (_enemy.getHitPoints()
Weapon.java
import java.util.Random; public class Weapon { /*** Public Constants ***/ public static final int SHORT_SWORD_MIN = 1; public static final int SHORT_SWORD_MAX = 4; public static final int LONG_SWORD_MIN = 3; public static final int LONG_SWORD_MAX = 7; public static final int JUMP_KICK_MIN = 2; public static final int JUMP_KICK_MAX = 6; public static final int EAGLE_STRIKE_MIN = 3; public static final int EAGLE_STRIKE_MAX = 8; public static final int AXE_MIN = 2; public static final int AXE_MAX = 6; public static final int CLUB_MIN = 1; public static final int CLUB_MAX = 3; public static final int MACE_MIN = 2; public static final int MACE_MAX = 6; public static final int FIRE_BLAST_MIN = 4; public static final int FIRE_BLAST_MAX = 10; /*** Attributes ***/ private String name; private int minDamage; private int maxDamage; /*** Singletons ***/ private static Weapon shortSword = null; private static Weapon longSword = null; private static Weapon jumpKick = null; private static Weapon eagleStrike = null; private static Weapon axe = null; private static Weapon club = null; private static Weapon mace = null; private static Weapon fireBlast = null; /*** Methods ***/ // constructor public Weapon(String _name, int _minDamage, int _maxDamage) { name = _name; minDamage = _minDamage; maxDamage = _maxDamage; } public String getName() { return name; } public int getMinDamage() { return minDamage; } public int getMaxDamage() { return maxDamage; } // determines weapon damage as random number in range of [minDamage-maxDamage] public int getDamage() { Random randomNum = new Random(); return randomNum.nextInt(maxDamage - minDamage + 1) + minDamage; } // Utility Methods public static Weapon getShortSword() { if (shortSword == null) { shortSword = new Weapon("Short Sword", SHORT_SWORD_MIN, SHORT_SWORD_MAX); } return shortSword; } public static Weapon getLongSword() { if (longSword == null) { longSword = new Weapon("Long Sword", LONG_SWORD_MIN, LONG_SWORD_MAX); } return longSword; } public static Weapon getJumpKick() { if (jumpKick == null) { jumpKick = new Weapon("Jump Kick", Weapon.JUMP_KICK_MIN, Weapon.JUMP_KICK_MAX); } return jumpKick; } public static Weapon getEagleStrike() { if (eagleStrike == null) { eagleStrike = new Weapon("Eagle Strike", Weapon.EAGLE_STRIKE_MIN, Weapon.EAGLE_STRIKE_MAX); } return eagleStrike; } public static Weapon getAxe() { if (axe == null) { axe = new Weapon("Axe", Weapon.AXE_MIN, Weapon.AXE_MAX); } return axe; } public static Weapon getClub() { if (club == null) { club = new Weapon("Club", Weapon.CLUB_MIN, Weapon.CLUB_MAX); } return club; } public static Weapon getMace() { if (mace == null) { mace = new Weapon("Long Sword", MACE_MIN, MACE_MAX); } return mace; } public static Weapon getFireBlast() { if (fireBlast == null) { fireBlast = new Weapon("Fire Blast", Weapon.FIRE_BLAST_MIN, Weapon.FIRE_BLAST_MAX); } return fireBlast; } }
ItemShop:
import java.util.Scanner; public class ItemShop { /*** Private Constants ***/ private final int LONG_SWORD_COST = 120; private final int SHORT_SWORD_COST = 90; private final int MACE_COST = 80; private final int MAGIC_RING_COST = 150; private final int HEALING_POTION_COST = 10; /*** Attributes ***/ private int playerOrder; private int quantity; private int discount; private int totalCost = 0; private int finalCost = 0; private int userDecision; private int itemEffect; /*** Methods ***/ public void visitItemShop(Player _player) { Scanner keyboard = new Scanner(System.in); System.out.print("Would you like to visit The Item Shop? " + "Enter 1 for \"yes\" or 0 for \"no\": "); userDecision = keyboard.nextInt(); if (userDecision==0) return; System.out.println(" Welcome to the Item Shop!"); while (userDecision != 0 && _player.getCoins() > 0) { System.out.printf(" You currently have %d gold. ", _player.getCoins()); System.out.println("Heres what we have for sale (all prices are in units of gold) : "); System.out.printf("%-20s%4d ", "1. Long Sword", 120); System.out.printf("%-20s%4d ", "2. Short Sword", 90); System.out.printf("%-20s%4d ", "3. Mace", 80); System.out.printf("%-20s%4d ", "4. Ring of Strength", 150); System.out.printf("%-20s%4d ", "5. Healing Potion", 10); System.out.print("Please enter the item number: "); playerOrder = keyboard.nextInt(); System.out.print("Please enter the quantity: "); quantity = keyboard.nextInt(); // Assumption 1: User will input a positive number. // Assumption 2: User will only order one weapon. switch (playerOrder) { case 1: // Long Sword totalCost = (LONG_SWORD_COST * quantity); break; case 2: // Short Sword totalCost = (SHORT_SWORD_COST * quantity); break; case 3: // Mace totalCost = (MACE_COST * quantity); break; case 4: // Ring of Strength totalCost = (MAGIC_RING_COST * quantity); break; case 5: // Healing Potion totalCost = (HEALING_POTION_COST * quantity); break; default: System.out.printf(" Invalid input. %d is not an available option. ", playerOrder); System.exit(0); } System.out.println(" Total cost: " + totalCost + " gold"); if (quantity >= 3) { discount = (int)(totalCost * 0.10); } else { discount = 0; } System.out.println("Discount: " + discount + " gold"); finalCost = totalCost - discount; if (finalCost Assignment 5: Object-Oriented Programming in the Adventure Game Deadline: Friday, December 8 at 11:59 PM Description In this assignment, you will refactor the adventure game that you coded in Assignment 2; more specifically, you will write and use a number of custom Java classes. Store your updated "Adventure Game" code in a file named AdventureGameFinal.java. Store your classes in the files Player.java, Enemy.java, and Weapon.java. The focus of this assignment is: (1) defining classes; and (2) using objects. New Features You will add three new features to the original game. 1. Improved Pacing (Note; this is a featured that you implemented in Assignment 3) Improve the pacing of the game by prompting the player to hit a key after each minion (i.e. Goblin/Skeleton) fight. So when the player battles multiple minions, instead of simulating all the fights and printing all the outputs together, the first fight will be simulated and its results printed, but then the user will be prompted to hit the Enter key to continue to the next fight. 2. A New, Powerful Weapon In addition to the option of choosing a Healing Potion or a Ring of Strength, present the player with a third option: Staff of Power. Weapon Name: Staff of Power Damage: 5 -9 3. Variable Number of Goblins/Skeletons The number of goblins will be a random number in the range 2-5. The number of skeletons will be a random number in the range 3 - 7
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started