-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·102 lines (93 loc) · 3.25 KB
/
Program.cs
File metadata and controls
executable file
·102 lines (93 loc) · 3.25 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
using System;
namespace Blackjack
{
public class Program
{
public static void Main(string[] args)
{
Deck myDeck = new Deck();
// Console.WriteLine(myDeck);
myDeck.shuffle();
Player player1 = new Player("Joe");
Player dealer = new Player("dealer");
// Console.WriteLine(player1.name);
// Console.WriteLine(dealer.name);
// Console.WriteLine(myDeck);
player1.Hit(myDeck);
player1.Hit(myDeck);
dealer.Hit(myDeck);
dealer.Hit(myDeck);
// Console.WriteLine(player1.hand);
int player_total = 0;
int dealer_total = 0;
Console.WriteLine("Player Cards: ");
foreach (var card in player1.hand)
{
Console.Write(card.val + ", ");
player_total += card.numVal;
}
foreach (var card in dealer.hand)
{
dealer_total += card.numVal;
}
while(player_total < 21)
{
Console.WriteLine("player your current total is: " + player_total);
Console.WriteLine("Would you like to hit or stay?");
string response = Console.ReadLine();
if (response == "hit")
{
player1.Hit(myDeck);
player_total = 0;
foreach (var card in player1.hand)
{
player_total += card.numVal;
}
}
else
{
break;
}
}
if(player_total > 21)
{
Console.WriteLine("Player total: " + player_total);
Console.WriteLine("Player BUSTED");
return;
}
while (dealer_total < 15)
{
dealer.Hit(myDeck);
dealer_total = 0;
foreach(var card in dealer.hand)
{
dealer_total += card.numVal;
}
}
if (dealer_total > 21)
{
Console.WriteLine("Dealer busts, you win!");
Console.WriteLine("Player total: " + player_total);
Console.WriteLine("Dealer total: " + dealer_total);
}
else if (dealer_total > player_total)
{
Console.WriteLine("Dealer is winner!");
Console.WriteLine("Player total: " + player_total);
Console.WriteLine("Dealer total: " + dealer_total);
}
else if (player_total > dealer_total)
{
Console.WriteLine("Player is winner!");
Console.WriteLine("Player total: " + player_total);
Console.WriteLine("Dealer total: " + dealer_total);
}
else
{
Console.WriteLine("draw");
Console.WriteLine("Player total: " + player_total);
Console.WriteLine("Dealer total: " + dealer_total);
}
}
}
}