From 8d8fc4931d0e603bb740b52c7f664de97061e24b Mon Sep 17 00:00:00 2001 From: lempamo Date: Tue, 28 Feb 2017 16:11:49 -0500 Subject: [PATCH] yo the snake is movin --- .../Applications/Snakey.Designer.cs | 6 +++-- ShiftOS.WinForms/Applications/Snakey.cs | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ShiftOS.WinForms/Applications/Snakey.Designer.cs b/ShiftOS.WinForms/Applications/Snakey.Designer.cs index 1b21792..d500a94 100644 --- a/ShiftOS.WinForms/Applications/Snakey.Designer.cs +++ b/ShiftOS.WinForms/Applications/Snakey.Designer.cs @@ -61,6 +61,7 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(260, 260); this.tableLayoutPanel1.TabIndex = 2; + this.tableLayoutPanel1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.OnKeyDown); // // button1 // @@ -71,6 +72,7 @@ this.button1.Text = "Play"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); + this.button1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.OnKeyDown); // // label1 // @@ -89,8 +91,8 @@ this.Controls.Add(this.button1); this.Controls.Add(this.tableLayoutPanel1); this.Name = "Snakey"; - this.Size = new System.Drawing.Size(317, 329); - this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.OnKeyPress); + this.Size = new System.Drawing.Size(306, 329); + this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.OnKeyDown); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ShiftOS.WinForms/Applications/Snakey.cs b/ShiftOS.WinForms/Applications/Snakey.cs index 2e437b5..560d2c0 100644 --- a/ShiftOS.WinForms/Applications/Snakey.cs +++ b/ShiftOS.WinForms/Applications/Snakey.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; +using System.Diagnostics; namespace ShiftOS.WinForms.Applications { @@ -36,23 +37,23 @@ namespace ShiftOS.WinForms.Applications private void updateSnake(object sender, EventArgs e) { - Control head = null; + PictureBox head = null; for (int x = 0; x < 10; x++) { - if (head != null) continue; + if (head != null) break; for (int y = 0; y < 10; y++) { - if (head != null) continue; + if (head != null) break; if (snakemap[x, y] == 2) { - head = tableLayoutPanel1.GetControlFromPosition(x, y); + head = (PictureBox)tableLayoutPanel1.GetControlFromPosition(x, y); break; } } } - int headX = int.Parse(head.Name.Split('b')[1]); // NRE was here + int headX = int.Parse(head.Name.Split('b')[1]); int headY = int.Parse(head.Name.Split('b')[2]); int newHeadX = headX; @@ -87,16 +88,16 @@ namespace ShiftOS.WinForms.Applications if (newHeadX > 9 || newHeadX < 0 || newHeadY > 9 || newHeadY < 0) return; snakemap[newHeadX, newHeadY] = 2; - tableLayoutPanel1.GetControlFromPosition(newHeadX, newHeadY).BackgroundImage = headImg; + ((PictureBox)tableLayoutPanel1.GetControlFromPosition(newHeadX, newHeadY)).Image = headImg; snakemap[headX, headY] = 1; - tableLayoutPanel1.GetControlFromPosition(headX, headY).BackgroundImage = Properties.Resources.SnakeyBody; + ((PictureBox)tableLayoutPanel1.GetControlFromPosition(headX, headY)).Image = Properties.Resources.SnakeyBody; if (!extending) { } } - private void OnKeyPress(object sender, PreviewKeyDownEventArgs e) + private void OnKeyDown(object sender, PreviewKeyDownEventArgs e) { switch (e.KeyCode) { @@ -119,6 +120,7 @@ namespace ShiftOS.WinForms.Applications default: break; } + Debug.Print("Snake Direction Value: " + snakedirection.ToString()); } private void makeGrid() @@ -145,7 +147,11 @@ namespace ShiftOS.WinForms.Applications public void OnSkinLoad() { } - public bool OnUnload() { return true; } + public bool OnUnload() + { + snakeupdater.Stop(); + return true; + } public void OnUpgrade() { }