Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java help NEED HELP REWORKING CODE IN THE FOLLOWING WAYS Store your code in a file named AdventureGameV4.java. The focus of this assignment is: (1)

Java help

NEED HELP REWORKING CODE IN THE FOLLOWING WAYS Store your code in a file named AdventureGameV4.java. The focus of this assignment is: (1) working with arrays; and (2) file input/output. 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. Storing Game Results Save the results of each game when the game ends; also, allow the player to print the stored information for each saved game. At the end of a game, save the results of the game to a file in the current directory, and print the message The game results have been saved!. Your program should store the players character name, current weapon, current HP, path taken, and won game (yes or no). Each saved game should be appended to the output file so that the user can save one or more games (note: you may decide on the format of the output file). At the beginning of a game, prompt the player, Would you like to display the saved game results?, and if the user decides to display the results, then your program should print the results of each saved game in a table format (see sample output for examples). Programming Requirements The numeric attribute values for the players character (HP, Strength, minimum weapon damage, maximum weapon damage) must be stored in an int[] array. The numeric attribute values for each enemy (goblin, skeleton, evil wizard) (HP, Strength, minimum weapon damage, maximum weapon damage) must also be stored in an int[] array. Use the printf method to display the saved game results in a table format. Include a multi-line comment at the top of your source file that includes your name, the class abbreviation (CS7), the semester (Fall 2017), 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 10 comments in your code. My code which is what is to be worked off for the prior assignemnt is as follows and it works successfull: import java.util.Scanner; import java.util.Random; public class AdventureGameSolution { public static void main(String[] args) { final int SHORT_SWORD_MIN = 1; final int SHORT_SWORD_MAX = 4; final int LONG_SWORD_MIN = 3; final int LONG_SWORD_MAX = 7; final int JUMP_KICK_MIN = 2; final int JUMP_KICK_MAX = 6; final int AXE_MIN = 2; final int AXE_MAX = 6; final int FIRE_BLAST_MIN = 4; final int FIRE_BLAST_MAX = 10; final int ROGUE_INIT_HP = 55; final int ROGUE_INIT_STRENGTH = 8; final int PALADIN_INIT_HP = 35; final int PALADIN_INIT_STRENGTH = 14; final int CHAN_INIT_HP = 45; final int CHAN_INIT_STRENGTH = 10; final int MINION_INIT_HP = 25; final int GOBLIN_INIT_STRENGTH = 4; final int SKELETON_INIT_STRENGTH = 3; final int WIZARD_INIT_HP = 40; final int WIZARD_INIT_STRENGTH = 8; final int NUM_GOBLINS = 3; final int NUM_SKELETONS = 5; String playerName = ""; int playerHP = 0, playerStrength = 0, playerDamageMin = 0, playerDamageMax = 0; String enemyName = ""; int enemyHP = 0, enemyStrength = 0, enemyDamageMin = 0, enemyDamageMax = 0; int characterChoice = 0, pathChoice = 0, itemChoice = 0, numEnemies = 0; String pathName = ""; int playerDamage, playerATK; int enemyDamage, enemyATK; int playerActionChoice, randomNumAnswer, randomNumGuess; Scanner keyboard = new Scanner(System.in); Random randomNums = new Random(); 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(); switch(characterChoice) { case 1: playerName = "Rogue"; playerHP = ROGUE_INIT_HP; playerStrength = ROGUE_INIT_STRENGTH; playerDamageMin = SHORT_SWORD_MIN; playerDamageMax = SHORT_SWORD_MAX; break; case 2: playerName = "Paladin"; playerHP = PALADIN_INIT_HP; playerStrength = PALADIN_INIT_STRENGTH; playerDamageMin = LONG_SWORD_MIN; playerDamageMax = LONG_SWORD_MAX; break; case 3: playerName = "Jackie Chan"; playerHP = CHAN_INIT_HP; playerStrength = CHAN_INIT_STRENGTH; playerDamageMin = JUMP_KICK_MIN; playerDamageMax = JUMP_KICK_MAX; break; } System.out.printf(" You chose: %s ", playerName); 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(); switch(pathChoice) { case 1: pathName = "The Forest"; enemyName = "Goblin"; enemyStrength = GOBLIN_INIT_STRENGTH; enemyDamageMin = AXE_MIN; enemyDamageMax = AXE_MAX; numEnemies = NUM_GOBLINS; break; case 2: pathName = "The Graveyard"; enemyName = "Skeleton"; enemyStrength = SKELETON_INIT_STRENGTH; enemyDamageMin = SHORT_SWORD_MIN; enemyDamageMax = SHORT_SWORD_MAX; numEnemies = NUM_SKELETONS; break; } System.out.printf(" You chose: %s ", pathName); System.out.printf("Once you enter %s, you encounter %d %ss! Time for battle! ", pathName, numEnemies, enemyName); for (int i = 1; i <= numEnemies; i++) { enemyHP = MINION_INIT_HP; System.out.printf("***%s vs %s %d*** ", playerName, enemyName, i); while(enemyHP > 0 && playerHP > 0) { playerDamage = randomNums.nextInt(playerDamageMax - playerDamageMin + 1) + playerDamageMin; playerATK = playerStrength + playerDamage; enemyHP -= playerATK; System.out.printf("%s attacks with ATK = %d + %d = %d ", playerName, playerStrength, playerDamage, playerATK); System.out.printf("%s HP is now %d - %d = %d ", enemyName, enemyHP + playerATK, playerATK, enemyHP); if (enemyHP <= 0) break; enemyDamage = randomNums.nextInt(enemyDamageMax - enemyDamageMin + 1) + enemyDamageMin; enemyATK = enemyStrength + enemyDamage; playerHP -= enemyATK; System.out.printf("%s attacks with ATK = %d + %d = %d ", enemyName, enemyStrength, enemyDamage, enemyATK); System.out.printf("%s HP is now %d - %d = %d ", playerName, playerHP + enemyATK, enemyATK, playerHP); } // end of while loop if (playerHP > 0) System.out.printf("%s defeated %s %d! ", playerName, enemyName, i); else { System.out.printf("--%s is defeated in battle!-- GAME OVER ", playerName); System.exit(0); } } // end of for loop System.out.printf("Your HP is: %d ", playerHP); System.out.println("Please choose a reward. 1. Healing Potion 2. Ring of Strength "); System.out.print("Which item do you choose?: "); itemChoice = keyboard.nextInt(); switch(itemChoice) { case 1: System.out.println(" You chose: Healing Potion "); playerHP += 10; System.out.printf("Your HP has increased to %d + %d = %d! ", playerHP - 10, 10, playerHP); break; case 2: System.out.println(" You chose: Ring of Strength "); playerStrength += 5; System.out.printf("Your Strength has increased to %d + %d = %d! ", playerStrength - 5, 5, playerStrength); } System.out.println("You have now reached The Castle! Time to battle The Evil Wizard! "); enemyName = "Wizard"; enemyHP = WIZARD_INIT_HP; enemyStrength = WIZARD_INIT_STRENGTH; enemyDamageMin = FIRE_BLAST_MIN; enemyDamageMax = FIRE_BLAST_MAX; randomNumAnswer = randomNums.nextInt(6) + 1; System.out.printf("***%s vs The Evil Wizard*** ", playerName); while(playerHP > 0 && enemyHP > 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: playerDamage = randomNums.nextInt(playerDamageMax - playerDamageMin + 1) + playerDamageMin; playerATK = playerStrength + playerDamage; enemyHP -= playerATK; System.out.printf(" %s attacks with ATK = %d + %d = %d ", playerName, playerStrength, playerDamage, playerATK); System.out.printf("%s HP is now %d - %d = %d ", enemyName, enemyHP + playerATK, playerATK, enemyHP); 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! ", playerName); enemyHP = 0; } else System.out.println(" Incorrect! The spell cast fails! "); break; } if (enemyHP <= 0) break; enemyDamage = randomNums.nextInt(enemyDamageMax - enemyDamageMin + 1) + enemyDamageMin; enemyATK = enemyStrength + enemyDamage; playerHP -= enemyATK; System.out.printf("%s attacks with ATK = %d + %d = %d ", enemyName, enemyStrength, enemyDamage, enemyATK); System.out.printf("%s HP is now %d - %d = %d ", playerName, playerHP + enemyATK, enemyATK, playerHP); } // end of while loop if (playerHP > 0) { System.out.printf("--%s wins the battle!-- ", playerName); System.out.println("You win! Congratulations!"); } else { System.out.printf("--%s is defeated in battle!-- GAME OVER ", playerName); } } // end of main } // end of class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

=+31-4 Discuss the information we process automatically.

Answered: 1 week ago