-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathChip.java
More file actions
60 lines (51 loc) · 975 Bytes
/
Chip.java
File metadata and controls
60 lines (51 loc) · 975 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.awt.Point;
import java.util.ArrayList;
public class Chip
{
Point position = new Point();
private int xPos;
private int yPos;
ArrayList<Integer> keys = new ArrayList<Integer>();
public Chip()
{
position.setLocation(13, 13);
xPos = 13;
yPos = 13;
}
public void goRight()
{
if (position.getX()+1 <= 26)
position.setLocation(position.getX()+1, position.getY());
xPos++;
}
public void goLeft()
{
if (position.getX()-1 > 0)
position.setLocation(position.getX()-1, position.getY());
xPos--;
}
public void goUp()
{
if (position.getX()-1 > 0)
position.setLocation(position.getX(), position.getY()-1);
yPos--;
}
public void goDown()
{
if (position.getY()+1 <= 26)
position.setLocation(position.getX(), position.getY()+1);
yPos++;
}
public Point getPosition()
{
return this.position;
}
public ArrayList<Integer> getKeys()
{
return keys;
}
public void addKey(int key)
{
keys.add(key-1);
}
}