Question: Description In this assignment, you will refactor the adventure game that you coded in Assignments 2 and 3; more specifically, you will write and use

Description In this assignment, you will refactor the adventure game that you coded in Assignments 2 and 3; more specifically, you will write and use a number of custom Java classes and also make a few gameplay changes. Store your refactored Adventure Game code in a file named AdventureGameV2.java . Store your classes in the files Character.java , Player.java , Enemy.java , and Weapon.java, and Potion.java . The focus of this assignment is: (1) defining classes; (2) using inheritance; and (2) using objects. Changes to the Gameplay ? The player will go through both the Forest and the Graveyard, in that order. ? The player will have an inventory that can store up to 5 potions. ? The inventory will be implemented as an array of Potion objects. ? The goblins and skeletons will drop coins when defeated. ? Each goblin/skeleton will drop a random number of coins in the range of 30 - 50 coins. ? When an enemy drops coins, add the number of coins dropped to the players coin total. ? Before visiting the Graveyard and before battling the Wizard, the player will have the option to do one or more of the following: ? View stats ? This will print out the players current stats (to do this, simply print the string that is returned by the Player classs toString method). ? View the inventory ? The players inventory has 5 slots; each slot can hold 1 potion. When the player chooses to view the inventory, display a row for each slot, with the row number in brackets and the item name to the right of that (display the empty string if the slot is empty). For example, assume that my player has 3 items, with an item in slots 1, 3 and 4. Then my inventory display would look like the following: [1] Healing Potion [2] [3] Minor Strength Potion [4] Minor Healing Potion [5] ? Purchase a potion ? 2 types of Healing Potions - Minor Healing (5 Gold) and Healing (10 Gold) ? A Minor Healing Potion adds 5 HP; a Healing Potion adds 10 ? 2 types of Strength Potions - Minor Strength (20 Gold) and Strength (40 Gold) ? A Minor Strength Potion adds 2 to strength; a Strength Potion adds 5 ? Each potion purchased should be added to the players inventory but only if there is an empty spot in the inventory. ? When adding a new item to the inventory, you may add it in any open slot. ? Drink a potion ? When the player purchases a potion, the potion will not be applied and will instead be added to the players inventory. The player can drink the potion when given the option to do so; drinking the potion will apply its effect. ? When a player drinks a potion, the potion should be removed from the inventory. ? Check out the example output for a demonstration of these new features in action. Class Descriptions ? Character (abstract class) ? Public enum ? Name: Type ? Values: ROGUE, PALADIN, JACKIE_CHAN, GOBLIN, SKELETON, WIZARD ? Attributes ? name (String) ? hitPoints (int) ? strength (int) ? weapon (Weapon) ? Methods ? Character(characterType) ? This method is the only constructor of the Character class. Based on the value of characterType, set the proper String for the name, int for the initial hit points, int for the strength attribute, and reference to a Weapon object for the weapon. ? getName() ? This method should return the name as a String. ? getHitPoints() ? This method should return the number of hit points. ? getStrength() ? This method should return the value of the strength attribute. ? increaseStrength(strengthIncrease) ? This method will add the passed value to the players strength attribute. ? setWeapon(weapon) ? This method will set the players weapon to be the Weapon object that is passed to the method. ? attack(opponent) ? This method will simulate an attack against the Character object that is passed to the method. ? increaseHitPoints(pointIncrease) ? This method will add the number of points passed to the hit points. ? decreaseHitPoints(pointDecrease) ? This method will subtract the number of points passed from the hit points. ? isDefeated() ? This method will return true if the players hit points value is 0 or less; otherwise, it will return false. ? toString() ? This method will return a String that gives the current values of name, hitPoint, strength, weapon. Here is an example: Name: Paladin Hit Points: 35 Strength: 14 Weapon: Long Sword (3 - 7) ? Player (extends Character class) ? Attributes ? coins (int) ? inventory (Potion[]) ? Methods ? Player(playerType) ? This method is the only constructor of the Player class. In this method, call the superclass constructor with the value playerType, initialize coins to 0, and set inventory to a new array of 5 Potion objects. ? getCoins() ? This method will return the number of coins. ? increaseCoins(coins) ? This method will add the number of coins passed to the players coin total. ? decreaseCoins(coins) ? This method will subtract the number of coins passed from the players coin total. ? addToInventory(potion) ? This method will take a Potion object and add it to the players inventory if and only if there is an open slot; do nothing if the attempt fails. ? removeFromInventory(index) ? This method will take an index in the range of 1 - 5 and return a reference to the Potion object that resides at that index. If no Potion object is at the specified index, then return null. ? displayInventory() ? This method will print out the players inventory in the format specified in the Changes to the Gameplay section. ? getNumOpenSlots() ? This method will return the number of open slots in the players inventory. Use this method to determine if a player may add potions to the inventory. ? battleMinion(enemy) ? This method will simulate a battle against the Enemy object that is passed to the method, where that object is a goblin or skeleton . ? battleWizard(enemy) ? This method will simulate a battle against the Enemy object that is passed to the method, where that object is a wizard . ? toString() ? This method will call the superclasss toString method and add one line to it for the number of coins. Here is an example: Name: Paladin Hit Points: 35 Strength: 14 Weapon: Long Sword (3 - 7) Coins: 114 ? Enemy (extends Character class) ? Methods ? Enemy(enemyType) ? This method is the only constructor of the Enemy class. In this method, call the superclass constructor with the value enemyType. ? dropCoins() ? This method will return a positive integer that represents the number of coins that the enemy dropped (this will be a random int that is in the range of 30 - 50). ? getNumGoblins() ? This is a static method that will return a random int that is in the range 2 - 5. ? getNumSkeletons() ? This is a static method that will return a random int that is in the range 3 - 7. ? Weapon ? Public Constants ? Add all of the weapon-damage-related constants (e.g. SHORT_SWORD_MIN) to this class as public, static constants. You will then be able to reference a constant in your main method by preceding the name of the constant with the name of the class (e.g. Weapon.SHORT_SWORD_MIN). ? Attributes ? name (String) ? minDamage (int) ? maxDamage (int) ? Methods ? Weapon(name, minDamage, maxDamage) ? This method is the only constructor of the Weapon class. Pass to this method a String for the name, an int for the minimum damage, and an int for the maximum damage. ? getName() ? This method should return the name as a String. ? getMinDamage() ? This method will return the minimum damage of the weapon. ? getMaxDamage() ? This method will return the maximum damage of the weapon. ? getDamage() ? This method will return a random int that is in the range of the minimum and maximum damage values. ? Potion ? Public enum ? Name: Type ? Values: MINOR_HEALING, HEALING, MINOR_STRENGTH, STRENGTH ? Attributes ? name (String) ? type (Type) ? Methods ? Potion(potionType) ? This method is the only constructor of the Potion class. In this method, initialize type to the passed in value, then set name based on type (valid names are: Minor Healing Potion, Healing Potion, Minor Strength Potion, Strength Potion) ? getName() ? This method should return the name as a String. ? drink(player) ? This method should apply the effect of the potion, based on the potions type (e.g. If its a Minor Strength potion, then it should add 2 to the players strength) (note that a reference to the player is being passed to this method - use this reference to call the proper method in the Player class) Programming Requirements ? Implement the gameplay that defines the Adventure Game from Assignment 3 and include the changes and new features that are listed above in the Changes to the Gameplay section. ? Define and properly use all of the classes described above. ? Attributes for the player, enemies and weapons must be stored in objects of the proper class, not in primitive variables or arrays. ? Every method of every class should be called at least once in your AdventureGameV2 class or in one of your other classes. ? Include a multi-line comment at the top of your source file that includes your name, the class (CS401), the semester (Spring 2018), and the assignment name (Assignment 4), with each item on its own line. ? Use good programming style. Specifically, in addition to the multi-line comment described above, include at least 5 comments in each class file . ? Global variables are prohibited (except for constants).

This is the previous assignment to be edited. import java.util.Scanner; public class AdventureGameWithObjects { public static void main(String[] args) { int characterChoice = 0; int pathChoice = 0; int itemChoice = 0; int numEnemies = 0; String pathName = ""; Scanner keyboard = new Scanner(System.in); System.out.println(" Adventure Game - Start! "); System.out.println("Here are the characters:"); System.out.println("1. Rogue 2. Paladin 3. Jackie Chan "); System.out.print("Which character do you choose?: "); characterChoice = keyboard.nextInt(); //Create Objects Player Player = new Player(); Enemy Minion = new Enemy(); Enemy Wizard = new Enemy(); Weapon fireBlast = new Weapon(); Weapon axe = new Weapon(); Weapon shortSword = new Weapon(); Weapon longSword = new Weapon(); Weapon jumpKick = new Weapon(); Weapon staff = new Weapon(); //Weapons shortSword.Weapon("Short Sword", 1, 4); longSword.Weapon("Long Sword", 3, 7); jumpKick.Weapon("Jump Kick", 2, 6); fireBlast.Weapon("Fire Blast",4,10); staff.Weapon("Staff of Power", 5, 9); axe.Weapon("Axe",2,6); //Determine Character's class switch(characterChoice) { case 1: Player.Player("Rogue",55,8,shortSword); break; case 2: Player.Player("Paladin",35,14,longSword); break; case 3: Player.Player("Jackie Chan",45,10,jumpKick); break; } 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 "); System.out.print("Which path will you take?: "); pathChoice = keyboard.nextInt(); //Determine player path for type of enemy switch(pathChoice) { case 1: pathName = "The Forest"; Minion.Enemy("Goblin", 25,4,axe); numEnemies = Minion.getNumGoblins(); break; case 2: pathName = "The Graveyard"; Minion.Enemy("Skeleton", 25,3,shortSword); numEnemies = Minion.getNumSkeletons(); break; } System.out.printf(" You chose: %s ", pathName); System.out.printf("Once you enter %s, you encounter %d %ss! Time for battle! ", pathName, numEnemies, Minion.getName()); //battle minions for (int i = 1; i <= numEnemies; i++) { Minion.resetHitPoints(); System.out.printf("***%s vs %s %d*** ", Player.getName(), Minion.getName(), i); Player.battleMinion(Minion); if (Player.isDefeated()) { System.out.printf("--%s is defeated in battle!-- GAME OVER ", Player.getName()); System.exit(0); } else { System.out.printf("%s defeated %s %d! ", Player.getName(), Minion.getName(), i); System.out.println("Press \"Enter\" to continue..."); Scanner scanner = new Scanner(System.in); scanner.nextLine(); } } System.out.printf("Your HP is: %d ", Player.getHitPoints()); System.out.println("Please choose a reward. 1. Healing Potion 2. Ring of Strength 3. Staff of Power "); System.out.print("Which item do you choose?: "); itemChoice = keyboard.nextInt(); //Decide which item the player chooses and alter stats switch(itemChoice) { case 1: System.out.println(" You chose: Healing Potion "); Player.increaseHitPoints(10); System.out.printf("Your HP has increased to %d + %d = %d! ", Player.getHitPoints() - 10, 10, Player.getHitPoints()); break; case 2: System.out.println(" You chose: Ring of Strength "); Player.increaseStrength(5); System.out.printf("Your Strength has increased to %d + %d = %d! ", Player.getStrength() - 5, 5, Player.getStrength()); break; case 3: System.out.println(" You chose: Staff of Power "); Player.setWeapon(staff); System.out.println("Your weapon damage is now 5 - 9 "); break; } System.out.println("You have now reached The Castle! Time to battle The Evil Wizard! "); Wizard.Enemy("Wizard", 40, 8, fireBlast); //Fight the Wizard Player.battleWizard(Wizard); if (Player.getHitPoints() > 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()); } } }
import java.util.Random; import java.util.Scanner; public class Player { //Attributes private String name; private int strength; private int hitPoints; private Weapon weapon; //Player Methods public void Player(String _name, int _hitPoints, int _strength, Weapon _weapon){ // Constructor for the Player class name = _name; strength = _strength; hitPoints = _hitPoints; weapon = _weapon; } public String getName(){ return name; } public int getHitPoints(){ return hitPoints; } public void increaseHitPoints( int _pointIncrease){ // Increase hitpoints by amount specified hitPoints = hitPoints + _pointIncrease; } public void decreaseHitPoints(int _pointDecrease){ // decrease hitpoints by amount specified hitPoints = hitPoints - _pointDecrease; } public int getStrength(){ return strength; } public void increaseStrength(int _strengthIncrease){ // Increase strength by amount specified strength = strength + _strengthIncrease; } public void setWeapon(Weapon _weapon){ // Change player's weapon to the one specified weapon = _weapon; } public void attack(Enemy _enemy){ int playerDamage; int playerATK; int oldEnemyHP; //calculate player and enemy damage and display old health compared to the new //Print out how the new health is calculated playerDamage = weapon.getDamage(); playerATK = getStrength() + playerDamage; oldEnemyHP = _enemy.getHitPoints(); _enemy.decreaseHitPoints(playerATK); System.out.printf("%s attacks with ATK = %d + %d = %d ", getName(), getStrength(), playerDamage, playerATK); System.out.printf("%s HP is now %d - %d = %d ", _enemy.getName(), oldEnemyHP, playerATK, _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 randomNumGuess; int randomNumAnswer; int playerActionChoice; //get the number that will instantly kill the wizard 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: "); playerActionChoice = keyboard.nextInt(); switch(playerActionChoice) { case 1: this.attack(_enemy); break; case 2: System.out.print("Enter your guess: "); 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! ", getName()); _enemy.decreaseHitPoints(_enemy.getHitPoints()); } else //number is wrong so the player skips his turn System.out.println(" Incorrect! The spell cast fails! "); break; } if (_enemy.getHitPoints() <= 0) { break; } _enemy.attack(this); } if (this.isDefeated()) { System.out.printf("--%s is defeated in battle!-- GAME OVER ", name); System.exit(0); } } public Boolean isDefeated(){ //checks if player is defeated hitPoints = getHitPoints(); if (hitPoints <= 0){ return true; } else{ return false; } } }
import java.util.Random; public class Weapon { //Attributes private String name; private int minDamage; private int maxDamage; // Weapon Methods public void Weapon(String _name, int _minDamage, int _maxDamage){ // Constructor for the Weapon class name = _name; minDamage = _minDamage; maxDamage = _maxDamage; } public String getWeaponName(){ return name; } public int getMaxDamage(){ return maxDamage; } public int getMinDamage(){ return minDamage; } public int getDamage(){ int damage; Random randomNums = new Random(); damage = randomNums.nextInt((getMaxDamage() - getMinDamage()) + 1) + getMinDamage(); return damage; } } 
import java.util.Random; public class Enemy { //Attributes private String name; private int hitPoints; private int strength; private Weapon weapon; // Enemy Methods public void Enemy(String _name, int _hitPoints, int _strength, Weapon _weapon){ // Constructor for the Enemy class name = _name; strength = _strength; hitPoints = _hitPoints; weapon = _weapon; } public String getName(){ return name; } public int getHitPoints(){ return hitPoints; } public void resetHitPoints(){ hitPoints = 25; } public void decreaseHitPoints(int _pointDecrease){ hitPoints = hitPoints - _pointDecrease; } public int getStrength(){ return strength; } public void attack(Player _player){ int enemyDamage; int enemyATK; int oldPlayerHP; //calculate player and enemy damage and display old health compared to the new //Print out how the new health is calculated enemyDamage = weapon.getDamage(); enemyATK = getStrength() + enemyDamage; oldPlayerHP = _player.getHitPoints(); _player.decreaseHitPoints(enemyATK); System.out.printf("%s attacks with ATK = %d + %d = %d ", getName(), getStrength(), enemyDamage, enemyATK); System.out.printf("%s HP is now %d - %d = %d ", _player.getName(), oldPlayerHP, enemyATK, _player.getHitPoints()); } public Boolean isDefeated(){ //checks if enemy is defeated hitPoints = getHitPoints(); if (hitPoints <= 0){ //Check if this is a thing return true; } else { return false; } } public int getNumGoblins(){ //Choose number of goblins between 2 -5 Random rand = new Random(); int NUM_GOBLINS = rand.nextInt((5 - 2) + 1) + 2; return NUM_GOBLINS; } public int getNumSkeletons(){ //Choose number of skeletons between 3 - 7 Random rand = new Random(); int NUM_SKELETONS = rand.nextInt((7-3) + 1) + 3; return NUM_SKELETONS; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!