-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWar.java
More file actions
100 lines (98 loc) · 3.84 KB
/
Copy pathWar.java
File metadata and controls
100 lines (98 loc) · 3.84 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
//Nancy
import java.util.*;
public class War
{
public static void main (String [] args){
int [] hand1 = new int [26];
int [] hand2 = new int [26];
for (int i = 0; i < 26; i++){
hand1[i] = (int) (Math.random() * 14) + 1;
hand2[i] = (int) (Math.random() * 14) + 1;
}
System.out.print("Player 1 has [");
for (int i = 0; i < 25; i++){
if (hand1[i] > 10){
if (hand1[i] == 11){System.out.print("J, ");}
else if (hand1[i] == 12){System.out.print("Q, ");}
else if (hand1[i] == 13){System.out.print("K, ");}
else{System.out.print("A, ");}
}
else {System.out.print(hand1[i] + ", ");}
}
if (hand1[25] > 10){
if (hand1[25] == 11){System.out.print("J]");}
else if (hand1[25] == 12){System.out.print("Q]");}
else if (hand1[25] == 13){System.out.print("K]");}
else{System.out.print("A]");}
}
else{System.out.println(hand1[25] + "]");}
System.out.print("Player 2 has [");
for (int i = 0; i < 25; i++){
if (hand2[i] > 10){
if (hand2[i] == 11){System.out.print("J, ");}
else if (hand2[i] == 12){System.out.print("Q, ");}
else if (hand2[i] == 13){System.out.print("K, ");}
else{System.out.print("A, ");}
}
else{System.out.print(hand2[i] + ", ");}
}
if (hand2[25] > 10){
if (hand2[25] == 11){System.out.print("J]");}
else if (hand2[25] == 12){System.out.print("Q]");}
else if (hand2[25] == 13){System.out.print("K]");}
else{System.out.print("A]");}
}
else{System.out.println(hand2[25] + "]");}
int wins1 = 0;
int wins2 = 0;
int ties = 0;
for (int i = 0; i < 26; i++){
System.out.println("Round " + (i + 1) + ":");
System.out.print("Player 1: ");
if (hand1[i] > 10){
if (hand1[i] == 11){System.out.println("J");}
else if (hand1[i] == 12){System.out.println("Q");}
else if (hand1[i] == 13){System.out.println("K");}
else{System.out.println("A");}
}
else{System.out.println(hand1[i]);}
System.out.print("Player 2: ");
if (hand2[i] > 10){
if (hand2[i] == 11){System.out.println("J");}
else if (hand2[i] == 12){System.out.println("Q");}
else if (hand2[i] == 13){System.out.println("K");}
else{System.out.println("A");}
}
else{System.out.println(hand2[i]);}
if (hand1[i] > hand2[i]){
System.out.println("Player 1 wins!");
wins1 ++;
}
else if (hand1[i] < hand2[i]){
System.out.println("Player 2 wins!");
wins2 ++;
}
else{
System.out.println("Tie!");
ties ++;
}
System.out.println();
System.out.println();
System.out.println();
System.out.println("Totals:");
System.out.println("Player 1: " + wins1);
System.out.println("Player 2: " + wins2);
System.out.println("Ties: " + ties);
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
}
System.out.println("Game over!");
if(wins1 > wins2){System.out.println("Player 1 won!");}
else if(wins1 < wins2){System.out.println("Player 3 won!");}
else{System.out.println("Tie!");}
}
}