-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
120 lines (98 loc) · 4.15 KB
/
Copy pathApp.java
File metadata and controls
120 lines (98 loc) · 4.15 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package WarCardGame;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class App {
public static void main(String[] args){
Scanner userInput = new Scanner(System.in);
System.out.print("Would you like to play a game? (y/n; yes/no; Y/N; Yes/No)");
String answer = userInput.next();
if(answer.equals("yes") || answer.equals("y")|| answer.equals("Yes") || answer.equals("Y")){
//create players
Player player1 = new Player();
Player player2 = new Player();
//ask human player for name
System.out.print("What is your name? ");
String name = userInput.next();
player1.setName(name);
player2.setName("SuperJava");
//introduce players
System.out.println("Hello " + player1.getName());
System.out.println("I am " + player2.getName());
delay();
Deck gameDeck = new Deck();
System.out.println("This is your new Game Deck.");
delay();
line();
gameDeck.describe();
line();
System.out.println("I will shuffle the cards.");
delay();
line();
gameDeck.shuffleDeck();
gameDeck.describe();
System.out.println("The cards have been shuffled.");
line();
delay();
/*player1.drawHand(gameDeck);
player1.describe();
System.out.println();
player2.drawHand(gameDeck);
player2.describe();*/
//I did not use a loop iterating 52 times.
//Iterating 26 times and sequentially drawing one card per player is simpler and requires less code.
for(int i=1;i<=26;i++){
player1.drawHand(gameDeck);
player2.drawHand(gameDeck);
}
System.out.println("I will now deal the cards.");
line();
delay();
player1.describe();
System.out.println();
player2.describe();
System.out.println();
System.out.println("Let's play...");
delay();
for(int i=1;i<=26;i++){
Card showPlayer1 = player1.flip();
Card showPlayer2 = player2.flip();
System.out.print(player1.getName() + " plays -->");
showPlayer1.describe();
System.out.print(player2.getName() + " plays -->");
showPlayer2.describe();
if(showPlayer1.getValue() > showPlayer2.getValue()){
player1.incrementScore();
System.out.println(player1.getName() + " wins this hand. Score: " + player1.getScore());
System.out.println();
}else{
player2.incrementScore();
System.out.println(player2.getName() + " wins this hand. Score: " + player2.getScore());
System.out.println();
}
delay();
}
line();
System.out.println("Final Score -- " + player1.getName() + ": "+ player1.getScore() + " " + player2.getName() + ": " + player2.getScore());
if(player1.getScore() > player2.getScore()){
System.out.println(player1.getName() + " is the winner!");
} else if (player2.getScore() > player1.getScore()) {
System.out.println(player2.getName() + " is the winner!");
}else
System.out.println("It is a Draw! Play Again!");
}else
System.out.println("Ok. Goodbye.... Chickenbird!! ()>");
}
public static void line(){
//method to print separation lines between homework prompts
System.out.println("__________________________________________________________________________________________");
System.out.println();//print an emptly line
}
public static void delay(){
//create a delay to yallow each hand to be observed during the game.
try{
TimeUnit.SECONDS.sleep(2);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}