-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
36 lines (35 loc) · 1.03 KB
/
Player.java
File metadata and controls
36 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.awt.*;
/**
* Creates a subclass of Unit that can move and has a paint method.
* @author Max Bernstein, Chris Hinstorff, Marco Valente
*
*/
public class Player extends Unit {
/**
* Creates a player with an x coordinate x, y coordinate y, and color c
* @param x the x coordinate
* @param y the y coordinate
* @param c the color
*/
public Player(int x, int y, Color c) {
xcoord = x;
ycoord = y;
color = c;
}
/**
* Moves the player to the set coordinate
* @param x the x coordinate
* @param y the y coordinate
*/
public void move(int x, int y) {
setX(x);
setY(y);
}
/**
* Draws the player, implementing the method in the Unit superclass.
*/
public void paint(Graphics g) {
g.setColor(color);
g.fillOval(xcoord * Globals.GRID_SIZE + (Globals.GRID_SIZE - Globals.UNIT_SIZE) / 2, ycoord * Globals.GRID_SIZE + (Globals.GRID_SIZE - Globals.UNIT_SIZE) / 2, Globals.UNIT_SIZE, Globals.UNIT_SIZE);
}
}