Repository navigation
Expand file tree
/
Copy pathPitPanel.java
More file actions
81 lines (62 loc) · 1.81 KB
/
Copy pathPitPanel.java
File metadata and controls
81 lines (62 loc) · 1.81 KB
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
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class PitPanel extends JPanel implements ChangeListener, MouseListener
{
private int stoneAmount;
private char pitSide;
private int pitNumber;
private MancalaModel mancalaModel;
private Interface format;
public PitPanel(MancalaModel mancalaModel, char pitSide, int pitNumber)
{
this.mancalaModel = mancalaModel;
this.pitSide = pitSide;
this.pitNumber = pitNumber;
//Only add mouse listener for player A
if(pitSide == 'a')
this.addMouseListener(this);
stoneAmount = mancalaModel.getPitValue(pitSide, pitNumber);
}
public void setFormat(Interface format)
{
this.format = format;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(format.getColor());
g2.draw(format.getPitShape());
g2.setColor(format.getFillColor());
for (Shape s : format.getPitStoneShapes(stoneAmount))
g2.fill(s);
}
public void stateChanged(ChangeEvent e)
{
stoneAmount = mancalaModel.getPitValue(pitSide, pitNumber);
}
public void mouseClicked(MouseEvent arg0)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
if(mancalaModel.currentPlayer=='a')
if(mancalaModel.getPitValue(pitSide, pitNumber) != 0)
mancalaModel.doTurn(pitSide, pitNumber);
}
public void mouseReleased(MouseEvent e)
{
}
}