Skip to content

Commit

Permalink
Added 60% keyboards support (eg. Razer Huntsman Mini), fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zabszk committed Oct 3, 2020
1 parent 15f135c commit 2ac1c82
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 61 deletions.
176 changes: 125 additions & 51 deletions Chroma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ private static async void MainLoop()

case Snake.GameState.Paused:
blinkState = !blinkState;
_grid[Key.Pause] = blinkState ? Color.Green : Color.Black;
_grid[Snake.Is60Percent ? Key.OemPeriod: Key.Pause] = blinkState ? Color.Green : Color.Black;
await ShowBoard();
await Task.Delay(250);
break;

case Snake.GameState.Finished:
blinkState = !blinkState;
_grid[Key.Escape] = blinkState ? Color.White : Color.Black;
_grid[Key.End] = blinkState ? Color.Green : Color.Black;
_grid[Snake.Is60Percent ? Key.OemTilde : Key.Escape] = blinkState ? Color.White : Color.Black;
_grid[Snake.Is60Percent ? Key.OemApostrophe : Key.End] = blinkState ? Color.Green : Color.Black;
await ShowBoard(finishReset);
finishReset = false;
await Task.Delay(250);
Expand All @@ -102,6 +102,14 @@ internal static async Task ShowBoard(bool reset = false)

switch (Snake.State)
{
case Snake.GameState.SelectKeyboardSize when reset:
_grid[Key.D6] = Color.Green;
_grid[Key.R] = Color.Green;
MainForm.Instance.statusLabel.Text =
// ReSharper disable once LocalizableElement
"Please select keyboard size.\r\nR - Regular or TE/TKL\r\n6 - 60%";
break;

case Snake.GameState.SelectMode:
switch (Snake.Speed)
{
Expand Down Expand Up @@ -148,7 +156,7 @@ internal static async Task ShowBoard(bool reset = false)

if (reset)
{
_grid[Key.Escape] = Color.White;
_grid[Snake.Is60Percent ? Key.OemTilde : Key.Escape] = Color.White;
_grid[Key.Enter] = Color.Green;
MainForm.Instance.statusLabel.Text =
@"Please select speed using numeric keys (1-5) and press ENTER.";
Expand All @@ -161,7 +169,7 @@ internal static async Task ShowBoard(bool reset = false)
ShowSnakeBoard();

MainForm.Instance.statusLabel.Text =
$@"Game will begin in {Snake.Countdown} seconds.";
$@"Game will begin in {Snake.Countdown} second{(Snake.Countdown == 1 ? "" : "s")}.";

if (Snake.Countdown > 2f)
{
Expand All @@ -184,34 +192,32 @@ internal static async Task ShowBoard(bool reset = false)

if (reset)
{
_grid[Key.Up] = DarkGold;
_grid[Key.Down] = DarkGold;
_grid[Key.Left] = DarkGold;
_grid[Key.Right] = DarkGold;
if (Snake.Is60Percent)
{
_grid[Key.I] = DarkGold;
_grid[Key.J] = DarkGold;
_grid[Key.K] = DarkGold;
_grid[Key.L] = DarkGold;

_grid[Key.OemApostrophe] = Color.Black;
_grid[Key.OemPeriod] = Color.Black;
}
else
{
_grid[Key.Up] = DarkGold;
_grid[Key.Down] = DarkGold;
_grid[Key.Left] = DarkGold;
_grid[Key.Right] = DarkGold;

_grid[Key.End] = Color.Black;
_grid[Key.Pause] = Color.Black;
_grid[Key.End] = Color.Black;
_grid[Key.Pause] = Color.Black;
}
}
break;

case Snake.GameState.InProgress:
ShowSnakeBoard();

if (reset)
{
_grid[Key.F12] = Color.White;
_grid[Key.F11] = Color.White;
_grid[Key.F10] = Color.White;
_grid[Key.F9] = Color.White;
_grid[Key.F8] = Color.White;
_grid[Key.F7] = Color.White;
_grid[Key.F6] = Color.White;
_grid[Key.F5] = Color.White;
_grid[Key.F4] = Color.White;
_grid[Key.F3] = Color.White;
_grid[Key.F2] = Color.White;
_grid[Key.F1] = Color.White;
_grid[Key.Escape] = Color.White;
_grid[Key.LeftControl] = Color.White;
_grid[Key.LeftWindows] = Color.White;
_grid[Key.LeftAlt] = Color.White;
Expand All @@ -220,32 +226,87 @@ internal static async Task ShowBoard(bool reset = false)
_grid[Key.Function] = Color.White;
_grid[Key.RightMenu] = Color.White;
_grid[Key.RightControl] = Color.White;

if (!Snake.Is60Percent)
{
_grid[Key.F12] = Color.White;
_grid[Key.F11] = Color.White;
_grid[Key.F10] = Color.White;
_grid[Key.F9] = Color.White;
_grid[Key.F8] = Color.White;
_grid[Key.F7] = Color.White;
_grid[Key.F6] = Color.White;
_grid[Key.F5] = Color.White;
_grid[Key.F4] = Color.White;
_grid[Key.F3] = Color.White;
_grid[Key.F2] = Color.White;
_grid[Key.F1] = Color.White;

_grid[Key.Up] = Gold;
_grid[Key.Down] = Gold;
_grid[Key.Left] = Gold;
_grid[Key.Right] = Gold;

_grid[Key.Up] = Gold;
_grid[Key.Down] = Gold;
_grid[Key.Left] = Gold;
_grid[Key.Right] = Gold;

_grid[Key.End] = DarkGreen;
_grid[Key.Pause] = DarkGreen;

_grid[Key.End] = DarkGreen;
_grid[Key.Pause] = DarkGreen;

_grid[Key.Escape] = Color.White;
}
else _grid[Key.OemTilde] = Color.White;

MainForm.Instance.statusLabel.Text =
@"Game is in progress.";
}

ShowSnakeBoard();

if (Snake.Is60Percent)
{
if (_grid[Key.I] == Color.Black)
_grid[Key.I] = Gold;

if (_grid[Key.J] == Color.Black)
_grid[Key.J] = Gold;

if (_grid[Key.K] == Color.Black)
_grid[Key.K] = Gold;

if (_grid[Key.L] == Color.Black)
_grid[Key.L] = Gold;

if (_grid[Key.OemApostrophe] == Color.Black)
_grid[Key.OemApostrophe] = DarkGreen;

if (_grid[Key.OemPeriod] == Color.Black)
_grid[Key.OemPeriod] = DarkGreen;
}
break;

case Snake.GameState.Paused:
if (reset)
{
ShowSnakeBoard();

_grid[Key.Up] = DarkGold;
_grid[Key.Down] = DarkGold;
_grid[Key.Left] = DarkGold;
_grid[Key.Right] = DarkGold;
if (Snake.Is60Percent)
{
_grid[Key.I] = Gold;
_grid[Key.J] = Gold;
_grid[Key.K] = Gold;
_grid[Key.L] = Gold;

_grid[Key.End] = DarkGreen;
_grid[Key.Pause] = Color.Green;
_grid[Key.OemApostrophe] = DarkGreen;
_grid[Key.OemPeriod] = Color.Green;
}
else
{
_grid[Key.Up] = DarkGold;
_grid[Key.Down] = DarkGold;
_grid[Key.Left] = DarkGold;
_grid[Key.Right] = DarkGold;

_grid[Key.End] = DarkGreen;
_grid[Key.Pause] = Color.Green;
}

ShowSnakeBoard();

MainForm.Instance.statusLabel.Text =
@"Game paused. Press PAUSE key to unpause.";
Expand All @@ -255,19 +316,32 @@ internal static async Task ShowBoard(bool reset = false)
case Snake.GameState.Finished:
if (reset)
{
_grid[Key.Up] = Color.Black;
_grid[Key.Down] = Color.Black;
_grid[Key.Left] = Color.Black;
_grid[Key.Right] = Color.Black;

_grid[Key.Escape] = Color.White;
_grid[Key.End] = Color.Green;
_grid[Key.Pause] = Color.Black;
if (Snake.Is60Percent)
{
_grid[Key.I] = Color.Black;
_grid[Key.J] = Color.Black;
_grid[Key.K] = Color.Black;
_grid[Key.L] = Color.Black;

_grid[Key.OemApostrophe] = Color.Green;
_grid[Key.OemPeriod] = Color.Black;
_grid[Key.OemTilde] = Color.White;
}
else
{
_grid[Key.Up] = Color.Black;
_grid[Key.Down] = Color.Black;
_grid[Key.Left] = Color.Black;
_grid[Key.Right] = Color.Black;

_grid[Key.End] = Color.Green;
_grid[Key.Pause] = Color.Black;
_grid[Key.Escape] = Color.White;
}

MainForm.Instance.statusLabel.Text =
@"Game over. Press END key to restart.";
}

break;
}

Expand Down
24 changes: 19 additions & 5 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,41 @@ private async void Form1_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
if (!_ready) return;

switch (e.KeyCode)
{
case Keys.Up:
case Keys.I:
Snake.Dir = Snake.Direction.Up;
break;

case Keys.Down:
case Keys.K:
Snake.Dir = Snake.Direction.Down;
break;

case Keys.Left:
case Keys.J:
Snake.Dir = Snake.Direction.Left;
break;

case Keys.Right:
case Keys.L:
Snake.Dir = Snake.Direction.Right;
break;

case Keys.R when Snake.State == Snake.GameState.SelectKeyboardSize:
Snake.Is60Percent = false;
Snake.State = Snake.GameState.SelectMode;
await Chroma.ShowBoard(true);
break;

case Keys.D6 when Snake.State == Snake.GameState.SelectKeyboardSize:
Snake.Is60Percent = true;
Snake.State = Snake.GameState.SelectMode;
await Chroma.ShowBoard(true);
break;

case Keys.Escape when Snake.State == Snake.GameState.SelectMode || Snake.State == Snake.GameState.Finished:
Environment.Exit(0);
break;
Expand Down Expand Up @@ -87,26 +103,31 @@ private async void Form1_KeyDown(object sender, KeyEventArgs e)
break;

case Keys.Pause when Snake.State == Snake.GameState.InProgress:
case Keys.OemPeriod when Snake.State == Snake.GameState.InProgress:
Snake.State = Snake.GameState.Paused;
await Chroma.ShowBoard(true);
break;

case Keys.Pause when Snake.State == Snake.GameState.Paused:
case Keys.OemPeriod when Snake.State == Snake.GameState.Paused:
Snake.Countdown = 3;
Snake.State = Snake.GameState.Countdown;
await Chroma.ShowBoard(true);
break;

case Keys.End when Snake.State == Snake.GameState.InProgress || Snake.State ==Snake.GameState.Paused || Snake.State ==Snake.GameState.Finished:
case Keys.Oem7 when Snake.State == Snake.GameState.InProgress || Snake.State ==Snake.GameState.Paused || Snake.State ==Snake.GameState.Finished:
Snake.State = Snake.GameState.SelectMode;
await Chroma.ShowBoard(true);
break;

case Keys.Insert when Snake.State == Snake.GameState.SelectMode && _testSequence < 2:
case Keys.OemQuestion when Snake.State == Snake.GameState.SelectMode && _testSequence < 2:
_testSequence++;
break;

case Keys.Home when _testSequence == 2:
case Keys.Oem6 when _testSequence == 2:
Testing = true;
await Chroma.MapTest();
Testing = false;
Expand Down
Loading

0 comments on commit 2ac1c82

Please sign in to comment.