-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
75 lines (60 loc) · 2.36 KB
/
Program.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
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
using System;
namespace BlackJack
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Let's play Blackjack!");
var deck = new Deck();
Dealer dealer = new Dealer(deck);
Console.WriteLine("What's your name?");
string name = Console.ReadLine();
Player player = new Player(name);
dealer.Deal(player, 2);
Console.WriteLine($"The Dealer's second card is: {dealer.RevealSecondCard()}");
Console.WriteLine($"Your hand is:\n{player.Hand}");
Console.WriteLine($"Combined total of: {player.Hand.CalculateValue()}");
if(player.Hand.CalculateValue() == 21) {
Console.WriteLine("Blackjack!!!");
return;
}
Console.WriteLine($"Hit or stand?");
string choice = Console.ReadLine();
while (choice == "hit")
{
dealer.Deal(player, 1);
Console.WriteLine($"Your new hand is:\n{player.Hand}");
Console.WriteLine($"So a total of: {player.Hand.CalculateValue()}\n");
if (player.Hand.CalculateValue() > 21)
{
Console.WriteLine("You lose!");
return;
}
Console.WriteLine("Hit or stand?");
choice = Console.ReadLine();
}
Console.WriteLine($"Dealer's hand is:\n{dealer.Hand.ToString()}");
Console.WriteLine($"So a total of: {dealer.Hand.CalculateValue()}\n");
while (dealer.Hand.CalculateValue() < 17)
{
Console.WriteLine("Dealer hits...");
dealer.Deal(dealer, 1);
Console.WriteLine($"Dealer's hand is:\n{dealer.Hand.ToString()}");
Console.WriteLine($"So a total of: {dealer.Hand.CalculateValue()}\n");
if (dealer.Hand.CalculateValue() > 21)
{
Console.WriteLine("Dealer busts! You win!");
return;
}
}
if (dealer.Hand.CalculateValue() < player.Hand.CalculateValue())
{
Console.WriteLine("You win!");
} else
{
Console.WriteLine("You lose!");
}
}
}
}