Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have programmed the game already, but now i need to figure out how to put it to a GUI. This is my game code:

I have programmed the game already, but now i need to figure out how to put it to a GUI.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

This is my game code:

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  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) 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) { 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

This is the MessageBox Class file

import javafx.application.*; import javafx.stage.*; import javafx.scene.*; import javafx.scene.layout.*; import javafx.scene.control.*; import javafx.geometry.*; public class MessageBox { public static void show(String message, String title) { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); stage.setTitle(title); stage.setMinWidth(250); Label lbl = new Label(); lbl.setText(message); Button btnOk = new Button(); btnOk.setText("OK"); btnOk.setOnAction(e -> stage.close()); VBox pane = new VBox(20); pane.getChildren().addAll(lbl, btnOk); pane.setAlignment(Pos.CENTER); Scene scene = new Scene(pane, 300, 200); stage.setScene(scene); stage.showAndWait(); } }
In this assignment, you will write a GUI-based program that simulates battles between a player and an enemy. Your program wil allow the user to choose values for different settings of the battle, such as the characters and the weapons, as well as the number of enemies that the player will battle. After the settings are configured, the user may run a simulation and later view the results of the simulation that include the total number of enemies defeated. The Graphical User Interface The figure below shows the state of the GUI when the program begins. The GUI contains controls that allow the user to select the player character, the player's weapon, the enemy's character, the enemy's weapon, the number of enemies per round, and the number of rounds of battle; the buttons at the bottom allow the user to run the battle simulation or exit the program. ADVENTURE GAME BATTLE SIMULATOR PLAYER OPTIONS ENEMY Paladin Rogue Jackie Chan Goblin Skeletorn Number of enemies 4 enemies 5 enemies 6 enemies Number of rounds 1 round Mace Short Sword Long Swored Axe 5 rounds 10 rounds 20 rounds Mace Short Sword Long Sword Axe SELECT PLAYER SELECT ENEMY In this assignment, you will write a GUI-based program that simulates battles between a player and an enemy. Your program wil allow the user to choose values for different settings of the battle, such as the characters and the weapons, as well as the number of enemies that the player will battle. After the settings are configured, the user may run a simulation and later view the results of the simulation that include the total number of enemies defeated. The Graphical User Interface The figure below shows the state of the GUI when the program begins. The GUI contains controls that allow the user to select the player character, the player's weapon, the enemy's character, the enemy's weapon, the number of enemies per round, and the number of rounds of battle; the buttons at the bottom allow the user to run the battle simulation or exit the program. ADVENTURE GAME BATTLE SIMULATOR PLAYER OPTIONS ENEMY Paladin Rogue Jackie Chan Goblin Skeletorn Number of enemies 4 enemies 5 enemies 6 enemies Number of rounds 1 round Mace Short Sword Long Swored Axe 5 rounds 10 rounds 20 rounds Mace Short Sword Long Sword Axe SELECT PLAYER SELECT ENEMY

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

More Books

Students also viewed these Databases questions

Question

1. What is meant by Latitudes? 2. What is cartography ?

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

1. Outline the listening process and styles of listening

Answered: 1 week ago

Question

4. Explain key barriers to competent intercultural communication

Answered: 1 week ago