public void Start() { this.isStarted = true; Position movementPosition = new Position(0, 0); while (isStarted) { BoundariesChecker.CheckPosition(this.Snake.SnakeBody.Head.Value, movementPosition); this.Snake.Move(movementPosition); if (this.Snake.CheckSelfCanibalism()) { Console.Clear(); ConsoleHelper.Write(new Position(0, 0), $"Gmae Over! Your total score is {this.Snake.SnakeBody.Count}"); this.isStarted = false; break; } if (Console.KeyAvailable) { var key = Console.ReadKey(false).Key; movementPosition = ReadUserInput.GetMovement(key, movementPosition); } Thread.Sleep(50); this.gameItems.ForEach(x => x.Draw()); } }
public void Grow(Position position) { var reverse = new Position(position.X * -1, position.Y * -1); var oldPosition = this.SnakeBody.Tail.Value; var newHead = new Position(oldPosition.X, oldPosition.Y); newHead.ChangePosition(reverse); BoundariesChecker.CheckPosition(newHead, reverse); this.SnakeBody.AddLast(newHead); }