In: Computer Science
(YOU don't need to write the client class I already have it, just need this)
You are provided with Main.java that is a client for this program.
You will create THREE files-- GameCharacter.java, ShieldMaiden.java, and Dragon.java
First: You must Create an interface called GameCharacter WITH JUST PROTOTYPES, NO IMPLEMENTATIONS
A GameCharacter has a few functions associated with it
1) takeHit: decreases the character's health. It should return an int representing damage taken (hit points)
2) heal: increases the character's health. Should return an int representing amount healed (i.e. hit points)
3) getHealth: returns the total current health the character has (i.e. hit points)
4) isAlive: determines if the character is dead. Should return true if the character is dead, and false if not.
Second: Then create two classes. One should be named Dragon, and the other should be named ShieldMaiden (i.e. warrior) that IMPLEMENT Game Character. Give them each private variables for health. The constructor should take in an initial amount to set health to.
Third: Implement the interface functions for these two classes (Dragon and ShieldMaiden). To make the game more interesting, the dragon's takeHit should hurt the dragon a random number from 10 to 20 inclusive and the ShieldMaiden's takeHit should hurt the shieldMaiden a random number from 15 to 25 inclusive. Furthermore, the dragon's heal should only heal the dragon a random number from 1 to 10 inclusive but the ShieldMaiden's heal should heal the ShieldMaiden a random number from 8 to 20 inclusive. A character is dead when they get negative health.
package java1;
import java.util.*;
import java.util.Random;
interface GameCharacter{
public int takeHit();
public int heal();
public int getHealth(int health);
public boolean isAlive();
}
class ShieldMaiden implements GameCharacter{
public static void main(String[] args){
private int healthShieldMaiden;
Random rand = new Random();
public int getHealth(int health){
healthShieldMaiden=health;
return healthShieldMaiden;
}
public int takeHit(){
int n = rand.nextInt(20+1) + 10;
healthShieldMaiden=healthShieldMaiden-n;
return healthShieldMaiden;
}
public int heal(){
int n=rand.nextInt(21)+8;
healthShieldMaiden=healthShieldMaiden+n;
return healthShieldMaiden;
}
public boolean isAlive(){
if(healthShieldMaiden<0){
return true;
}
else{
return false;
}
}
}
}
public class Dragon implements GameCharacter{
public static void main(String[] args){
private int dragonHealth;
Random rand = new Random();
public int getHealth(int health){
dragonHealth=health;
return dragonHealth;
}
public int takeHit(){
Random rand = new Random();
int n = rand.nextInt(25+1) + 15;
dragonHealth=dragonHealth-n;
return dragonHealth;
}
public int heal(){
int n=rand.nextInt(11)+1;
dragonHealth=dragonHealth+n;
return dragonHealth;
}
public boolean isAlive(){
if(dragonHealth<0){
return true;
}
else{
return false;
}}}
}
ShieldMaiden class output::
0-->for getHealth
THIS STATEMENT BASED UPON COMPILER // int n = rand.nextInt(20+1)
+ 10;
NEGATIVE VALUE...> FOR
takeHit()
heal ...> -VE
isAlive..> false
Dragonclass output::
0-->for getHealth
NEGATIVE VALUE...> FOR
takeHit()
heal ...> -VE
isAlive..> false