-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHole.java
164 lines (148 loc) · 3.16 KB
/
Hole.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import javax.swing.Icon;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.lang.Cloneable;
import java.lang.CloneNotSupportedException;
/**
* @author Samuel Boulanger
* @author Cindy Ho
* @author Aldo Barrientos
* Abstract class that defines the general holes in a Mancala game
*/
abstract class Hole implements Cloneable
{
private int x;
private int y;
private int pebbles;
protected int pebbleX;
protected int pebbleY;
private int arrPos;
int[][] holePos = new int[14][2];
/**
* Contructor that initalizes the pebble count and array position
* @param pebbles the amount of pebbles
* @param arrPos the index in the dataModel array
*/
public Hole(int pebbles, int arrPos)
{
this.pebbles = pebbles;
this.arrPos = arrPos;
}
/**
* gets the index of this hole in the dataModel array
* @return index of position in dataModel array
*/
public int getArrPos()
{
return arrPos;
}
/**
* sets the x position of the Hole
* @param x the x position
*/
public void setX(int x)
{
this.x = x;
}
/**
* sets the y position of the Hole
* @param y the y position
*/
public void setY(int y)
{
this.y = y;
}
/**
* returns a clone of the hole position
* @return the clones hole
*/
public Hole clone(){
try {
Hole hole = (Hole)super.clone();
return hole;
} catch (CloneNotSupportedException e){
return null;
}
}
/**
* sets the pebble count in the hole
* @param pebbles the amount of pebbles
*/
public void setStones(int pebbles)
{
this.pebbles = pebbles;
}
/**
* returns the amount of pebbles in the hole
* @return the amount of pebbles in the hole
*/
public int getStones()
{
return pebbles;
}
/**
* checks whether an x and y coordinate is in the area of the hole
* @param x coordinate
* @param y coordinate
* @return return true if in circle false otherwise
*/
public boolean contains(int x, int y)
{
if (x > this.x && x < this.x + 120 && y > this.y && y < this.y + 120){
return true;
}
return false;
}
public int getPebbleX()
{
return pebbleX;
}
public int getPebbleY()
{
return pebbleY;
}
/**
* gets the width of hole
* @param width
*/
abstract public int getWidth();
/**
* gets the height of hole
* @param height
*/
abstract public int getHeight();
/**
* translates the pebble to be drawn
* @param x position
* @param y position
* @param z pebble count
*/
abstract public void translatePebble(int x, int y, int z);
/**
* draws the hole onto the screen
* @param g2 2-dimensional graphics object to draw on
* @param x coordinate
* @param y coordinate
*/
public void draw(Graphics2D g2, int x, int y){
setX(x);
setY(y);
Ellipse2D hole = new Ellipse2D.Double(x, y, this.getWidth(), this.getHeight());
Color color = new Color(155, 100, 49);
g2.setColor(color);
g2.draw(hole);
g2.fill(hole);
g2.setColor(Color.BLACK);
this.drawStones(g2, x, y);
}
/**
* draws the all the stones in the hole
* @param g2 2-dimensional graphics object to draw on
* @param x coordinate
* @param y coordinate
*/
abstract public void drawStones(Graphics2D g2, int x, int y);
}