Exemplo n.º 1
0
        /// <summary>
        /// Базовый конструктор
        /// Base constructor
        /// </summary>
        /// <param name="snakeFactory">Производство змеек/Snakes factory</param>
        /// <param name="mapSideSize">Сторона карты/Map's edge</param>
        /// <param name="foodCount">Максимальное колличество еды/Max amount of food</param>
        public GameLogicBase(HashSet <GameLogicsAttributes.GameoverPredicates> gameoverPredicates,
                             ISnakeFactory snakeFactory, int mapSideSize, int foodCount, List <string> snakeNames, bool leftDeadSnakeBody = false,
                             GameLogicsAttributes.Barriers barriers = GameLogicsAttributes.Barriers.None)
        {
            BarriersType        = barriers;
            this.SnakeFactory   = snakeFactory;
            this.SnakesForLogic = new GameLogicsAttributes.SnakesForLogic();
            Map = new PlayingMap(mapSideSize, foodCount);
            LeftDeadSnakeBody = leftDeadSnakeBody;
            InitialGameoverPredicate(gameoverPredicates);

            if (snakeNames.Count == 0)
            {
                snakeNames.Add(nameof(PlayerArrows));
            }
            var snakesCordinates = GetInitialSnakesCordinates(mapSideSize, snakeNames.Count);

            for (int i = 0; i < snakeNames.Count; i++)
            {
                var snake = snakeFactory.GetSnakeByName(snakeNames[i], snakesCordinates[i]);
                snake.ID = i;
                SnakesForLogic.Snakes.Add(snake);
            }

            foreach (var snake in SnakesForLogic.Snakes)
            {
                Map.Snake.Add(new PlayingMapAttributes.Snake(snake.SnakeName, snake.SnakeBody, snake, snake.Statistics));
            }

            InsertBarriers(Map);
            InsertFood(Map);
        }
Exemplo n.º 2
0
        public SnakeBase AddSnake(string snakeName, List <Cordinates> cordinates)
        {
            foreach (var cord in cordinates)
            {
                if (CollisionWithOtherObject(cord, Map, LeftDeadSnakeBody))
                {
                    return(null);
                }
            }

            var snake = SnakeFactory.GetSnakeByName(snakeName, cordinates);

            snake.ID = SnakesForLogic.Snakes.Count;
            SnakesForLogic.Snakes.Add(snake);
            return(snake);
        }