-
Notifications
You must be signed in to change notification settings - Fork 0
/
Peg.java
87 lines (75 loc) · 1.52 KB
/
Peg.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.ArrayList;
public class Peg
{
private int xCoord = 0;
private int yCoord = 0;
private int numBeads = 0;
private ArrayList<Bead> beads = new ArrayList<Bead>();
public Peg(int x, int y)
{
Debug.log("Creating Peg at: (x: " + x + ", y: " + y +")");
xCoord = x;
yCoord = y;
}
public boolean addBead(Colour colour)
{
boolean successful = false;
if (numBeads < 4)
{
Bead bead = new Bead(colour, xCoord, yCoord, numBeads);
beads.add(bead);
numBeads++;
successful = true;
}
else
{
successful = false;
}
return successful;
}
public boolean removeBead(Bead bead)
{
boolean successful = false;
if (numBeads > 0) {
int x = bead.getXCoord();
int y = bead.getYCoord();
int z = bead.getZCoord();
Debug.log("Removing bead at: (x: " + x + ", y: " + y + ", z: " + z);
beads.remove(bead);
numBeads--;
successful = true;
}
else
{
successful = false;
}
return successful;
}
public Bead getBead(int n)
{
Bead bead = beads.get(n - 1);
int x = bead.getXCoord();
int y = bead.getYCoord();
int z = bead.getZCoord();
Debug.log("Getting bead at: (x: " + x + ", " + y + ")");
return bead;
}
public ArrayList<Bead> getAllBeads()
{
Debug.log("Getting all beads from peg: (x: " + xCoord + ", y: " + yCoord + ")");
return beads;
}
public int getXCoord() {
return xCoord;
}
public int getYCoord() {
return yCoord;
}
public int getNumBeads() {
return numBeads;
}
public void emptyBeads(){
beads.removeAll(beads);
numBeads = 0;
}
}