/
Program.cs
65 lines (49 loc) · 1.91 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
using System;
namespace State
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Stock sellin' time!");
Console.WriteLine();
var money = 100m;
var stock = 0m;
// *** Initializing a player ***
// We start out in the uninitialized state
var player = new Player();
// Lets initialize a player
player.Start(money, stock);
Console.WriteLine();
// Lets try that again
player.Start(money, stock);
Console.WriteLine();
// Looks like that didn't work. Lets try buying!
// *** Buying! ***
// Let buy $50 worth
player.Buy(10, 5);
Console.WriteLine();
// We now have money and stock! Lets try buying more!
player.Buy(10, 5);
Console.WriteLine();
// We now have no money, but we have stock. Let's try to buy more to make sure!
player.Buy(100, 50);
Console.WriteLine();
// That didn't work--time to sell I guess!
// *** Selling ***
// Let's give selling a shot
player.Sell(5, 6);
Console.WriteLine();
// We now have money AND stock again! Let's sell the rest of it.
player.Sell(20, 13);
Console.WriteLine();
// We now have money and no stock. Let's try selling stock just in case...
player.Sell(500, 20);
Console.WriteLine();
// Nope, that doesn't work either!
// Hope this helps you guys get a feel for how the state pattern
// could work in your game to make rules around state transition
// easier to think about!
}
}
}