-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pit.java
78 lines (68 loc) · 1.45 KB
/
Pit.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
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
/**
* Pit class representing the Pits
*/
class Pit extends Hole
{
private int height = 120;
private int width = 120;
/**
* calls the Hole (super) contructor
*/
public Pit(int pebbles, int id)
{
super(pebbles, id);
}
/**
* draws the all the stones in the hole
* @param 2-dimensional graphics object to draw on
* @param x coordinate
* @param y coordinate
*/
public void drawStones(Graphics2D g2, int x, int y)
{
if(this.getStones() < 5)
{
for(int i = 0; i < this.getStones(); i++)
{
translatePebble(x, y, i);
Stone pebble = new Stone();
pebble.draw(g2, pebbleX, pebbleY, i);
}
}
else
{ Font Title = new Font("Arial", Font.PLAIN, 50);
g2.setFont(Title);
g2.setColor(Color.black);
g2.drawString(this.getStones() + "", x + 45, y + 75);
}
}
/**
* translates the pebble to be drawn
* @param x position
* @param y position
* @param z pebble count
*/
public void translatePebble(int x, int y, int z)
{
this.pebbleX = (int) (Math.cos(z * 3.14f / 2 - 3.14f / 2) * 30 + (x + 40));
this.pebbleY = (int) (Math.sin(z * 3.14f / 2 - 3.14f / 2) * 30 + (y + 40));
}
/**
* return the pit width
* @return the pit width integer
*/
public int getWidth(){
return this.width;
}
/**
* return the pit height
* @return the pit height integer
*/
public int getHeight(){
return this.height;
}
}