in JAVA
Write a new class, Game, that have a main method and instantiates and uses the above class. Create (at least) one Hero, one Monster, and one Potion(that you equip the hero with). Use repetition to have the monster attack the hero multiple time! Have the hero try to drink a potion whenever their health gets low(say below 10). Finally -- have there be an end-game condition. Maybe the game ends when the hero's health is equal to 0. Maybe the game ends if the hero survives 10 monster attacks, forcing the monster to realise that needless aggression never solves anything. Beyond the basics outlined above, make it your own and have fun.
package com.example.poc;
public class Game{
Integer potion = 10;
public Integer getPotion() {
return potion;
}
public void setPotion(Integer potion) {
this.potion = potion;
}
public Game() {
}
public static void main(String[] args) {
Game game = new Game();
game.startGame(game);
}
private void startGame(Game game) {
Monster monster = new Monster();
Hero hero = new Hero();
// run for loop in thread for parallel operation
for (int i = 0; i < 10; i++) {
monster.attack(game);
hero.defend(game);
if(game.getPotion()<10) {
endGame();
}
}
endGame();
}
private void endGame() {
System.out.println("Game end");
}
}
class Hero {
public Hero() {
// TODO Auto-generated constructor stub
}
void defend(Game game) {
System.out.println("Defending");
game.setPotion(game.getPotion() + 1);
}
}
class Monster {
public Monster() {
// TODO Auto-generated constructor stub
}
void attack(Game game) {
System.out.println("Attacking");
game.setPotion(game.getPotion() - 1);
}
}
in JAVA Write a new class, Game, that have a main method and instantiates and uses the above class. Create (at least) one Hero, one Monster, and one Potion(that you equip the hero with). Use repetitio...