forked from TrippW/onitama
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnitama.java
More file actions
113 lines (92 loc) · 2.46 KB
/
Onitama.java
File metadata and controls
113 lines (92 loc) · 2.46 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
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
public class Onitama {
private static Onitama game;
private GUI gui;
private Player p1, p2;
private Board board;
private static int p1Difficulty=Player.EASY, p2Difficulty=Player.EASY;
private static int playerColor = Board.blue;
private static int playerCount = 1;
public static void main(String [] args) {
Card.init();
Deck.init();
game = new Onitama();
game.run();
}
public static void reset() {
Deck.shuffle();
game.resetGame();
game.run();
}
public static void updatePlayerCount(int n) {
playerCount = n;
}
public static void updateDifficulty(int newDifficulty) {
p1Difficulty = p2Difficulty = newDifficulty;
game.updateDifficulty();
}
public Onitama() {
Card cards[] = Deck.draw();
p1 = new Player(new Card[] {cards[0],cards[3]}, Board.red, Player.EASY);
p2 = new Player(new Card[] {cards[1],cards[4]}, Board.blue);
board = null;
if(cards[2].getColor() == Board.red)
board = new Board(cards[2], p1, p2);
else
board = new Board(cards[2], p2, p1);
gui = new GUI(cards, board);
p1.setBoard(board);
p2.setBoard(board);
}
public void run() {
if(board.isComputerTurn())
gui.compTurn();
}
private void updateDifficulty() {
switch(playerCount) {
case 2:
System.out.println("No change");
break;
case 1:
if(playerColor == Board.red) {
p2.setDifficulty(p2Difficulty);
} else {
p1.setDifficulty(p1Difficulty);
}
break;
case 0:
p1.setDifficulty(p1Difficulty);
p2.setDifficulty(p2Difficulty);
break;
}
}
public void resetGame() {
Card cards[] = Deck.draw();
switch(playerCount) {
case 2:
p1 = new Player(new Card[] {cards[0],cards[3]}, Board.red);
p2 = new Player(new Card[] {cards[1],cards[4]}, Board.blue);
break;
case 1:
if(playerColor == Board.red) {
p1 = new Player(new Card[] {cards[0],cards[3]}, Board.red);
p2 = new Player(new Card[] {cards[1],cards[4]}, Board.blue, p2Difficulty);
} else {
p1 = new Player(new Card[] {cards[0],cards[3]}, Board.red, p1Difficulty);
p2 = new Player(new Card[] {cards[1],cards[4]}, Board.blue);
}
break;
case 0:
p1 = new Player(new Card[] {cards[0],cards[3]}, Board.red, p1Difficulty);
p2 = new Player(new Card[] {cards[1],cards[4]}, Board.blue, p2Difficulty);
break;
}
board = null;
if(cards[2].getColor() == Board.red)
board = new Board(cards[2], p1, p2);
else
board = new Board(cards[2], p2, p1);
p1.setBoard(board);
p2.setBoard(board);
gui.reset(cards, board);
}
}