-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMancala.java
More file actions
83 lines (68 loc) · 2.03 KB
/
Copy pathMancala.java
File metadata and controls
83 lines (68 loc) · 2.03 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
82
83
/****************************************************************
* Mancala.java
*/
public class Mancala
{
/** time limit each player has to decide on a move (default: 10 secs) **/
public static final int TIME_LIMIT = 10;
/** number of stones with which to initialize bins (default: 4) **/
public static final int NUM_STONES = 4;
/** pausing time when moving stones among pots **/
public static final int SLEEP_TIME = 400;
/**this is the gui for the game **/
public static GUI gui;
public static void main(String[] args) throws Exception
{
String player1 = null, player2;
switch (args.length)
{
case 1: player2 = args[0];
player1 = new String("HumanPlayer");
break;
case 2: player1 = args[0];
player2 = args[1];
break;
case 0:
default:
player1 = new String("HumanPlayer");
player2 = new String("HumanPlayer");
break;
}
//set up the gui
gui = new GUI(player1, player2);
Match match = new Match(player1, player2, TIME_LIMIT, NUM_STONES);
match.loadPlayers();
/**Set up the gui**/
int winner = match.play();
switch (winner)
{
case 1:
if (match.getPlayer1Score() == -1)
{
Mancala.gui.textArea.append(player1+":1 has won the match by default\n");
}
else
{
Mancala.gui.textArea.append(player1+":1 has won the match " +
match.getPlayer1Score() + " to " +
match.getPlayer2Score() + "\n");
}
break;
case 2:
if (match.getPlayer2Score() == -1) {
Mancala.gui.textArea.append(player2+":2 has won the match by default\n" );
}
else
{
Mancala.gui.textArea.append(player2+":2 has won the match " +
match.getPlayer2Score() + " to " +
match.getPlayer1Score() + "\n");
}
break;
case 0:
Mancala.gui.textArea.append(player1+":1 and "+player2+":2 tie at " +
match.getPlayer1Score() + " each.\n");
}
return;
}
}