Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can I get help with this java program? I wrote the Player , Weapon and enemy parts. Just need the Potion and Chracter java parts.

Can I get help with this java program? I wrote the Player , Weapon and enemy parts. Just need the Potion and Chracter java parts.

AdventurGame.java

import java.util.Scanner;

import java.util.Random;

public class AdventureGame

{

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

{

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

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

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

Player.java

class Player{

private String name;

private int hitPoint;

private int strengthPoint;

private Weapon weapon;

public Player(String name,int hitPoint,int strengthPoint,Weapon weapon){

this.name = name;

this.hitPoint = hitPoint;

this.strengthPoint = strengthPoint;

this.weapon = weapon;

}

public String getName(){

return this.name;

}

public int getHitPoint(){

return this.hitPoint;

}

public void increaseHitPoint(int strengthIncreased){

this.hitPoint = this.hitPoint+strengthIncreased;

System.out.printf("Your HP has increased to %d + %d = %d! ", hitPoint - 10, 10, hitPoint);

}

public void decreaseHitPoint(int decPoint){

this.hitPoint = this.hitPoint = decPoint;

}

public void increaseStrengthPoint(int incPoint){

this.strengthPoint = this.strengthPoint+incPoint;

System.out.printf("Your Strength has increased to %d + %d = %d! ", strengthPoint - 5, 5,strengthPoint);

}

public void setWeapon(Weapon weapon){

this.weapon = weapon;

}

public void attack(Enemy enemy){

int playerDamage = weapon.getDamage();

int playerAtk = strengthPoint + playerDamage;

enemy.decreaseHitPoint(playerAtk);

System.out.printf("%s attacks with ATK = %d + %d = %d ", this.getName(), this.strengthPoint, playerDamage, playerAtk);

System.out.printf("%s HP is now %d - %d = %d ", enemy.getName(), enemy.getHitPoints() + playerAtk, playerAtk,enemy.getHitPoints());

}

public void battleMinion(Enemy enemy){

}

public void battleWizard(Enemy enemy){

}

public boolean isDefeated(){

if(this.hitPoint

return true;

else

return false;

}

}

Weapon.java

class Weapon{

public static final int SHORT_SWORD_MIN = 1;

private String name;

private int minDamage;

private int maxDamage;

public Weapon(String name,int minDamage,int maxDamage){

this.name = name;

this.minDamage = minDamage;

this.maxDamage = maxDamage;

}

public String getName(){

return this.name;

}

public int getMinDamage(){

return this.minDamage;

}

public int getMaxDamage(){

return this.maxDamage;

}

public int getDamage(){

int randomNum = ThreadLocalRandom.current().nextInt(getMinDamage(), getMaxDamage() + 1);

return randomNum;

}

}

Enemy.java

class Enemy{

private String name;

private int hitPoint;

private int strength;

private Weapon weapon;

public Enemy(String name,int hitPoint,int strength,Weapon weapon){

this.name = name;

this.hitPoint = hitPoint;

this.strength = strength;

this.weapon = weapon;

}

public String getName(){

return this.name;

}

public int getHitPoints(){

return this.hitPoint;

}

public void resetHitPoints(){

this.hitPoint = 25;

}

public void decreaseHitPoint(int decPoint){

this.hitPoint = this.hitPoint - decPoint;

}

public void attack(Player player){

int enemyDamage = weapon.getDamage();

int enemyATK = this.strength + enemyDamage;

player.decreaseHitPoint(enemyATK);

System.out.printf("%s attacks with ATK = %d + %d = %d ", this.getName(), this.strength, enemyDamage, enemyATK);

System.out.printf("%s HP is now %d - %d = %d ", player.getName(), player.getHitPoint() + enemyATK, enemyATK, player.getHitPoint());

}

public boolean isDefeated(){

if(this.hitPoint

return true;

else

return false;

}

public static int getNumGoblins(){

//Plus one to make range inclusive

int randomNum = ThreadLocalRandom.current().nextInt(2,5 + 1);

return randomNum;

}

public static int getNumSkeletons(){

int randomNum = ThreadLocalRandom.current().nextInt(3,7 + 1);

return randomNum;

}

}

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

SampleOutput:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In this assignment, you will refactor the adventure game that you coded in Assignments 2 and3; 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 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 o The inventory will be implemented as an array of Potion objects . The goblins and skeletons will drop coins when defeateg o Each goblin/skeleton will drop a random number of coins in the range of 30 50 coins o When an enemy drops coins, add the number of coins dropped to the player's 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 o View stats This will print out the player's current stats (to do this, simply print the string that is returned by the Player class's tostring method) o View the inventory The player's 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 121 [3] Minor Strength Potion [4] Minor Healing Potion 15] o 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 In this assignment, you will refactor the adventure game that you coded in Assignments 2 and3; 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 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 o The inventory will be implemented as an array of Potion objects . The goblins and skeletons will drop coins when defeateg o Each goblin/skeleton will drop a random number of coins in the range of 30 50 coins o When an enemy drops coins, add the number of coins dropped to the player's 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 o View stats This will print out the player's current stats (to do this, simply print the string that is returned by the Player class's tostring method) o View the inventory The player's 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 121 [3] Minor Strength Potion [4] Minor Healing Potion 15] o 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

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

Students also viewed these Databases questions