-
Notifications
You must be signed in to change notification settings - Fork 2
/
PitPanel.java
103 lines (88 loc) · 2.32 KB
/
PitPanel.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
import src.Model.MancalaModel;
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;
/**
COPYRIGHT (C). All Rights Reserved.
@author Jonathan Sagabaen
@version 1.00
Class representing a pit display panel.
*/
public class PitPanel extends JPanel implements ChangeListener, MouseListener
{
private int stoneAmount;
private char pitSide;
private int pitNumber;
private MancalaModel mancalaModel;
private BoardFormatter format;
/**
* Constructor.
* @param mancalaModel model this panel is attached to
* @param pitSide side this pit is on
* @param pitNumber number of pit
*/
public PitPanel(MancalaModel mancalaModel, char pitSide, int pitNumber)
{
this.mancalaModel = mancalaModel;
this.pitSide = pitSide;
this.pitNumber = pitNumber;
this.addMouseListener(this);
stoneAmount = mancalaModel.getPitValue(pitSide, pitNumber);
}
/**
* Set panel format.
* @param format format to be set to
*/
public void setFormat(BoardFormatter format)
{
this.format = format;
}
/**
* Display panel.
*/
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);
}
/**
* Update panel based on model state change.
*/
public void stateChanged(ChangeEvent e)
{
stoneAmount = mancalaModel.getPitValue(pitSide, pitNumber);
}
public void mouseClicked(MouseEvent arg0)
{
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e)
{
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e)
{
// TODO Auto-generated method stub
}
/**
* Controller to do a turn when clicking on pit.
*/
public void mousePressed(MouseEvent e)
{
mancalaModel.doTurn(pitSide, pitNumber);
}
public void mouseReleased(MouseEvent e)
{
// TODO Auto-generated method stub
}
}