-
Notifications
You must be signed in to change notification settings - Fork 0
/
PitShape.java
145 lines (131 loc) · 3.36 KB
/
PitShape.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
/**
* Fall 2022 CS151 Team Project
* Simple Mancala Board
* Instructor: Dr. Suneuy Kim
*
* @author Sean Nian, Abdugafur Dalerzoda, Xianqiao Zhang, Aarushi Gautam
* @version 1.0 12/1/2022
*/
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/**
* PitShape contains what the pits look like and draws out each pit given x and y coordinates
*/
public class PitShape {
private int x;
private int y;
private int width;
private int pitNum;
private Player player;
/**
* Creates a PitShape
* @param pitNum - the pit number the pit is in
* @param x - xAxis
* @param y - yAxis
* @param width - width of the pit
* @param i - variable to add to each axis to relocate where to draw the Pit
* @param player - player who owns the pit
*/
public PitShape(int pitNum,int x, int y, int width,int i, Player player)
{
this.x = x+i*100;
this.y = y;
this.width = width;
this.pitNum = pitNum;
this.player = player;
}
/**
* Will draw the PitShape
* @param g2 - the graphics that is being used to draw the pit
* @param x - xAxis
* @param y - yAxis
* @param i - variable to add to each axis to relocate where to draw the Pit
* @param width - width of the pit
* @param color - color of the pit
*/
public void draw(Graphics2D g2,int x,int y,int i, int width, Color color)
{
if(width == 80) {
g2.drawOval(x + i * 100, y, width, width);
g2.setPaint(color);
g2.fillOval(x + i * 100, y, width, width);
}else if(width == 84){
g2.drawRect(x + i * 100, y, width, width);
g2.setPaint(color);
g2.fillRect(x + i * 100, y, width, width);
}
else{
g2.setBackground(color);
g2.drawRect(x, y, width, width+260);
g2.fillRect(x, y, width, width+260);
}
}
/**
* Returns the xAxis
* @return - xAxis
*/
public int getX() {
return x;
}
/**
* Sets the xAxis
* @param x - xAxis
*/
public void setX(int x) {
this.x = x;
}
/**
* Returns the yAxis
* @return - yAxis
*/
public int getY() {
return y;
}
/**
* Sets the yAxis
* @param y - yAxis
*/
public void setY(int y) {
this.y = y;
}
/**
* Returns the width of the pit
* @return - width of the pit
*/
public int getWidth() {
return width;
}
/**
* Sets the width of the pit
* @param width - width of the pit
*/
public void setWidth(int width) {
this.width = width;
}
/**
* Contains method which checks to see if point P is in the PitShape
* @param p - point P being checked
* @return - true or false if point P is in the pit
*/
public boolean contains(Point2D p)
{
return getX() <= p.getX() && p.getX() <= getX() + getWidth()
&& getY() <= p.getY() && p.getY() <= getY() + getWidth();
}
/**
* Returns the pit number
* @return - the pit number
*/
public int getPitNum(){
return pitNum;
};
/**
* Returns the player who owns the pit
* @return - the player who owns the pit
*/
public Player getPlayer()
{
return player;
}
}