/
VideoPoker.cs
192 lines (165 loc) · 6.7 KB
/
VideoPoker.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Collections.Generic;
namespace CardGame
{
class VideoPoker
{
static void Main(string[] args)
{
string input ="";
char[] delimiterChars = {' ',',','.',':','\t'};
int points = 0;
int pointDifference = 0;
int cardCounter = -1;
bool gameIsOn = true;
bool won = false;
bool winMessage = false;
string playerDesicion;
var deck = new Deck();
deck.Shuffle();
List<Card> playerCards = new List<Card>();
JacksOrBetter VideoPokerGame = new JacksOrBetter();
while (gameIsOn)
{
pointDifference = points;
Console.WriteLine("The players hand:\n");
for (int i = 0; i < 5; i++)
{
playerCards.Add(deck.GetCard());
Console.WriteLine($"{i + 1}:Card {playerCards[i].DisplayName}, {playerCards[i].Suit}, {playerCards[i].Value}");
}
Console.WriteLine("\nChoose which cards to discards: \nexample 1,5 (discards first and fifth cards from hand)\n");
input = Console.ReadLine();
Console.WriteLine();
string[] discardCards = input.Split(delimiterChars);
//put discarded cards back to deck
foreach (var card in discardCards)
{
deck.PutCard(playerCards[Int32.Parse(card) + cardCounter]);
playerCards.RemoveAt(Int32.Parse(card) + cardCounter);
cardCounter += -1;
}
//draw new cards
for (int i = 0; discardCards.Length > i; i++)
{
deck.Shuffle();
playerCards.Add(deck.GetCard());
}
Console.WriteLine("\nPlayers new hand:\n");
for (int i = 0; i < playerCards.Count; i++)
{
Console.WriteLine($"{i + 1}:Card {playerCards[i].DisplayName}, {playerCards[i].Suit}, {playerCards[i].Value}");
}
//Checking winning conditions
points += VideoPokerGame.RoyalFlush(playerCards);
won = CheckPointDifference(pointDifference, points);
if (won)
{
winMessage = true;
Console.WriteLine("You won a RoyalFlush !!!");
}
if (!won)
{
points += VideoPokerGame.StraightFlush(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a StraightFlush !!!");
}
if (!won)
{
points += VideoPokerGame.FourOfAKind(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a Four Of A Kind !!!");
}
if (!won)
{
points += VideoPokerGame.FullHouse(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a FullHouse !!!");
}
if (!won)
{
points += VideoPokerGame.Flush(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a Flush !!!");
}
if (!won)
{
points += VideoPokerGame.Straight(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a Straight !!!");
}
if (!won)
{
points += VideoPokerGame.ThreeOfAKind(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a Three Of A Kind !!!");
}
if (!won)
{
points += VideoPokerGame.TwoPair(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a Two Pair !!!");
}
if (!won)
{
points += VideoPokerGame.OnePairOfJacksOrBetter(playerCards);
won = CheckPointDifference(pointDifference, points);
}
if (won && !winMessage)
{
winMessage = true;
Console.WriteLine("You won a One Pair Of Jacks Or Better !!!");
}
Console.WriteLine($"\nCurrent player points: {points}");
Console.WriteLine("Want to play the game again y/n");
playerDesicion = Console.ReadLine();
if (playerDesicion == "n") gameIsOn = false;
else {
//put discarded cards back to deck for a new game
for (int i=0; i < playerCards.Count; i++)
{
deck.PutCard(playerCards[i]);
}
deck.Shuffle();
playerCards.Clear();
cardCounter = -1;
}
Console.Clear();
}
}
static bool CheckPointDifference (int currentPoints, int pointsAfterWinningCheck)
{
bool difference = false;
if (pointsAfterWinningCheck - currentPoints > 0) difference = true;
return difference;
}
}
}