yo the snake is movin
This commit is contained in:
parent
998f3357a7
commit
8d8fc4931d
2 changed files with 19 additions and 11 deletions
6
ShiftOS.WinForms/Applications/Snakey.Designer.cs
generated
6
ShiftOS.WinForms/Applications/Snakey.Designer.cs
generated
|
@ -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();
|
||||
|
||||
|
|
|
@ -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() { }
|
||||
|
||||
|
|
Reference in a new issue