Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a basic RPG simulator. Very simple, but must contain certain elements le

ID: 3803414 • Letter: T

Question

This is a basic RPG simulator. Very simple, but must contain certain elements learned up to this point including: Abstract class Derived classes (inheritance) Overriding methods with proper use of @Override annotation The program will simulate a very simple RPG that has two types of classes. A damage class and a tank class. There should be a player class that has a common HP (health points) attribute. That class should be an abstract class (ie, never instantiated) but there should be two or more types of players derived from it. At minimum should be a "damage" class that has a bonus applied for damage on each round, and a tank class that has a shield reduction applied for each attack. Initial health applied, and bonuses for attacks and shields should be slightly varied by a random value to make the game a little more unpredictable. Overall logic is very simple. In main() just instantiate an instance of each of your desired players, then go into a while loop that does the attack and damage calculations and outputs the results until one of the players reaches zero HP and output who is the survivor (or maybe no one!) Now you should strive to make your calculations and random number parameters so the classes are balanced. If done correctly each run should be a near 50/50 chance that one or the other wins. ie, if your tank is always winning, it is overpowered and you need to "nerf" it.

Here's an example output:

Health for dps is 52

Health for tank is 74

Health for dps is 41

Health for tank is 58

Health for dps is 29

Health for tank is 47

Health for dps is 20

Health for tank is 40

Health for dps is 11

Health for tank is 30

Tank is alive with 23 left

Process finished with exit code 0

Explanation / Answer

//Abstract class Player
abstract class Player
{
   int health = 50;
   //Constructor
   Player(int h)
   {
       health -= h;
   }//End of constructor
   //Method to return health point
   int getHealth()
   {
       return health;
   }//End of method
}//End of class

//Class Damage derived from Player
class Damage extends Player
{
   int damagePoint;
   //Constructor
   Damage(int d)
   {
       super(d);
   }//End of constructor
  
   //Method to return damage point
   int getDamagePoint()
   {
       return health;
   }//End of method
   //Overrides toString method to display information
   public String toString()
   {
       return "Health for dps is: " + getHealth();
   }//End of method
}//End of class

//Class Tank derived from Player
class Tank extends Player
{
   int tankPoint;
   //Constructor
   Tank(int tp)
   {
       super(tp);      
   }//End of constructor
   //Method to return tank point
   int getTankPoint()
   {
       return health;
   }//End of method
   //Overrides toString method to display information
   public String toString()
   {
       return "Health for tank is: " + getHealth();
   }//End of method
}//End of class

//Driver class
public class RPGDemo
{
   //Main method
   public static void main(String ss[])
   {
       int point = 0;
       //For two players
       Player p1;
       Player p2;
       //Loops till health is 0
       do
       {
           //Generates a random point
           point = (int )(Math. random() * 50 + 1);          
           //Point passed to tank class
           p1 = new Tank(point);
           //Generates a random point
           point = (int )(Math. random() * 50 + 1);
           //Point passed to tank class
           p2 = new Damage(point);
           //Displays health point for player1 and player2
           System.out.println(p1);
           System.out.println(p2);
           //Checks health point
           if(p1.getHealth() < 1 || p2.getHealth() < 1)
           {
               System.out.println("Process finished with exit code 0");
               break;
           }//End of if
       }while(true);
   }//End of main method
}//End of class

Output:

Health for tank is: 4
Health for dps is: 15
Health for tank is: 26
Health for dps is: 7
Health for tank is: 22
Health for dps is: 38
Health for tank is: 31
Health for dps is: 4
Health for tank is: 14
Health for dps is: 12
Health for tank is: 19
Health for dps is: 1
Health for tank is: 48
Health for dps is: 21
Health for tank is: 25
Health for dps is: 13
Health for tank is: 49
Health for dps is: 34
Health for tank is: 27
Health for dps is: 22
Health for tank is: 49
Health for dps is: 41
Health for tank is: 19
Health for dps is: 45
Health for tank is: 49
Health for dps is: 30
Health for tank is: 17
Health for dps is: 49
Health for tank is: 12
Health for dps is: 15
Health for tank is: 19
Health for dps is: 29
Health for tank is: 47
Health for dps is: 30
Health for tank is: 19
Health for dps is: 38
Health for tank is: 34
Health for dps is: 26
Health for tank is: 36
Health for dps is: 22
Health for tank is: 9
Health for dps is: 24
Health for tank is: 24
Health for dps is: 28
Health for tank is: 18
Health for dps is: 38
Health for tank is: 48
Health for dps is: 46
Health for tank is: 38
Health for dps is: 35
Health for tank is: 20
Health for dps is: 30
Health for tank is: 31
Health for dps is: 25
Health for tank is: 34
Health for dps is: 28
Health for tank is: 27
Health for dps is: 16
Health for tank is: 28
Health for dps is: 25
Health for tank is: 11
Health for dps is: 43
Health for tank is: 48
Health for dps is: 15
Health for tank is: 25
Health for dps is: 11
Health for tank is: 19
Health for dps is: 18
Health for tank is: 22
Health for dps is: 23
Health for tank is: 46
Health for dps is: 2
Health for tank is: 24
Health for dps is: 45
Health for tank is: 0
Health for dps is: 47
Process finished with exit code 0

//Run this program in eclipse

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote