-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevolverMock.cs
More file actions
38 lines (34 loc) · 1.07 KB
/
RevolverMock.cs
File metadata and controls
38 lines (34 loc) · 1.07 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
namespace TJC.StateMachine.Tests.Mocks
{
internal class RevolverMock() : StateMachineBase<RevolverStates>(RevolverStates.Loaded)
{
public int BulletsLoaded { get; private set; } = 6;
internal uint StateChanges = 0;
public bool TryShoot()
{
switch (State)
{
case RevolverStates.Empty:
return false;
case RevolverStates.Loaded:
BulletsLoaded--;
if (BulletsLoaded == 0)
State = RevolverStates.Empty;
return true;
default:
throw new InvalidOperationException(
$"Unknown State [{State}] for method {nameof(TryShoot)}"
);
}
}
public void Reload()
{
BulletsLoaded = 6;
State = RevolverStates.Loaded;
}
protected override void OnStateChanged()
{
StateChanges++;
}
}
}