/// <summary> /// Moves Snake to next position and redraws it in window /// Called every timer tick /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void TickHandler(object sender, EventArgs e) { if (!Snake.MoveSnake()) //if snake hits is tail { Timer.Stop(); MessageBox.Show("You lost"); CheckScore(); NewGame(); //this.Close(); } Snake.RedrawSnake(); }
/// <summary> /// Initiates Snake moved by player /// </summary> public void InitSnake() { Snake.grid = grid; Snake = new Snake(); Snake.GridXSize = (int)grid.Width / SQUARE_SIZE; Snake.GridYSize = (int)grid.Height / SQUARE_SIZE; grid.Children.Add(Snake.Head.Rect); foreach (var piece in Snake.Tail) { grid.Children.Add(piece.Rect); } Snake.RedrawSnake(); }