-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient class
More file actions
95 lines (92 loc) · 3.37 KB
/
Copy pathclient class
File metadata and controls
95 lines (92 loc) · 3.37 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
/******************************************************************************
Eric Zhang
Comp Sci 3
March 23, 2021
High-Low Program:Graded
*******************************************************************************/
import java.io.*;
public class Main
{
public static String capitalize (String word)
{
word = word.toUpperCase ( );
return word;
}
public static void main(String[] args) throws IOException
{
DataInputStream reader = new DataInputStream(System.in);
String choice;
Deck deck = new Deck();
deck.shuffle();
Card current = new Card ();
int value;
int score;
boolean check = true;
String ok = "Y";
int highscore;
//deck made and shuffled
BufferedReader inFile = new BufferedReader(new FileReader("Hi-Score.txt"));
highscore = Integer.parseInt(inFile.readLine());
while (ok.equals("Y"))
{
score = 0 ;
check = true;
System.out.println("Welcome to High-Low. A card will be dealt from the deck and you have to predict whether the next card will be higher or lower. Your score is calculated by the number of correct guesses you make before you get one wrong!");
current = deck.dealcard();
System.out.print("\n\nThe first card is the "+ current.showValue() + " of " + current.getSuit() + ".");
while (check == true)
{
value = current.getValue();
System.out.print("\n\nWill the next card be higher or lower? (H / L): ");
choice = reader.readLine();
choice = capitalize(choice);
while (!(choice.equals("H")) && !(choice.equals("L")))
{
System.out.print("\n\nInvalid input please enter H or L: ");
choice = reader.readLine();
choice = capitalize(choice);
}
current = deck.dealcard();
System.out.print("\n\nThe next card is the "+ current.showValue() + " of " + current.getSuit() + ".");
if ((choice.equals("H") && (current.getValue() > value)))
{
System.out.print("\n\nYour prediction was correct.");
score++;
}
else if ((choice.equals("L") && (current.getValue() < value)))
{
System.out.print("\n\nYour prediction was correct.");
score++;
}
else if ((choice.equals("H") && (current.getValue() < value)))
{
System.out.print("\n\nYour prediction was incorrect.");
check = false;
}
else if ((choice.equals("L") && (current.getValue() > value)))
{
System.out.print("\n\nYour prediction was incorrect.");
check = false;
}
else
{
System.out.print("\n\nThe card value is the same. Sorry, you lose!");
check = false;
}
}
System.out.print("\n\nGame over! You made "+score+" correct predictions.");
if (highscore < score)
{
System.out.print("\n\nCongratulations! You beat the previous high score of "+highscore+" correct guesses!");
highscore = score;
}
System.out.print("\n\nWould you like to play again? (Y / N): ");
ok = reader.readLine();
ok = capitalize(ok);
PrintWriter outFile = new PrintWriter(new FileWriter("Hi-Score.txt"));
outFile.print(highscore);
inFile.close();
outFile.close();
}
}
}