Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions