From 85ae3a820a9a41550c98d55cbaf95beb923d8746 Mon Sep 17 00:00:00 2001 From: lempamo Date: Tue, 28 Feb 2017 17:41:18 -0500 Subject: [PATCH] tail stuff --- ShiftOS.WinForms/Applications/Snakey.cs | 54 ++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/ShiftOS.WinForms/Applications/Snakey.cs b/ShiftOS.WinForms/Applications/Snakey.cs index 94dd671..17c7c85 100644 --- a/ShiftOS.WinForms/Applications/Snakey.cs +++ b/ShiftOS.WinForms/Applications/Snakey.cs @@ -38,6 +38,7 @@ namespace ShiftOS.WinForms.Applications private void updateSnake(object sender, EventArgs e) { PictureBox head = null; + PictureBox tail = null; for (int x = 0; x < 10; x++) { @@ -53,12 +54,32 @@ namespace ShiftOS.WinForms.Applications } } + for (int x = 0; x < 10; x++) + { + if (tail != null) break; + for (int y = 0; y < 10; y++) + { + if (tail != null) break; + if (snakemap[x, y] == 3) + { + tail = (PictureBox)tableLayoutPanel1.GetControlFromPosition(x, y); + break; + } + } + } + int headX = int.Parse(head.Name.Split('b')[1]); int headY = int.Parse(head.Name.Split('b')[2]); int newHeadX = headX; int newHeadY = headY; + int tailX = int.Parse(tail.Name.Split('b')[1]); + int tailY = int.Parse(tail.Name.Split('b')[2]); + + int newTailX = tailX; + int newTailY = tailY; + Image headImg = null; switch (snakedirection) { @@ -95,7 +116,33 @@ namespace ShiftOS.WinForms.Applications ((PictureBox)tableLayoutPanel1.GetControlFromPosition(headX, headY)).Image = Properties.Resources.SnakeyBody; if (!extending) { + Image tailImg = null; + switch (tailDirection()) + { + case 0: + newTailX = tailX - 1; + break; + case 1: + newTailY = tailY + 1; + break; + + case 2: + newTailX = tailX + 1; + break; + + case 3: + newTailY = tailY - 1; + break; + + default: + break; + } + switch (nextTailDirection(newTailX, newTailY)) + { + default: + break; + } } if (extending) extending = false; if (newheadlocation == 1) @@ -104,6 +151,11 @@ namespace ShiftOS.WinForms.Applications } } + private int nextTailDirection(int x, int y) + { + return -1; + } + private void gameover() { throw new NotImplementedException(); @@ -219,7 +271,7 @@ namespace ShiftOS.WinForms.Applications } } - private int getTailDirection() + private int tailDirection() { PictureBox tail = null;