-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLand.java
More file actions
83 lines (72 loc) · 2.43 KB
/
GameLand.java
File metadata and controls
83 lines (72 loc) · 2.43 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
//Luke Bradaric
import java.util.concurrent.ThreadLocalRandom;
public class GameLand
{
private int player1;
private int player2;
private boolean oneTurn;
public GameLand()
{
}
private void Print()
{
System.out.println("Player1 is on space " + player1);
System.out.println("Player2 is on space " + player2);
}
private void Check(){
if(player1 >= 100){
System.out.println("Player1 wins!");
}else if(player2 >= 100){
System.out.println("Player2 wins!");
}else{
}
}
public void player1Roll(){
if(oneTurn == true){
int roll = ThreadLocalRandom.current().nextInt(1, 12 + 1);
System.out.println("Rolled a " + roll);
if(roll == 2 || roll == 12){
System.out.println("Player1 lost this turn");
}else if(roll == 7){
System.out.println("Player1 moves backwards 7 spaces");
player1 -= 7;
if(player1 <= 0)
player1 = 0;
}else{
player1 += roll;
}
if(player1 == player2){
System.out.println("You landed on the other players square and bumped them back to start!");
player2 = 0;
}
Print();
Check();
oneTurn = false;
}else
System.out.println("Not your turn");
}
public void player2Roll(){
if(oneTurn == false){
int roll = ThreadLocalRandom.current().nextInt(1, 12 + 1);
System.out.println("Rolled a " + roll);
if(roll == 2 || roll == 12){
System.out.println("Player2 lost this turn");
}else if(roll == 7){
System.out.println("Player2 moves backwards 7 spaces");
player2 -= 7;
if(player1 <= 0)
player2 = 0;
}else{
player2 += roll;
}
if(player1 == player2){
System.out.println("You landed on the other players square and bumped them back to start!");
player1 = 0;
}
Print();
Check();
oneTurn = true;
}else
System.out.println("Not your turn");
}
}