Page 1 of 1

Exercise 1: Creating the PlayableCharacter class We will now be creating the PlayableCharacter class. This class will co

Posted: Fri Jul 01, 2022 5:37 am
by answerhappygod
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 1
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 1 (46.47 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 2
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 2 (72.19 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 3
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 3 (49.81 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 4
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 4 (44 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 5
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 5 (41.96 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 6
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 6 (52.72 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 7
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 7 (28.14 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 8
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 8 (28.14 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 9
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 9 (30.14 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 10
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 10 (34.14 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 11
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 11 (27.53 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 12
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 12 (33.06 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 13
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 13 (43.09 KiB) Viewed 50 times
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 14
Exercise 1 Creating The Playablecharacter Class We Will Now Be Creating The Playablecharacter Class This Class Will Co 14 (39.05 KiB) Viewed 50 times
Exercise 1: Creating the PlayableCharacter class We will now be creating the PlayableCharacter class. This class will contain methods that will allow it to interact with the Enemy class. D. Add our class fields to the PlayableCharacter java class. Remember to use the "private" access modifier as we are continuing to practice encapsulation. These fields are chosen to represent a bare-minimum playable character, but this list of variables can be expanded in the future. //class fields private String name: private int currentHitPointe = 10; private int weaponDamage private int locationx = 0; 5: private int locationY= 0; E. Let's let Eclipse generate getters and setters for us. Remember that it is under Source > Generate Getters and Setters. F. Now, we want to add some logic to our PlayableCharacter class. We will add methods to be able to do the following: A. Receive damage, lowering our playable character's current hitpoints by the damage amount B. Attack an enemy, causing the enemy to take damage equal to our weapon damage. We will make the enemy class later. C. Override the toString method, so that we can show the current status of the player. We will use String format here to create a formatted String. Remember that the arguments after the String in String format will be used to replace the Format Specifiers (ie. %s or %d etc.). For something like String.format("Hello %a", "world"), the is will be replaced with "world". We are overriding the toString method since it exists in the parent class Object. All classes inherit from the Object class. D. Override the equals method, so that we can determine if one character is "equivalent" to another character based on their names. It will take an Object as a parameter and we will cast it to a PlayableCharacter object so we can use its getName() method. We are overriding the equals method since it exists in the parent class Object. All classes inherit from the Object class G. To accomplish our previous point, add the following code to your class //Lover our current hitpoints by the damageTaken argument public void receiveDamage(int damageTaken) ( damageTaken: this.currentHitPoints 1/object interaction. The parameter is an Enemy object //We call the enemy's receiveDamage method within this attackEnemy method public void attackEnemy (Enemy enemy) ( enemy receiveDamage (this.weaponDamage); > public string toString() { //ks means String //td means decimal number (integer) return String.format("sa location: sd, 1d. HitPo: nta: d\n", this.getName(), this.getLocationX(), this.getLocation(). this.getCurrentHitPoints()); > public boolean equals(object other) { //Cast the object parameter to a PlayableCharacter so we can access its name //If the name of the current PlayableCharacter equals the other PlavableCharacter being passed as a parameter, return true. Else. return
G. To accomplish our previous point, add the following code to your class: //Lower our current hitpoints by the damageTaken argument public void receiveDamage (int damageTaken) { this.currentHitPoints == damageTaken; } //Object interaction. The parameter is an Enemy object //We call the enemy's receiveDamage method within this attackEnemy method public void attackEnemy (Enemy enemy) { enemy.receive Damage (this.weaponDamage); } public String toString() { //%s means String //%d means decimal number (integer) return String.format("%s location: %d, &d. HitPoints: %d\n", this.getName(), this.getLocationX(), this.getLocationY ( ), this.getCurrentHitPoints()); } public boolean equals (Object other) { //Cast the Object parameter to a PlayableCharacter so we can access its name //If the name of the current PlayableCharacter equals the other PlayableCharacter being passed as a parameter, return true. Else, return false. PlayableCharacter tempCast = (PlayableCharacter) other; (this.name.equals(tempCast.getName())){ if } else { return true; return false; H. Finally, let's create our class constructor. It should do the following: A. Take a String that represents the playable character's name and assign the value to the name variable. I. With all of the previous step, we can create our constructor with the following code: public playableCharacter (String name) { this.name = name; //Alternatively, you could have used setName to set the name }
Exercise 2: Creating the Enemy class We will now be creating the Enemy class. This class will contain methods that will allow it to interact with the PlayableCharacter. B. Add our class fields to the Enemy java class. Remember to use the "private access modifier as we are continuing to practice encapsulation. These fields are chosen to represent a bare-minimum Enemy, but this list of variables can be expanded in the future. //class fields private String name: private int currentHitPoints - 4; private int veaponDamage = 2; private int locationx = 0; private int location! 0: C. Just like in exercise 1. generate getters and setters for each of these fields. D. Now, we want to create methods that will handle some logic for enemies. We want to make methods that do the following: A. Receive damage, lowering the enemy's hitpoints by the damage amount B. Attack a playable character, causing the playable character to take damage equal to the enemy's weapon damage. C. Override the toString method, so that we can show the current status of the enemy, We will use String format here to create a formatted String. D. Override the equals method, so that we can determine if one Enemy is "equivalent" to another Enemy based on their names. It will take an Object as a parameter and we will cast it to an Enemy object so we can use its getName() method. E. As you may notice, we created methods in PlayableCharacter that were nearly identical to these. Implement these methods and feel free to reuse code! Here are the method headers and empty method bodies for those two methods: public void receiveDanage(int damageTaken) { } public void attackPlayableCharacter (PlayableCharacter player) { } public String toString() { } public boolean equals(Object other) { F. Let's create our class constructor. It should do the following: A. Take a String that represents the enemy's name and assign the value to the name variable. B. Take an int that represents the enemy's X location and assign the value to the location X variable. C. Take an int that represents the enemy's Y location and assign the value to the location Y variable. F. With all of the previous step, we can create our constructor. Create the constructor for the Enemy class on your own. G. Finally, let's create another constructor that will use constructor chaining so we can provide some default values. It should do the following: A. Take a String as a parameter that represents the enemy's name. B. Call the other class constructor using the String parameter as the name argument, 2 as the location X argument, and 3 as the location Y argument. Remember that you can use this arguments here) within a constructor to call another constructor (constructor chaining), H. We have finished the Enemy class! Make sure there are no syntax errors (red underlines)
Exercise 3: Creating the Game class We will now be creating the Game class. This class will contain the game logic that uses the PlayableCharacter and Enemy classes to create a simple game. A. We want the main method to use a Scanner object to ask for the player's name. This Scanner object will also be used later for playing the game. Let's add the code for creating a Scanner object and asking for the player's name Scanner input = new Scanner(System.in); System.out.print("Welcome to the Dungeon! What is your character's name? (Input name then press enter): "); input.nextLine(); String playerName //Create instance of PlayableCharacter with inputed nane PlayableCharacter pe new PlayableCharacter (playerName); System.out.println("Hello, + pc.getName()); B. We will now create a simple Enemy object called zombie. We will use the constructor with "Zombie" as the name, 2 as the location X, and 3 as the location Y * Enemy class constructor has 3 arguments. * Argument 11 String name • Argument 2: int locationx * Argument 3: int location Enemy zombie - new Enemy("Zombie", 2, 3); C. Now, we will create the "game loop". This loop will handle the turns of the player and enemy while the player's hitpoints are not below 0 and while the player's location is not where the "stairs" are located (at 6,6). The condition of this loop will do the following three A. Check if the player's X location is 6 B. Check if the player's Y location is 6 C. Check if the player's current hitpoints is above 0 11 GAME LOOP START 11 while ((pe.getLocation()64 pe.getLocationY() 6) 66 pc.getCurrentlitPoints() > 0) { A. Let us print out both the player and the zombie (only if the zombie's current hitpoints are above 0: System.out.print(pc); if (zombie.getCurrentitPoints() > 0) System.out.print (zombie); B. We now want to go through the player's turn. The player should be prompted with instructions on how to move the character in this grid-based game. After getting the input from the player, a good option for moving the player based on their entry is to use a switch statement. (Note: The String in the switch expression is compared with the expressions associated with each case label as if the String equals method were being used). Here is the incomplete code for this: //Player's turn System.out.println("Where to move? u for up, d for down, 1 for left, r for right. Any other key will skip the turn."); String in input.nextLine(); switch (in) { case. "u": pc.setLocation (pc.getLocationY() + 1); break; case 1
A. Let us print out both the player and the zombie (only if the zombie's current hitpoints are above 0: System.out.print (pc); if (zombie.getCurrent RitPoints() > 0) System.out.print (zombie); B. We now want to go through the player's turn. The player should be prompted with instructions on how to move the character in this grid-based game. After getting the input from the player, a good option for moving the player based on their entry is to use a switch statement. (Note: The String in the switch expression is compared with the expressions associated with each case label as if the String equals method were being used). Here is the incomplete code for this: //Player's turn System.out.println("Where to move? u for up, d for down, 1 for left, r for right. Any other key will skip the turn."); string in input.nextLine(); switch (in) ( case "u": pc.setLocation (pc.getlocation() 1); case "r": break; pc.getName(), pc.setLocationk(pe.getLocation() + 1): default: System.out.println("Turn Skipped. u for up, d for down, 1 for left, r for right. Any other key will skip the turn."); zombie.getName()); break; Finish this code to handle down and left. D. Next, we want the player to attack the zombie if the player moves to the same location as the zombie. We will check if the position of player is the same as the zombie and if the zombie's health is above 0. We will call pc attackEnemy(zombie) to actually "attack" the enemy as the player. If the player's attack causes the zombie's health to go below, we will print a message saying the player defeated the zombie. if (pe.getlocationx() zombie.getlocation() is pc.getLocationY() zombie.getCurrentHitPoints() > 0) { } zombie.getLocation() System.out.printf("%s attacked tsin. pc.getane (). pc.attackEnemy (zombie); if (zombie.getCurrentMitPoints() < 0) { System.out.printf("is defeated tsin", zombie.getName()); } E. Now, we want to do the same thing as the previous two steps, but for the zombie. In this case, we will use a Random object so we can randomly generate the next direction the zombie should move in. We want to create a Random object so we can use it later. Add this to your code inside of your main method: Random rand = new Random(); F. Now, lets add the code for the zombie's turn if (zombie.getCurrentHitPoints() > 0) { int direction switch (direction) ( case 0: zombie.setLocation! (zombie.getLocation() 1); break; case 1: rand.nextInt (4): zombie.setLocationT(zombie.getLocationT() - 11: break; case 21
E. Now, we want to do the same thing as the previous two steps, but for the zombie. In this case, we will use a Random object so we can randomly generate the next direction the zombie should move in. We want to create a Random object so we can use it later. Add this to your code inside of your main method: Random rand new Random(); F. Now, lets add the code for the zombie's turn: if (zombie.getCurrentHitPoints() > 0) { int direction = rand.nextInt (4); switch (direction) { case 0: zombie.setLocationY (zombie.getLocationY() + 1); break; case 1: zombie.setLocationY (zombie.getLocationY() - 1); break; case 2: zombie.setLocationx (zombie.getLocationX() - 1); } break; case 3:1 zombie.setLocationx (zombie.getLocationX() + 1); break; } if (pc.getLocationX() == zombie.getLocationX() && zombie.getLocationY() && pc.getLocationY() pc.getCurrentHitPoints() > 0) { System.out.printf("%s attacked %s\n", zombie.getName(), pc.getName()); zombie.attackPlayableCharacter (pc); if (pc.getCurrentHitPoints() <= 0) { System.out.printf("%s defeated %s\n", zombie.getName(), pc.getName()); } G. And that's it! This logic should handle moving the player and enemy throughout the grid. If the player or enemy moves into the other one, they should attack and remove health, and if the player moves to 6,6 (where our "stairs" are), then the game ends. To make it clear to the player that the game is over (whether they were defeated or if they reached the goal), we should print a few things about the player and zombie to show their status. After the closing curly brace of the while loop, add this code: System.out.println("Game Over!"); System.out.println("Character: + pc.getName()); System.out.println("Remaining hitpoints: System.out.println("Zombie hitpoints: pc.getCurrentHitPoints()); zombie.getCurrentHitPoints()); input.close(); For the final step, add another enemy (in addition to the zombie) and write the code to handle the logic for it. It should follow the same logic as the zombie (moving in a random direction and attacking the player). (All you will have to do is create a new Enemy object, not make a new class.)
Exercise 1: Creating the Playable Character class We will now be creating the playableCharacter class. This class will contain methods tain methods that will allow it to interact with the Enemy class D. Add our class fields to the PlayableCharacter java class. Remember to use the "private access modifier as we are continuing to practice encapsulation. These fields are chosen to represent a bare-minimum playable character, but this is is list of variables can be e expanded in the future. en //class fields private String name; private int currentMitPoints 18; private int weaporange-5 private int location - private int location E. Let's let Eclipse generate getters and setters for us. Remember that it is under Source Generate Getters and Setters F. Now, we want to add some logic to our PlayableCharacter class. We will add methods to be able to do the following A. Receive damage, lowering our playable character's current hitpoints by the damage amount B. Attack an enemy, causing the enemy to take damage equal to our weapon damage. We will make the enemy class later. C. Override the toString method, so that we can show the current status of the player. We will use String format bere to create a formatted String. Remember that the arguments after the String in String format will be used to replace the Format Specifiers (ie. %s or %id etc.). For something like String.format("Hello", "world"). the is will be replaced with "world". We are overriding the toString method since it exists in the parent class Object. All classes inherit from the Object class D. Override the equals method, so that we can determine if one character is "equivalent to another character based on their names. It will take an Object as a parameter and we will cast it to a Playable Character object so we can use its getName() method. We are overriding the equals method since it exists in the parent class Object All classes inherit from the Object class G. To accomplish our previous point, add the following code to your class: //Lower our current hitpoints by the damageTaken argument
G. To accomplish our previous point, add the following code to your class: //Lower our current hitpoints by the damageTaken argument public void receiveDamage(int damageTaken) { this.currentHitPoints damageTaken; } //object interaction. The parameter is an Enemy object //We call the enemy's receiveDamage method within this attackEnemy method public void attackEnemy (Enemy enemy) ( enemy.receiveDamage (this.weaponDamage); } public String toString() { //%s means String //%d means decimal number (integer) return String.format("%s location: %d, Xd. HitPoints: %d\n", this.getName(); this.getlocationX(), this.getLocationY(), this.getCurrentHitPoints()); } public boolean equals(Object other) ( //Cast the Object parameter to a PlayableCharacter so we can access its name //If the name of the current PlayableCharacter equals the other PlayableCharacter being passed as a parameter, return true. Else, return false. PlayableCharacter tempCast (PlayableCharacter)other; if (this.name.equals(tempCast.getName()))( return true; } else { } return false; ) H. Finally, let's create our class constructor. It should do the following: A. Take a String that represents the playable character's name and assign the value to the name variable. 1. With all of the previous step, we can create our constructor with the following code: public PlayableCharacter(String nane) ( this name name; //Alternatively, you could have used setName to set the name > J. We have finished the PlayableCharacter class! Make sure there are no syntax errors (red underlines) outside of receiveDamage (since we use Enemy as a parameter type and we haven't created that class yet) and make sure to save the file.
Exercise 2: Creating the Enemy class We will now be creating the Enemy class. This class will contain methods that will allow it to interact with the playable Character. B. Add our class fields to the Enemy java class. Remember to use the "private" access modifier as we are continuing to practice encapsulation. These fields are chosen to represent a bare-minimum Enemy, but this list of variables can be expanded in the future. //class fields private String name; private int currentHitPoints = 4; private int weaponDamage - 2; private int locationx ; private int location = 0; C. Just like in exercise 1, generate getters and setters for each of these fields. D. Now, we want to create methods that will handle some logic for enemies. We want to make methods that do the following: A. Receive damage, lowering the enemy's hitpoints by the damage amount B. Attack a playable character, causing the playable character to take damage equal to the enemy's weapon damage. C. Override the toString method, so that we can show the current status of the enemy. We will use String format here to create a formatted String D. Override the equals method, so that we can determine if one Enemy is "equivalent" to another Enemy based on their names. It will take an Object as a parameter and we will cast it to an Enemy object so we can use its getName() method. E. As you may notice, we created methods in PlayableCharacter that were nearly identical to these. Implement these methods and feel free to reuse code! Here are the method headers and empty method bodies for those two methods: public void receiveDamage(int damageTaken) ([ > public void attackPlayableCharacter (PlayableCharacter player) ( } public String toString() ( } public boolean equals(Object other) ( } F. Let's create our class constructor. It should do the following: A. Take a String that represents the enemy's name and assign the value to the name variable.
E. As you may notice, we created methods in PlayableCharacter that were nearly identical to these. Implement these methods and feel free to reuse code! Here are the method headers and empty method bodies for those two methods: public void receiveDamage(int damageTaken) { } public void attackPlayableCharacter (PlayableCharacter player) { } public String toString() { } public boolean equals(Object other) ( > F. Let's create our class constructor. It should do the following: A. Take a String that represents the enemy's name and assign the value to the name variable. B. Take an int that represents the enemy's X location and assign the value to the location variable. C. Take an int that represents the enemy's Y location and assign the value to the location Y variable. F. With all of the previous step, we can create our constructor. Create the constructor for the Enemy class on your own. G. Finally, let's create another constructor that will use constructor chaining so we can provide some default values. It should do the following: A. Take a String as a parameter that represents the enemy's name. B. Call the other class constructor using the String parameter as the name argument, 2 as the location X argument, and 3 as the location Y argument. Remember that you can use this arguments here) within a constructor to call another constructor (constructor chaining). H. We have finished the Enemy class! Make sure there are no syntax errors (red underlines) and make sure to save the file. The syntax errors in Playable Character should have been resolved now too.
Exercise 3: Creating the Game class We will now be creating the Game class. This class will contain the game logic that uses the Playable Character and Enemy classes to create a simple game, A. We want the main method to use a Scanner object to ask for the player's name. This Scanner object will also be used later for playing the game. Let's add the code for creating a Scanner object and asking for the player's name: Scanner Input = new Scanner(System.in); System.out.print("Welcome to the Dungeon! What is your character's name? (Input nase then press enter): "); String playerName input.nextLine(); //Create instance of PlayableCharacter with inputed name PlayableCharacter pc new PlayableCharacter (playerName); System.out.println("Hello, pc.getName()); B. We will now create a simple Enemy object called zombie. We will use the constructor with "Zombie" as the name, 2 as the locationX, and 3 as the location Y. /" • Enemy class constructor has 3 arguments.. Argument 1: String name Argument 2: int location Argument 3: int locationY " Enemy zomble new Enemy("Zombie", 2, 3); C. Now, we will create the "game loop". This loop will handle the turns of the player and enemy while the player's hitpoints are not below 0 and while the player's location is not where the "stairs" are located (at 6,6). The condition of this loop will do the following three things: A. Check if the player's X location is 6 B. Check if the player's Y location is 6 C. Check if the player's current hitpoints is above 0 11 //GAME LOOP START 11 while (1(pc.getLocationx() 688 pc.getLocation() 6) && pc.getCurrentHitPoints() > 0) ( A. Let us print out both the player and the zombie (only if the zombie's current hitpoints are above 0: System.out.print (pc); if (zoable.getCurrentHitPoints()0) System.out.print(zombie);
A. Let us print out both the player and the zombie (only if the zombie's current hitpoints are above 0: System.out.print(pc); if (zombie.getCurrentHitPoints()) System.out.print(zombie); B. We now want to go through the player's turn. The player should be prompted with instructions on how to move the character in this grid-based game. After getting the input from the player, a good option for moving the player based on their entry is to use a switch statement. (Note: The String in the switch expression is compared with the expressions associated with each case label as if the String.equals method were being used). Here is the incomplete code for this: //Player's turn System.out.println("Where to move? u for up, d for down, 1 for left, r for right. Any other key will skip the turn."); String in input.nextLine(); switch (in) ( case "u": pc.setLocationY(pc.getLocationY() 1); break; case "r": pc.setLocationx(pc.getLocationx() + 1); break; default: } System.out.println("Turn Skipped. u for up, d for down, 1 for left, r for right. Any other key will skip the turn."); } C. Finish this code to handle down and left. D. Next, we want the player to attack the zombie if the player moves to the same location as the zombie. We will check if the position of player is the same as the zombie and if the zombie's health is above 0. We will call pe.attackEnemy(zombie) to actually "attack" the enemy as the player. If the player's attack causes the zombie's health to go below 0, we will print a message saying the player defeated the zombie. if (pc.getLocationx() zombie.getLocationx() && pc.getLocation() zombie.getlocation() && zombie.getCurrentHitPoints()*) ( System.out.printf("%s attacked %s\n", pc.getName(), zombie.getName()); pc.attackEnemy (zombie); if (zombie-getCurrentHitPoints() < 0) ( System.out.printf("%s defeated %s\n", pc.getName(), zombie-getName()); E. Now, we want to do the same thing as the previous two steps, but for the zombie. In this case, we will use a Random object so we can randomly generate the next direction the zombie should move in. We want to create a Random object so we can use it later. Add this to your code inside of your main method: Random rand new Random(); F. Now, lets add the code for the zombie's turn: if (zomble.getCurrentHitPoints() > 0) { int direction switch (direction) ( case 0: rand.nextInt (4); zombie.setLocationY(zombie.getLocation() 1);
E. Now, we want to do the same thing as the previous two steps, but for the zombie. In this case, we will use a Random object so we can randomly generate the next direction the zombie should move in. We want to create a Random object so we can use it later. Add this to your code inside of your main method: Randoe rand new Random(); F. Now, lets add the code for the zombie's turn: if (zombie.getCurrentHitPoints() > 0) { int direction = rand.nextInt (4); switch (direction) { case 0: zombie.setLocationY(zombie.getLocationY()+ 1); break; case 1: zombie.setLocationY(zombie.getLocation() - 1); break; case 2: zombie.setLocationx(zombie.getLocationx()- 1); break; case 3: zombie.setLocation (zombie.getLocationX() + 1); break; } if (pc.getLocationX() zombie.getLocationX() && pc.getLocation() zombie.getlocationY() && pc.getCurrentHitPoints() > 0) { System.out.printf("%s attacked %s\n", zombie.getName(), pc.getName()); zombie.attackPlayableCharacter (pc); if (pc.getCurrentHitPoints() <= 0) { System.out.printf("%s defeated %s\n", zombie.getName(), pc.getName()); G. And that's it! This logic should handle moving the player and enemy throughout the grid. If the player or enemy moves into the other one, they should attack and remove health, and if the player moves to 6,6 (where our "stairs" are), then the game ends. To make it clear to the player that the game is over (whether they were defeated or if they reached the goal), we should print a few things about the player and zombie to show their status. After the closing curly brace of the while loop, add this code: System.out.println("Game Over!"); pc.getName()); System.out.println("Character: System.out.println("Remaining hitpoints: pc.getCurrentHitPoints()); System.out.println("Zombie hitpoints: zombie-getCurrentHitPoints()); input.close(); H. For the final step, add another enemy (in addition to the zombie) and write the code to handle the logic for it. It should follow the same logic as the zombie (moving in a random direction and attacking the player). (All you will have to do is create a new Enemy object, not make a new class.)