Skip to content

Commit 7e15200

Browse files
committed
[Kanban 43] add a random navigator
1 parent 06f9774 commit 7e15200

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

Source/VisualPairCoding/VisualPairCoding.WinForms/RunSessionForm.Designer.cs

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/VisualPairCoding/VisualPairCoding.WinForms/RunSessionForm.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ public partial class RunSessionForm : Form
77
private readonly PairCodingSession _pairCodingSession;
88
private TimeSpan _currentTime = TimeSpan.Zero;
99
private int _currentParticipant = -1;
10+
private Random random = new Random();
1011

1112
public RunSessionForm()
1213
{
1314
InitializeComponent();
15+
_pairCodingSession = new PairCodingSession(Array.Empty<string>(), 1);
1416
}
1517

1618
public RunSessionForm(PairCodingSession pairCodingSession)
@@ -29,22 +31,39 @@ private void timer_Tick(object sender, EventArgs e)
2931
{
3032
if (_currentTime <= TimeSpan.Zero)
3133
{
32-
_currentParticipant += 1;
33-
if (_currentParticipant >= _pairCodingSession.Participants.Length)
34-
{
35-
_currentParticipant = 0;
36-
}
37-
38-
_currentTime = new TimeSpan(0, _pairCodingSession.MinutesPerTurn, 0);
39-
FlashCounter = 10;
40-
flashTimer.Start();
34+
ChooseAnotherPairAndStartNewTurn();
4135
}
4236

4337
_currentTime = _currentTime.Subtract(new TimeSpan(0, 0, 1));
4438
activeParticipantLabel.Text = _pairCodingSession.Participants[_currentParticipant];
39+
4540
remainingTimeLabel.Text = _currentTime.ToString();
4641
}
4742

43+
private void ChooseAnotherPairAndStartNewTurn()
44+
{
45+
_currentParticipant += 1;
46+
if (_currentParticipant >= _pairCodingSession.Participants.Length)
47+
{
48+
_currentParticipant = 0;
49+
}
50+
51+
ChooseRandomNavigatorFromListWithout(_pairCodingSession.Participants[_currentParticipant]);
52+
53+
_currentTime = new TimeSpan(0, _pairCodingSession.MinutesPerTurn, 0);
54+
FlashCounter = 10;
55+
flashTimer.Start();
56+
}
57+
58+
private void ChooseRandomNavigatorFromListWithout(string currentDriver)
59+
{
60+
var potentialNavigators =
61+
_pairCodingSession.Participants.Where( x => !(x == currentDriver)).ToArray();
62+
63+
var randomEntry = potentialNavigators[random.Next(0, potentialNavigators.Length)];
64+
recommendedNavigator.Text = randomEntry;
65+
}
66+
4867
private void PauseButton_Click(object sender, EventArgs e)
4968
{
5069
if (timer.Enabled)

0 commit comments

Comments
 (0)