Exemple #1
0
        internal GameInstance(GridDescription gridDescription, Snake snake, ISnakeController controller, RandomFoodGenerator randomFoodGenerator)
        {
            this.gridDescription     = gridDescription;
            this.snake               = snake;
            this.controller          = controller;
            this.randomFoodGenerator = randomFoodGenerator;

            foodPosition         = GenerateFoodPosition();
            elapsedTimeSinceMove = 0;
            speed        = 10;
            IsSnakeAlive = true;
            Score        = 0;
        }
        private IReadOnlyList <GameInstance> CreateGameInstances()
        {
            var games = new List <GameInstance>(Controllers.Count);
            var seed  = rand.Next();

            const int initialX = ScreenWidth / (2 * GridSize);
            const int initialY = ScreenHeight / (2 * GridSize);

            foreach (var controller in Controllers)
            {
                var snake = Snake.Create(initialX, initialY, 3);
                var randomFoodGenerator = new RandomFoodGenerator(gridDescription, new Random(seed));
                games.Add(new GameInstance(gridDescription, snake, controller, randomFoodGenerator));
            }

            return(games);
        }