-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCounting.cs
58 lines (48 loc) · 1.16 KB
/
Counting.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
namespace WingTechBot;
using System.Diagnostics;
public class Counting : Game
{
private int _countBy;
private bool _turnOrder;
private int _currentPlayerIndex = 0;
protected override bool Debug => false;
protected override void Start()
{
_countBy = Prompt<int>(GamemasterID, AllowedChannels, true, "What are we gonna count by?");
_turnOrder = Prompt<bool>(GamemasterID, AllowedChannels, true, "Is turn order required? (true/false)");
}
public override void RunGame()
{
if (PlayerIDs.Count == 0)
{
WriteLine("You can't count with zero players!");
return;
}
Stopwatch timer = new();
var score = 0;
WriteLine($"Alright, start counting by {_countBy}'s!");
timer.Start();
while (true)
{
(var id, var guess) = PromptAny<int>(PromptMode.Any, true);
if ((!_turnOrder || PlayerIDs[_currentPlayerIndex] == id) && guess == ++score * _countBy)
{
Advance();
}
else
{
timer.Stop();
break;
}
}
WriteLine($"Gameover! Score: {score - 1}; Time: {timer.Elapsed} seconds");
}
private void Advance()
{
_currentPlayerIndex++;
if (_currentPlayerIndex >= PlayerIDs.Count)
{
_currentPlayerIndex = 0;
}
}
}