-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
39 lines (31 loc) · 1.04 KB
/
Game.cs
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
namespace cards;
internal class Game
{
private int _lastDraw = -1;
private int _currentDraw = -1;
private Deck _deck = new Deck();
private int _score = 0;
public void Play()
{
Console.WriteLine("Welcome to Hi-Lo!");
Console.WriteLine("When you reach the guessing phase, you can enter q to quit.");
while (true)
{
if (_lastDraw == -1)
{
_lastDraw = _deck.DrawCard();
}
string? response = null;
while (response != "h" && response != "l")
{
Console.WriteLine($"Will the next card be higher or lower than {_lastDraw} (h/l)? ");
response = Console.ReadLine();
if (response == "q") return;
}
_currentDraw = _deck.DrawCard();
_score += ((response == "h") == (_currentDraw > _lastDraw)) ? 75: -100;
Console.WriteLine($"You drew a {_currentDraw}! Score: {_score}");
_lastDraw = _currentDraw;
}
}
}