- This event has passed.
7 PM – Intro To Java – Darin
June 26 @ 7:00 pm - 8:00 pm
What We Did Today:
- Continued on the monster inheritance project.
Homework:
Upload your file to your google drive homework section when you are finished.
This is what we have so far for the play method:
public void play() { System.out.println("\nPLAY GAME"); System.out.print("What is your character's name: "); playerName = s.nextLine(); System.out.print("Set your character's health: "); String strHealth = s.nextLine(); playerHealth = Integer.parseInt(strHealth); while (true) { // Darin has 100 health remaining System.out.println("\n%s has %s health remaining".formatted(playerName, playerHealth)); String monsterName = printMonsterMenu(); if (monsterName.toLowerCase() == "stop") { break; } Monster m = monsterMap.get(monsterName.toLowerCase()); if (m == null) { // when I try to use .get(), if i unsuccessfully get the value, null will be returned System.out.println("Invalid monster. Please try again."); } else { System.out.print(attackMenu.formatted(monsterName)); String attackType = s.nextLine(); if (attackType.equals("1")) { System.out.println("Do a Magic Attack"); } else if (attackType.equals("2")) { ; // doMeleeAttack(m); } else if (attackType.equals("3")) { ; // doArrowAttack(m); } else if (attackType.equals("4")) { System.out.println("Heal"); } else { System.out.println("Invalid choice. Please try again with 1, 2, 3, or 4."); } } } }
You want to implement the meleeAttack and arrowAttack methods by creating a new method in the Monster class for receiving damage.
Then you will want to implement the two methods below which will be used in the else if statements for the play() method
private void doMeleeAttack(Monster m) { ; // call a method from the monster class (receiveDamage), and use a random amount of attack and deplete // the health from the monster // do a random amount of damage from 10 to 20 } private void doArrowAttack(Monster m) { ; // call a method from the monster class (receiveDamage), and use a random amount of attack and deplete // the health from the monster // do a random amount of damage from 5 to 25 }
Notes:
If you have any questions, you may reach out to me at ddjapri@ayclogic.com.