aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications/Snakey.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-02-28 15:18:11 -0500
committerMichael <[email protected]>2017-02-28 15:18:11 -0500
commit998f3357a77661cdd85aa1f419bed5054aa21ede (patch)
treebc0fc89653f911c85bd35d1ab78e81950a65aa63 /ShiftOS.WinForms/Applications/Snakey.cs
parentdd95bc225f332c3c8ad23db55b3600b75e9511f1 (diff)
downloadshiftos_thereturn-998f3357a77661cdd85aa1f419bed5054aa21ede.tar.gz
shiftos_thereturn-998f3357a77661cdd85aa1f419bed5054aa21ede.tar.bz2
shiftos_thereturn-998f3357a77661cdd85aa1f419bed5054aa21ede.zip
fix Snakey NRE
Diffstat (limited to 'ShiftOS.WinForms/Applications/Snakey.cs')
-rw-r--r--ShiftOS.WinForms/Applications/Snakey.cs21
1 files changed, 11 insertions, 10 deletions
diff --git a/ShiftOS.WinForms/Applications/Snakey.cs b/ShiftOS.WinForms/Applications/Snakey.cs
index 2f01b88..2e437b5 100644
--- a/ShiftOS.WinForms/Applications/Snakey.cs
+++ b/ShiftOS.WinForms/Applications/Snakey.cs
@@ -40,9 +40,10 @@ namespace ShiftOS.WinForms.Applications
for (int x = 0; x < 10; x++)
{
- if (head != null) break;
+ if (head != null) continue;
for (int y = 0; y < 10; y++)
{
+ if (head != null) continue;
if (snakemap[x, y] == 2)
{
head = tableLayoutPanel1.GetControlFromPosition(x, y);
@@ -51,8 +52,6 @@ namespace ShiftOS.WinForms.Applications
}
}
- if (head == null) return;
-
int headX = int.Parse(head.Name.Split('b')[1]); // NRE was here
int headY = int.Parse(head.Name.Split('b')[2]);
@@ -86,7 +85,7 @@ namespace ShiftOS.WinForms.Applications
break;
}
- if (newHeadX > 9 | newHeadX < 0 | newHeadY > 9 | newHeadY < 0) return;
+ if (newHeadX > 9 || newHeadX < 0 || newHeadY > 9 || newHeadY < 0) return;
snakemap[newHeadX, newHeadY] = 2;
tableLayoutPanel1.GetControlFromPosition(newHeadX, newHeadY).BackgroundImage = headImg;
snakemap[headX, headY] = 1;
@@ -97,23 +96,23 @@ namespace ShiftOS.WinForms.Applications
}
}
- private void OnKeyPress(object sender, KeyPressEventArgs e)
+ private void OnKeyPress(object sender, PreviewKeyDownEventArgs e)
{
- switch (e.KeyChar)
+ switch (e.KeyCode)
{
- case (char)Keys.Up:
+ case Keys.Up:
snakedirection = 3;
break;
- case (char)Keys.Down:
+ case Keys.Down:
snakedirection = 1;
break;
- case (char)Keys.Left:
+ case Keys.Left:
snakedirection = 0;
break;
- case (char)Keys.Right:
+ case Keys.Right:
snakedirection = 2;
break;
@@ -205,5 +204,7 @@ namespace ShiftOS.WinForms.Applications
return -1;
}
+
+
}
}