Determine how all of your classes are related, and create a complete UML class diagram representing your class structure. Don't forget to include the appropriate relationships between the classes.
GameDriver
import java.util.Scanner;
public class GameDriver {
Scanner in = new Scanner(System.in);
public static void main(String[] args) {
Move move1 = new Move("Vine Whip", "Grass", 45, 1.0f);
Move move2 = new Move("Tackle", "Normal", 50, 1.0f);
Move move3 = new Move("Take Down", "Normal", 90, 0.85f);
Move move4 = new Move("Razor Leaf", "Grass", 55, 0.95f);
Monster monster = new Monster("Bulbasaur", "Grass", 240, 45, 49, 49, move1, move2, move3, move4);
HumanPlayer player = new HumanPlayer(monster);
move1 = new Move("Scratch", "Normal", 40, 1.0f);
move2 = new Move("Ember", "Fire", 40, 1.0f);
move3 = new Move("Peck", "Flying", 35, 1.0f);
move4 = new Move("Fire Spin", "Fire", 35, 0.85f);
monster = new Monster("Torchic", "Fire", 240, 45, 60, 40, move1, move2, move3, move4);
CPUPlayer enemy = new CPUPlayer(monster);
while ((!player.hasLost()) && (!enemy.hasLost())) {
System.out.println("");
System.out.printf("%s has %d HP\n", player.getMonster().getName(), player.getMonster().getHP());
System.out.printf("%s has %d HP\n", enemy.getMonster().getName(), enemy.getMonster().getHP());
int playerMove = player.chooseMove();
int enemyMove = enemy.chooseMove();
if (player.isFasterThan(enemy)) {
player.attack(enemy, playerMove);
if (!enemy.hasLost()) {
enemy.attack(player, enemyMove);
}
} else {
enemy.attack(player, enemyMove);
if (!player.hasLost()) {
player.attack(enemy, playerMove);
}
}
}
if (player.hasLost()) {
System.out.printf("You and %s have lost the battle.\n", player.getMonster().getName());
} else {
System.out.printf("You and %s are victorious!\n", player.getMonster().getName());
}
}
}
HumanPlayer
import java.util.Random;
import java.util.Scanner;
public class HumanPlayer extends Player
{
HumanPlayer(Monster monster)
{
this.monster=monster;
}
public int chooseMove()
{
System.out.println("1. Vine Whip");
System.out.println("2. Tackle");
System.out.println("3. Tak Down");
System.out.println("4. Razor Leaf");
System.out.print("Which Move(1-4): ");
int choice=input.nextInt();
while(choice<0 || choice >4)
{
System.out.println("Invalid move!");
System.out.print("Enter your move(1-4): ");
}
return choice;
}
}
Monster
public class Monster{
private String name;
private String type;
private int hp;
private int speed;
private int attack;
private int defence;
private Move move1;
private Move move2;
private Move move3;
private Move move4;
public Monster(String name,String type,int hp,int speed,int attack,int defence,Move move1,Move move2,Move move3,Move move4){
this.name = name;
this.type=type;
this.hp=hp;
this.speed=speed;
this.attack=attack;
this.defence=defence;
this.move1=move1;
this.move2=move2;
this.move3=move3;
this.move4=move4;
}
String getName(){
return name;
}
int getHP(){
return hp;
}
void setHP(int hp){
this.hp=hp;
}
int getSpeed(){
return speed;
}
int getAttack(){
return attack;
}
int getDefense(){
return defence;
}
Move getMove1(){
return move1;
}
Move getMove2(){
return move2;
}
Move getMove3(){
return move3;
}
Move getMove4(){
return move4;
}
}
Move
public class Move{
private float accuracy;
private int power;
private String type;
private String name;
public Move(final String name,final String type,final int power,final float accuracy){
this.name=name;
this.type=type;
this.power=power;
this.accuracy=accuracy;
}
float getAccuracy()
{
return accuracy;
}
int getPower()
{
return power;
}
String getName()
{
return name;
}
String getType()
{
return type;
}
}
Player
import java.util.Random;
import java.util.Scanner;
public class Player{
Random rand=new Random();
Scanner input=new Scanner(System.in);
protected Monster monster;
public boolean hasLost()
{
if(monster.getHP()<=0)
return true;
else{
return false;
}
public Monster getMonster()
{
return monster;
}
public int chooseMove()
{
return 0;
}
public boolean isFasterThan(Player enemy)
{
if(this.monster.getSpeed()>enemy.getMonster().getSpeed())
return true;
else
return false;
}
public void attack(Player enemy, int playerMove)
{
float acc=rand.nextFloat();
float movAcc=0;
int movPower=0;
if(playerMove==1)
{
movAcc=this.getMonster().getMove1().getAccuracy();
movPower=this.getMonster().getMove1().getPower();
System.out.println(this.getMonster().getName()+" uses "+this.getMonster().getMove1().getName());
}
else if(playerMove==2)
{
movAcc=this.getMonster().getMove2().getAccuracy();
movPower=this.getMonster().getMove2().getPower();
System.out.println(this.getMonster().getName()+" uses "+this.getMonster().getMove2().getName());
}
else if(playerMove==3)
{
movAcc=this.getMonster().getMove3().getAccuracy();
movPower=this.getMonster().getMove3().getPower();
System.out.println(this.getMonster().getName()+" uses "+this.getMonster().getMove3().getName());
}
else if(playerMove==4)
{
movAcc=this.getMonster().getMove4().getAccuracy();
movPower=this.getMonster().getMove4().getPower();
System.out.println(this.getMonster().getName()+" uses "+this.getMonster().getMove4().getName());
}
if(acc<movAcc)
{
int damageDealth = this.getMonster().getAttack() + movPower - enemy.getMonster().getDefense();
System.out.println(this.getMonster().getName()+" hit for "+damageDealth+" points of damage");
enemy.getMonster().setHP(enemy.getMonster().getHP()-damageDealth);
}
}
}
CPUPlayer
import java.util.Random;
public class CPUPlayer extends Player
{
CPUPlayer(Monster monster)
{
this.monster=monster;
}
public int chooseMove(){
return rand.nextInt(4)+1;
}
}
Important: Please submit pictures of the UML diagram
Get Answers For Free
Most questions answered within 1 hours.