public Engine(Snake snake, IDrawManager drawManager, Coordinate boardCoordinate) { Snake = snake; DrawManager = drawManager; BoardCoordinate = boardCoordinate; InitializeBoard(); Food = FoodFactory.Create(); Score = 0; }
public void Run() { while (true) { if (Console.KeyAvailable) { ChangeSnakeDirection(Console.ReadKey()); } DrawManager.Draw(Food.Symbol, new List <Coordinate>() { Food.Position }); DrawManager.Draw(Snake.Symbol, Snake.Body); PlayerInfo(); Snake.Move(); DrawManager.UndoDraw(); if (SnakeHasCollisionWithFood()) { Snake.Eat(Food); Score += Food.Points; Food = FoodFactory.Create(); } if (SnakeHasCollisionWithBorder() || SnakeHasCollisionWithHerself()) { AskPlayerForRestart(); } if (Snake.Direction == Direction.Left || Snake.Direction == Direction.Right) { Thread.Sleep(GameConstants.Engine.ThreadSleepTimeHorizontalMovement); } else { Thread.Sleep(GameConstants.Engine.ThreadSleepTimeVerticalMovement); } } }