-
Notifications
You must be signed in to change notification settings - Fork 0
/
MancalaTester.java
114 lines (99 loc) · 4.02 KB
/
MancalaTester.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
import java.util.Scanner;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
/**
* @author Samuel Boulanger
* @author Cindy Ho
* @author Aldo Barrientos
* Runnable class that sets up the Mancala game and prompts for settings
*/
public class MancalaTester {
enum BoardChoice { RECTANGLE, CIRCLE }
private static BoardChoice choice;
private static int pebbleCount;
/**
* main function that starts the program
*/
public static void main (String args[]){
doInitProcess1();
}
/**
* creates frame to prompt the user to select the board layout
*/
public static void doInitProcess1(){
JFrame initframe = new JFrame();
initframe.setLayout(new FlowLayout());
JLabel initLabel = new JLabel("Which Board do you choose?");
initframe.add(initLabel);
JButton rectButton = new JButton("Rectangle");
rectButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
initframe.dispose();
choice = BoardChoice.RECTANGLE;
doInitProcess2();
}
});
JButton circleButton = new JButton("Circle");
circleButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
initframe.dispose();
choice = BoardChoice.CIRCLE;
doInitProcess2();
}
});
initframe.add(rectButton);
initframe.add(circleButton);
initframe.pack();
initframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initframe.setVisible(true);
}
/**
* creates frame to prompt user to select the amount of pebbles
*/
public static void doInitProcess2(){
JFrame initframe = new JFrame();
initframe.setLayout(new FlowLayout());
JLabel initLabel = new JLabel("How many pebbles?");
initframe.add(initLabel);
JButton rectButton = new JButton("3");
rectButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
initframe.dispose();
pebbleCount = 3;
doInitProcess3();
}
});
JButton circleButton = new JButton("4");
circleButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
initframe.dispose();
pebbleCount = 4;
doInitProcess3();
}
});
initframe.add(rectButton);
initframe.add(circleButton);
initframe.pack();
initframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initframe.setVisible(true);
}
/**
* starts the Mancala game based on selected attributes
*/
public static void doInitProcess3(){
DataModel dm = new DataModel(pebbleCount);
Board b = new Board(dm);
if(choice == BoardChoice.RECTANGLE){
b.attachBoardLayout(new RectangleBoard(dm.getData()));
}
if(choice == BoardChoice.CIRCLE){
b.attachBoardLayout(new CircularBoard(dm.getData()));
}
dm.attachListener(b);
b.pack();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setVisible(true);
}
}