Question: SOLUTION IN JAVA PLEASE For this assignment, we will create a simple battle system for a JRPG style game. The battle system will simulate a

SOLUTION IN JAVA PLEASE

For this assignment, we will create a simple battle system for a JRPG style game. The battle system will simulate a battle between a human player and a CPU player. Each player will have their 'monster' that will battle one another using a selection of moves.

Your classes should work given any configuration of players and monsters. An example driver class (GameDriver) that tests the various classes that you will eventually implement has been provided, below:

public class GameDriver { public static void main(String[] args) { Move move1 = new Move("Vine Whip", "Grass", 45, 1.0f); Move move2 = new Move("Tackle", "Normal", 50, 1.0f); Move move3 = new Move("Take Down", "Normal", 90, 0.85f); Move move4 = new Move("Razor Leaf", "Grass", 55, 0.95f); Monster monster = new Monster("Bulbasaur", "Grass",240, 45, 49, 49,move1, move2, move3, move4); Player player = new HumanPlayer(monster); move1 = new Move("Scratch", "Normal", 40, 1.0f); move2 = new Move("Ember", "Fire", 40, 1.0f); move3 = new Move("Peck", "Flying", 35, 1.0f); move4 = new Move("Fire Spin", "Fire", 35, 0.85f); monster = new Monster("Torchic", "Fire", 240, 45, 60, 40,move1, move2, move3, move4); Player enemy = new CPUPlayer(monster); while ((!player.hasLost()) && (!enemy.hasLost())) { // print both monsters' HP System.out.println(""); System.out.printf("%s has %d HP ", player.getMonster().getName(), player.getMonster().getHP()); System.out.printf("%s has %d HP ", enemy.getMonster().getName(), enemy.getMonster().getHP());

// decide the next move int playerMove = player.chooseMove(); int enemyMove = enemy.chooseMove(); // execute the next move if (player.isFasterThan(enemy)) { player.attack(enemy, playerMove); if (!enemy.hasLost()) { enemy.attack(player, enemyMove); } } else { enemy.attack(player, enemyMove); if (!player.hasLost()) { player.attack(enemy, playerMove); } } } if (player.hasLost()) { System.out.printf("You and %s have lost the battle. ", player.getMonster().getName()); } else { System.out.printf("You and %s are victorious! ",player.getMonster().getName()); } } }

Upon examining this driver code, you will see that you need to implement the following classes:

Player - represents players in general

This class has no constructor

HumanPlayer - selects moves by asking the user via console input

Constructor arguments:

monster (Monster) - the player's battling monster

CPUPlayer - selects moves by generating a random number

Constructor arguments:

monster (Monster) - the player's battling monster

Monster - represents a monster with four available moves

Constructor arguments:

name (String) - the name of the creature

type (String) - the type of the creature

hp (int) - the hit points of the creature

speed (int) - the speed stat of the creature

attack (int) - the attack stat of the creature

defense (int) - the defense stat of the creature

move1 (Move) - the first move

move2 (Move) - the second move

move3 (Move) - the third move

move4 (Move) - the fourth move

Move - represents a single move

Constructor arguments:

name (String) - the name of the move

type (String) - the type of the move

power (int) - the attack power of the move

accuracy (float) - 0.0-1.0, representing the hit percentage for the move

You are welcome to create any additional classes required to implement the correct behaviour. The battle system first asks each player to choose their next move. The CPU player will select their move randomly. The human player will present a list of moves to the user on the console, and ask the user to select one (e.g. by entering a number 1-4) on the console. The battle system then selects which monster is faster (a monster with a higher speed stat is faster). The faster monster uses their move first. Then, determine if the move will hit the defending monster. Generate a random floating point number between 0.0 and 1.0. If the number is greater than the accuracy of the move (impossible for some moves that have accuracy 1.0), then the move is a miss and no damage is dealt to the defending monster. Each move's attack is calculated using the following formula:

damageDealth = attacking monster's attack stat + attacking monster move's power - defending monster's defense stat

The calculated damage is then subtracted from the HP of the defending monster. If the HP becomes less than (or equal to) zero, the monster is dead and cannot attack any further, including the move selected at the beginning of this round. If both monsters are still alive when the round has finished, the process repeats. When finished, the driver class will display a message determining if the human player has won or lost the battle.

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!