-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRatscrewOnePlayer.java
64 lines (62 loc) · 2 KB
/
RatscrewOnePlayer.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
/**
* Write a description of class RatscrewSim here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RatscrewOnePlayer
{
public static int waitTime = 1000;
public static void main(String[] args){
boolean currentlyPlaying = true;
boolean playing = true;
RatscrewGUI gui = new OnePlayerGUI();
Ratscrew game = gui.getGame();
gui.displayGame();
while (playing){
while (!game.gameOver()){
if (game.claimable() || game.pair() || game.sandwich()){
sleep(waitTime/2);
autoClaim(game, gui);
}
else if (game.getCurrentPlayer()!=0) {
sleep(waitTime/2);
game.draw(game.getCurrentPlayer());
gui.repaint();
}
else if (game.getCurrentPlayer()==0 && game.deckSize(0)==0) {
game.switchTurn();
gui.repaint();
}
else {
sleep(waitTime/2);
}
sleep(waitTime/2);
}
}
}
public static void autoClaim(Ratscrew game, RatscrewGUI gui){
//sleep(waitTime/2);
if (game.claimable() && game.getFaceCardPlayer()!=0){
//sleep(waitTime);
gui.claim(game.getFaceCardPlayer());
gui.repaint();
}
else if (game.pair() || game.sandwich()){
int claimer=0;
do{
claimer = (int) (Math.random()*game.getPlayers());
}while (claimer==0 || game.getPlayerPile(claimer).size()==0);
gui.claim(claimer);
gui.repaint();
}
}
public static void sleep(int waitTime){
try{
Thread.sleep(waitTime);
}
catch(Exception e){
System.out.println(e.toString());
}
}
}