-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstTo100.java
More file actions
53 lines (48 loc) · 2 KB
/
FirstTo100.java
File metadata and controls
53 lines (48 loc) · 2 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
import java.util.Random;
/**
* Plays dice game where the first Player to reach 100 wins.
*/
public class FirstTo100 {
public static void main(String[] args) throws InterruptedException {
SoundClipTest sound = new SoundClipTest();
final int PAUSE_TIME = 200;
int currentHighScore = 0;
CircularLinkedList<Player> players = new CircularLinkedList<>();
players.add(new Player("Lilac"));
players.add(new Player("Daisy"));
players.add(new Player("Rose"));
players.add(new Player("Briar"));
Random random = new Random();
System.out.println("LET THE GAME BEGIN!");
Thread.sleep(PAUSE_TIME);
for (Player player : players) {
if (player.getName().equals("Lilac")) {
System.out.println("\nNew Round Starting...");
//start round sound
if (sound.clip.isRunning()) {
sound.clip.stop();
}
sound.clip.setFramePosition(0);
sound.clip.start();
Thread.sleep(sound.clip.getMicrosecondLength() / 1000 / 4);
// sound.clip.stop();
}
int roll1 = random.nextInt(6) + 1;
int roll2 = random.nextInt(6) + 1;
String printer = player.getName();
printer += " rolls a " + roll1 + " and a " + roll2;
printer += " score now totaling " + player.increaseScore(roll1 + roll2);
if (player.getScore() > currentHighScore) {
currentHighScore = player.getScore();
printer += "...new high player!";
}
System.out.println(printer);
Thread.sleep(PAUSE_TIME);
if (player.getScore() >= 100) {
//play victory sound
System.out.println("\nThe winner is " + player.getName() + " with a score of " + player.getScore() + "!");
return;
}
}
}
}