public void MovePlayer(MoveDirection direction) { int x = 0; int y = 0; switch (direction) { case MoveDirection.Up: x = 0; y = moveSpeedY*-1; break; case MoveDirection.Left: x = moveSpeedX*-1; y = 0; break; case MoveDirection.Down: x = 0; y = moveSpeedY; break; case MoveDirection.Right: x = moveSpeedX; y = 0; break; } snakePanels[0].Me.Location = new Point(snakePanels[0].Me.Location.X + x, snakePanels[0].Me.Location.Y + y); for (int i = snakePanels.Count - 1; i > 0; --i) { snakePanels[i].Me.Location = new Point(snakePanels[i - 1].Me.Location.X, snakePanels[i - 1].Me.Location.Y); } }
public Snake() { Random rnd = new Random(); Direction dir = (Direction)rnd.Next(0, 3); var StartPos = new Position() { X = 40, Y = 12 }; //Center of the screen MoveDirection = new MoveDirection() { Direction = dir}; Blocks = new List<Snake.SnakeBlock>() { new SnakeBlock() { IsHead = true, Symbol = "#", Position = StartPos, Type = ObjectType.Player }, new SnakeBlock() { IsHead = false, Symbol = "#", Position = StartPos + dir.NextPos(1), Type = ObjectType.Player}, new SnakeBlock() { IsHead = false, Symbol = "#", Position = StartPos + dir.NextPos(2), Type = ObjectType.Player} }; Blocks[1].Parent = Blocks.First(); //ugh, hack to wire parents :( Blocks[2].Parent = Blocks.First(); }