Question: need help with java project Purpose Player To help obtain an understanding of classes and how and when to use them. Directions and Examples: The

need help with java project

Purpose

Player

To help obtain an understanding of classes and how and when to use them.

Directions and Examples:

The game company that hired you is back with a pretty large project. They have a class called Player that controls the game character in their RPG game. The player has fields and methods:

String name the players name. int x the x location of the player in the 2D world int y the y location of the player in the 2D world int health the health of the player int damage the damage the player does to enemies per hit

Player(String name, int x, int y, int health, int damage)

This constructor should initialize the Player objects fields

boolean teleport(int uBoundX, int uBoundY, int lBoundX, int lBoundY, int destX, int destY)

If destX and destY are within the bounding box described by uBoundX, uBoundY, lBoundX and lBoundY, set the players x and y coordinates to destX and destY and return true; otherwise, do not change the players x and y coordinates and return false.

void hit(Player other)

Decrease the other players health by the amount of damage this player does. The other players health cannot go below zero.

String toString()

Override the toString() method to return a String containing the Players name, health and location in this form Name (health) is at x,y.

Write a main method that creates two Player objects, calls teleport on one, has one hit the other, and calls toString on both objects.

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 Databases Questions!