Lab 7 You are to develop an entire program that simulates th

Lab 7

You are to develop an entire program that simulates the way a game is handled in the random creation of its characters. Your program should have the ability to create one of 3 types of character. The choices should be an ogre, archer and a swordsman. Each of these characters will share many of the same types of attributes such as name, life and energy and these should be contained in the Super class that we will call Entity (because Character is already a class). Only the archer and the swordsman are playable, which leaves the ogre to be a Non-Player Character (NPC). This means that the Ogre will be a subclass of the Entity, while the archer and swordsman will be subclasses of Playable which is a subclass of Entity. Below is the diagram. No changes need to be made to the driver.

The Playable class should extend the Entity class and should contain some additional methods that dictate the movement of the character by the user. Note that we will NOT be tracking the movement of the characters to help simplify the lab. The playable class should have a method for moving the character in the 4 standard directions (no diagonals allowed). So up, down, left and right.

Class Name: Entity

                Class Level (global) Variables:

                                strName              - String

                                intLife                   - Integer

                                intEnergy             - Integer

Method Name: getStrName

Parameters: None

Desired Result: Accessor

Data Returned: strName

Solution


public class game {

   static class Entity
   {
       String strname;
       int intLIfe;
       int intEnergy;
         
      
      
   public String   getStrname()
       {
           return this.strname;
       }
   }
  
   static class Ogre extends Entity
   {
   // your code specfic for ogre
   }
  
   static class Playable extends Entity
   {
       public void moveLeft()
       {
           System.out.println(this.getStrname()+\" has moved left\");
       }
      
       public void moveRight()
       {
           System.out.println(this.getStrname()+\" has moved Right\");
       }
      
       public void moveUp()
       {
           System.out.println(this.getStrname()+\" has moved Up\");
       }
      
       public void moveDown()
       {
           System.out.println(this.getStrname()+\" has moved down\");
       }
      
   }
  
  
   static class Swordsmen extends Playable
   {
       //code specific for swordsmen
   }
  
   static class Archer extends Playable
   {
       // code specific for archer
   }
  
   public static void main(String args[])
   {//use your driver class instead of this method
       game.Archer a =new game.Archer();
      
       a.strname=\"Robinhood\";
      
       a.moveUp();
       a.moveDown();
       a.moveLeft();
       a.moveRight();
      
      
   }
}

Lab 7 You are to develop an entire program that simulates the way a game is handled in the random creation of its characters. Your program should have the abili
Lab 7 You are to develop an entire program that simulates the way a game is handled in the random creation of its characters. Your program should have the abili

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site