package squishgame;
/*
* The player class allows for a player to be created with:
* a name
* a location on a grid (0-10, 0-10)
*
* The player can move North, South, East, or West but will not move off the
* grid (must stay within (0,0) to (10,10)). If a move is called, it will update
* it's location or not move (if outside the grid).
*
* Complete the constructors and methods below
*/
public class Player implements Comparable {
private String myname;
private int mylocx, mylocy;
public Player(String name) {
// constucts a new player with a random location
}
public Player(String name, int x, int y) {
// constructs a new player with the given location
}
public void moveNorth() {
// moves the player up 1 location if possible
}
public void moveSouth() {
// moves the player down 1 location if possible
}
public void moveEast() {
// moves the player right 1 location if possible
}
public void moveWest() {
// moves the player left 1 location if possible
}
public int getX() {
// returns the x position
}
public int getY() {
// returns the y position
}
public double distance(Player p) {
// returns the distance between this player and player p
}
public boolean isSamelocation(Player p) {
// returns true if this location is the same a the player p's location
}
public String toString() {
// returns a string representation of the player's name and location
}
public int compareTo(Object o) {
// returns a negative number, 0, or a positive number depending if this
// object is less than, equal to, or greater than the parameter o
// Players are ordered by x position, then by y position so (2,5) < (3,1)
}
}
dahliababy 0 Newbie Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

JenniLei
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.