-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
144 lines (126 loc) · 3.75 KB
/
Game.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* @author Evgeni
*/
public class Game {
static CardField sf;
static CardsStack ks;
static FirstBot fBot;
static SecondBot sBot;
static Bot winner;
static Design t;
static boolean fBotsTurn = false;
static boolean pause;
static int waitingTime = 10; //Change this to a higher value while developing (e.g.: 1500)
public Game(int cardAmount) {
ks = new CardsStack(cardAmount);
Game.sBot = new SecondBot(15);
Game.fBot = new FirstBot(15);
winner = null;
System.out.println();
Card beginnerCard = CardsStack.drawCard();
System.out.print("Placed Card: ");
Card.showCard(beginnerCard);
CardField.placeCard(beginnerCard);
System.out.println();
System.out.println("FirstBots cards: ");
Card.showCards(fBot.getCards());
System.out.println();
System.out.println("SecondBots cards: ");
Card.showCards(sBot.getCards());
System.out.println();
t = new Design();
if ((int) (Math.random()*10) > 4) {
System.out.println(fBot.getName() + "´s first turn: ");
fBot.drawCard();
nextTurn(fBot);
Main.stats.beginner(fBot);
} else {
System.out.println(sBot.getName() + "´s first turn: ");
sBot.drawCard();
nextTurn(sBot);
Main.stats.beginner(sBot);
}
}
public static void pauseGame(boolean stop) {
pause = stop;
System.out.println("Pause: " + stop);
}
public static boolean isPaused() {
return pause;
}
public void nextTurn(Bot bot) {
repaint();
System.out.println();
System.out.println(bot.getName() + "´s turn:");
delay();
while (isPaused()) {
System.out.print("");
}
delay();
if (bot.equals(fBot)) {
fBotsTurn = true;
repaint();
delay();
while (isPaused()) {
System.out.print("");
}
delay();
fBot.placeCard(sBot.getCards(), CardField.getCard());
} else {
fBotsTurn = false;
repaint();
delay();
while (isPaused()) {
System.out.print("");
}
delay();
sBot.placeCard(fBot.getCards(), CardField.getCard());
}
if (bot.placed()) {
if (bot.getCardAmount() > 0) {
Card.showCards(bot.getCards());
if (bot.equals(fBot)) {
nextTurn(sBot);
} else {
nextTurn(fBot);
}
} else {
setWinner(bot);
}
} else {
if (bot.equals(fBot)) {
setWinner(sBot);
} else {
setWinner(fBot);
}
}
}
public static void delay() {
try {
Thread.sleep(waitingTime/2);
} catch (InterruptedException ex) {
}
}
public static boolean fBotsTurn() {
return fBotsTurn;
}
public static void repaint() {
if (t != null) {
t.repaint();
}
}
private void setWinner(Bot bot) {
if (t != null) {
t.gameEnd();
}
repaint();
winner = bot;
System.out.println(bot.getName() + " won!");
}
public boolean isFinished() {
return winner != null;
}
public Bot getWinner() {
return winner;
}
}