Exemplo n.º 1
0
        private void deduceOrientation(SnakeType snake, FoodType food)
        {
            int number = random % upperBound;

            switch (threat)
            {
            case ThreatLevel.low:
                if (number == 0)
                {
                    randomOrientation();
                }
                else if (number == 1)
                {
                    directionalOrientation(food);
                }
                else
                {
                    attackOrientation(snake, food);
                }
                break;

            case ThreatLevel.medium:
                if (number == 0 || number == 1)
                {
                    randomOrientation();
                }
                else if (number == 2)
                {
                    attackOrientation(snake, food);
                }
                else
                {
                    smartOrientation(snake);
                }
                break;

            case ThreatLevel.high:
                if (number == 0 || number == 1)
                {
                    attackOrientation(snake, food);
                }
                else
                {
                    smartOrientation(snake);
                }
                break;
            }
        }
Exemplo n.º 2
0
        //Returns the same orientation as the snake, simulating the food running from the snake
        private void runOrientation(SnakeType snake, FoodType food)
        {
            bool temp = false;

            //Determine if food is in front of snake
            switch (snake.Orientation)
            {
            case OrientationType.up:
                if (snake.Vector.Y > food.Vector.Y)
                {
                    temp = true;
                }
                break;

            case OrientationType.down:
                if (snake.Vector.Y < food.Vector.Y)
                {
                    temp = true;
                }
                break;

            case OrientationType.left:
                if (snake.Vector.X > food.Vector.X)
                {
                    temp = true;
                }
                break;

            case OrientationType.right:
                if (snake.Vector.X < food.Vector.X)
                {
                    temp = true;
                }
                break;
            }

            //If the food is in front of snake, run, else random
            if (temp)
            {
                orientation = snake.Orientation;
            }
            else
            {
                randomOrientation();
            }
        }
Exemplo n.º 3
0
        private void deduceThreat(SnakeType snake, FoodType food)
        {
            int yClose = (int)(snake.Vector.Y - food.Vector.Y);
            int xClose = (int)(snake.Vector.X - food.Vector.X);

            if ((Math.Abs(yClose) <= innerZone) || (Math.Abs(xClose) <= innerZone))
            {
                threat = ThreatLevel.high;
            }
            else if ((Math.Abs(yClose) <= outerZone) || (Math.Abs(xClose) <= outerZone))
            {
                threat = ThreatLevel.medium;
            }
            else if ((Math.Abs(yClose) > outerZone) || (Math.Abs(xClose) > outerZone))
            {
                threat = ThreatLevel.low;
            }
        }
Exemplo n.º 4
0
        void updateScore(FoodType food)
        {
            BaseTextType text = hud.getText("Add Score Number");

            if (!text.DrawText)
            {
                text.changeNumber(food.Score);
                text.startText(time);
            }
            else
            {
                text.addToNumber(food.Score);
            }

            score += food.Score;

            hud.getText("Score Number").changeNumber(score);
        }
Exemplo n.º 5
0
        private void movement(SnakeType snake, FoodType food, LevelType level)
        {
            PortalType portal;

            //If the food is in a portal, clear the portal
            if (level.tryGetPortal(food.Vector, out portal))
            {
                portal.clearGrid(level);
            }
            //Else empty the old grid cell
            else
            {
                level.Grid.GetCell(food.Vector).emptyCell();
            }

            //Add the movement vector to the current mouse vector
            Vector2 newLocation = food.Vector + MovementFunctions.calculateLocation(orientation);

            if (level.tryGetPortal(newLocation, out portal))
            {
                if (!portal.IsFull)
                {
                    food.Vector = newLocation;
                    portal.fillPortal(food);
                }
            }
            else if (level.Grid.GetCell(newLocation).content == CellContent.snake)
            {
                if (classification == FoodClassification.threat)
                {
                    snake.GameOver(this, new EventArgs());
                }
            }
            else if (level.Grid.GetCell(newLocation).content == CellContent.empty)
            {
                food.Vector = newLocation;
            }

            food.fillGrid(level);
        }
Exemplo n.º 6
0
        public static bool calculateMovement(GameGrid grid, FoodType food, OrientationType orientation)
        {
            bool move = false;

            int x = (int)food.Vector.X;
            int y = (int)food.Vector.Y;

            switch (orientation)
            {
            case OrientationType.up:
                if (grid.GetCell(x, y - 1).content == CellContent.empty)
                {
                    move = true;
                }
                break;

            case OrientationType.down:
                if (grid.GetCell(x, y + 1).content == CellContent.empty)
                {
                    move = true;
                }
                break;

            case OrientationType.right:
                if (grid.GetCell(x + 1, y).content == CellContent.empty)
                {
                    move = true;
                }
                break;

            case OrientationType.left:
                if (grid.GetCell(x - 1, y).content == CellContent.empty)
                {
                    move = true;
                }
                break;
            }

            return(move);
        }