Question

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...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

}

}

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT