-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractiveEntity.cs
More file actions
107 lines (92 loc) · 3.1 KB
/
InteractiveEntity.cs
File metadata and controls
107 lines (92 loc) · 3.1 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
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BlackjackSandbox
{
/// <summary>
/// A blackjack entity that prompts the user for actions
/// </summary>
public class InteractiveEntity : Entity
{
public InteractiveEntity(int startCash)
: base(startCash, "Player")
{
}
/// <summary>
/// Prompt the user for a bet
/// </summary>
/// <param name="count">The current count of the shoe</param>
/// <returns>The amount that this entity wishes to bet</returns>
public override int GetBet(int count)
{
int bet = 0;
while (true)
{
Console.Write("Please input your bet (the current count is {0}): ", count);
string input = Console.ReadLine();
if (int.TryParse(input, out bet))
{
break;
}
}
return bet;
}
/// <summary>
/// Prompt the user for an action
/// </summary>
/// <param name="hand">The user's current hand</param>
/// <param name="dealerHoleCard">The dealer's hole card</param>
/// <returns>The action that the user would like to perform</returns>
public override TurnAction TakeTurn(List<Card> hand, Card dealerHoleCard)
{
while (true)
{
Console.Write("Would you like to [S]tick, [H]it, [D]ouble or S[P]lit?: ");
switch (Console.ReadKey().KeyChar)
{
case 's':
case 'S':
Console.WriteLine();
return TurnAction.Stick;
case 'h':
case 'H':
Console.WriteLine();
return TurnAction.Hit;
case 'd':
case 'D':
Console.WriteLine();
return TurnAction.Double;
case 'p':
case 'P':
Console.WriteLine();
return TurnAction.Split;
default:
Console.WriteLine();
break;
}
}
}
/// <summary>
/// Prompts the user for the amount they would like to double down for
/// </summary>
/// <param name="hand">The user's current hand</param>
/// <param name="count">The current count of the shoe</param>
/// <returns></returns>
public override int GetDoubleDownBet(List<Card> hand, int count)
{
int bet = 0;
while (true)
{
Console.Write("Please input your double down bet: ");
string input = Console.ReadLine();
if (int.TryParse(input, out bet))
{
break;
}
Console.WriteLine();
}
return bet;
}
}
}