Question: RPG Player class Design and implement a RPG ( role - playing game ) Player class. Players should be able to battle with each other.

RPG Player class Design and implement a RPG(role-playing game) Player class. Players should be able to battle with each other. The Player class should include the following instance variables: name: players name status: in this game we will only have 2 types of status: alive and dead experience: The experience points (often abbreviated as exp or XP) is a unit of measurement used to quantify a player character's life experience and progression through the game. In our design each battle the player fights will earn them 50 experience points. level: A level is a number that represents the overall power of the player and is determined by the players experience points. The more experience points the player has the higher level the player will be in. The level of the player decides the value of max hit points and damage points. currentHitPoints: The current hit points indicate how much damage the player can take before they die. If the value drops to 0 the player is dead. maxHitPoints: This is the ceiling of your current hit points. Lets say you have 45 hit points out of a maximum of 50, and you drink a potion and recover 6 hit points. Your hit points cap out at 50, meaning you have one healing power wasted. (This is just an example. We will not have healing implemented in this program.) damagePoints: Damage points reflect the amount of harm inflicted on a player by an opponent's attack. Damage points of the opponent are deducted from the current hit points and vice versa the damage points the current player has will be deducted from the opponents current hit points. The Player class should include the following methods: getters and setters: Some setters can be tricky. For example, when the value of experience is set, it should also set the level, which should set the value of maxHitPoints and demagePoints. When the currentHitPoints is set it should also set the status of the player. (If below 0, the player is dead.) The currentHitPoints should never exceed the maxHitPoints of the player, which is determined by the players level. Algorithm to use in the setters: level = experience /100(level 1: 0-199; level 2: 200-299...) Use an if statement to set the level to 1 if the level is below 1 maxHitPoints =(int)(level*100*(1+level/10.0)) damagePoints = level *30 constructor: One constructor that takes name, experience, and currentHitPoints as parameters. public Player(String name, int experience, int currentHitPoints) toString: The toString method should return all the info about the player. battle: The method should have a Player typed parameter. For example: Public void battle(Player player) During the battle each player will have their current hit points deducted by the number of the damage points the opponent has. After the battle each player will gain 50 experience points. Use the following main method to test your class. Feel free to change the players name but DO NOT change the initial passed-in experience and currentHitPoints in the example. public static void main(String[] args){//feel free to change the players names, but do not change anything else Player player1= new Player("FiFi",450,10000); Player player2= new Player("Moblin",230,190); System.out.println("before the battle:"); System.out.println(player1); System.out.println(player2); System.out.println(player1.getName()+" is battling "+ player2.getName()); player1.battle(player2); System.out.println("after the battle"); System.out.println(player1); System.out.println(player2); System.out.println("battle again"); player1.battle(player2); System.out.println("after the battle"); System.out.println(player1); System.out.println(player2); } Run your program and insert the results in the appropriate section of the machine problem worksheet.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!