Beispiel #1
0
        private void MoveSnakes()
        {
            foreach (var snake in Snakes.ToArray())
            {
                if (snake.TurnsHasNotEaten == Params.SnakeTurnToDie)
                {
                    Snakes.Remove(snake);
                }

                if (snake.IsStarving)
                {
                    var isDead = snake.StarvingSnakeTurn();

                    if (isDead)
                    {
                        Snakes.Remove(snake);
                    }
                }
                else
                {
                    var headLocation = snake.HeadLocation;

                    snake.MoveSnake(GetRandomGrassCell(headLocation));
                }

                if (snake.ShouldSplit)
                {
                    Snakes.Add(snake.SplitSnake());
                }
            }
        }
Beispiel #2
0
        private bool SnakeBirth(SnakeItem snake)
        {
            // once 7 nodes is contained in our snake, it birth
            count += 1;
            bool found      = false;
            int  snakeValue = snake.SnakeValue;

            if (!Snakes.ContainsKey(snakeValue))
            {
                // created a new node into the dictionary if its value does not exist
                List <SnakeItem> snakesSameValue = new List <SnakeItem>()
                {
                    snake
                };
                Snakes.Add(snakeValue, snakesSameValue);
            }
            else
            {
                // if the same value were found, a new snake is add to a list of the same value
                foreach (var item in Snakes[snakeValue])
                {
                    if (!snake.Equals(item))
                    {
                        // comparing all snakes with same value,
                        // found if each node from a snake differs from the other
                        SnakesFound = new List <SnakeItem>();
                        SnakesFound.Add(snake);
                        SnakesFound.Add(item);
                        return(true);
                    }
                }
                Snakes[snake.SnakeValue].Add(snake);
            }
            return(found);
        }
Beispiel #3
0
        public void AddPlayerSnake()
        {
            Snake newPlayerSnake = GetRandomSnake();

            Snakes.Add(newPlayerSnake);
            PlayerSnake = newPlayerSnake;
        }
Beispiel #4
0
        public void AddPlayerSnake(int x, int y, Direction direction, Color headColor, Color bodyColor)
        {
            Snake newPlayerSnake = new Snake(x, y, direction, headColor, bodyColor);

            Snakes.Add(newPlayerSnake);
            PlayerSnake = newPlayerSnake;
        }
Beispiel #5
0
        public void AddSnake()
        {
            var snake = new Snake(Params);

            var grassCells = GrassBoard.GrassCells[0];

            snake.Locations.Enqueue(grassCells[0]);
            snake.Locations.Enqueue(grassCells[1]);
            snake.Locations.Enqueue(grassCells[2]);
            snake.HeadLocation = grassCells[2];

            Snakes.Add(snake);
        }
    /// <summary>
    /// Register the snake in the Snakes list
    /// </summary>
    /// <param name="snake"></param>
    /// <returns></returns>
    public static bool RegisterSnakeScript(Snake snake)
    {
        if (Snakes == null)
        {
            Snakes = new List <Snake>(4);
        }

        if (snake == null || Snakes.Contains(snake))
        {
            return(false);
        }

        Snakes.Add(snake);

        Snakes = Snakes.OrderBy(s => s.GetActorIDOfCreator()).ToList();

        return(true);
    }
        private void SetSnakesOnGame(List <List <int> > snakeIndices)
        {
            foreach (var snakeIndex in snakeIndices)
            {
                if (Snakes.Any(x => x.Head == snakeIndex[0]))
                {
                    //Skipping two snake heads at same point
                    continue;
                }

                var snake = new Snake()
                {
                    Head = snakeIndex[0],
                    Tail = snakeIndex[1]
                };
                Snakes.Add(snake);
            }
        }
Beispiel #8
0
        // Objects
        public void RegisterObject(Entity o)
        {
            objects.Add(o);
            if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Foliage)) || o.GetType() == typeof(Foliage))
            {
                foliage.Add((Foliage)o);
            }
            else if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Actor)) || o.GetType() == typeof(Actor))
            {
                actors.Add((Actor)o);
            }

            if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(ShopKeeper)) || o.GetType() == typeof(ShopKeeper))
            {
                MatchShopKeeper = (ShopKeeper)o;
            }
            if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Snake)) || o.GetType() == typeof(Snake))
            {
                Snakes.Add((Snake)o);
            }
        }
Beispiel #9
0
 public void CreateSnake()
 {
     Snakes.Add(new SnakeProfile(DefaultResources.RandomSkin().SkinName));
     SelectedSnake = Snakes[Snakes.Count - 1];
 }
 public void SetupSnakes(int head, int tail)
 {
     Snakes.Add(head, tail);
 }
Beispiel #11
0
 public void AddAISnake(int x, int y, Direction direction, Color headColor, Color bodyColor)
 {
     Snakes.Add(new ComputerSnake(x, y, direction, headColor, bodyColor));
 }
Beispiel #12
0
 public void AddAISnake()
 {
     Snakes.Add(GetRandomComputerSnake());
 }