private static bool Update() { _snake.Direction = _input.GetNewDirection(); var oldTail = _snake.Tail; _snake.Move(); if (_snake.GetBody().Skip(1).Any(n => Equals(n, _snake.Head))) { return(true); } if (!_area.AllFields.Contains((_snake.Head.X, _snake.Head.Y))) { return(true); } if (IsPositionEqual(_snake.Head, _food)) { _area.Score++; _area.PrintScore(); _snake.Grow(oldTail); _food.SpawnNew(_area, _snake); _renderer.Redraw(_snake.Head); } else { _renderer.Redraw(_snake.Head, oldTail); } _renderer.Draw(_food); return(false); }
public void GameEvent(int Width, int Height) //Event for one Timer Tick { int PositionX = 0; int PositionY = 0; bool Collision = false; if (Direction == 1) { PositionX = 10; } else if (Direction == 3) { PositionY = 10; } else if (Direction == 2) { PositionX = -10; } else if (Direction == 4) { PositionY = -10; } Body.Move(_Target, PositionX, PositionY); //Determines where draw next square Collision = Body.Collision(); //Checks Collision terms if (Body.Eat(ref Food, Target, PositionX, PositionY) == true) { _Score += 100; IncreaseSpeed(); } ; //If Snake will meet Food square GameEnd(Width, Height, Collision); //Check Game Over conditions }