Beispiel #1
0
        /// <summary>
        /// Progress the snake's head forward.
        /// </summary>
        /// <param name="level">The current level.</param>
        private void moveHead(LevelType level)
        {
            PortalType portal;

            //If the snake is in a portal, check to see if it can teleport
            if (level.tryGetPortal(head.Vector, out portal))
            {
                //If the snake's orientation is the same as the portal's, teleport.
                if (head.Orientation == portal.Entrance)
                {
                    portal.teleport();
                }
                //Else clear the portal and move the snake normally
                else
                {
                    portal.clearPortal();

                    head.Vector += MovementFunctions.calculateLocation(Orientation);
                }
            }
            //If the snake is in a normal square, move normally
            else
            {
                head.Vector += MovementFunctions.calculateLocation(Orientation);
            }
        }
Beispiel #2
0
        private void movement(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.empty)
            {
                food.Vector = newLocation;
            }

            food.fillGrid(level);
        }
Beispiel #3
0
        /// <summary>
        /// This function returns the content of the cell the snake is attempting to move to.
        /// </summary>
        /// <param name="grid">The game grid that contains all object data for the level.</param>
        /// <returns>Returns the content of the cell the snake will move into.  Depending on this, the game will respond
        /// differently, i.e. if there is a wall, the game wil go to game over.</returns>
        private CellContent collision(LevelType level)
        {
            Vector2 newLocation = MovementFunctions.calculateLocation(Orientation) + Vector;

            try
            {
                return(level.Grid.GetCell(newLocation).content);
            }
            catch
            {
                return(CellContent.portal);
            }
        }