Example #1
0
        /// <summary>
        /// Get creature game board location coordinates.
        /// </summary>
        /// <returns>Creature location.</returns>
        public CharacterGameBoardLocation GetCharacterGameBoardLocation()
        {
            CharacterGameBoardLocation charLocation = new CharacterGameBoardLocation();

            double row, col, rowRounded, colRounded;

            col = coordinates.X / 50;
            row = coordinates.Y / 50;

            // Direction change is allowed if we are in even grid (with respect to
            // the gameBoard table v.s. canvas coordinates).
            if (col % 1 == 0 && row % 1 == 0)
            {
                allowDirectionChange = true;
            }
            else
            {
                allowDirectionChange = false;
            }

            // If character is going UP or LEFT, we ceil the canvas coordinates, otherwise we will
            // floor the coordinates. This is to align the canvas coordinates (pixels) with the
            // 50 x 50 game board grid blocks.
            if (creatureDirection == (int)Directions.UP || creatureDirection == (int)Directions.LEFT)
            {
                rowRounded = Math.Ceiling(row);
                colRounded = Math.Ceiling(col);
            }
            else
            {
                rowRounded = Math.Floor(row);
                colRounded = Math.Floor(col);
            }

            charLocation.Row = (int)rowRounded;
            charLocation.Col = (int)colRounded;

            return(charLocation);
        }
Example #2
0
        /// <summary>
        /// Checks whether the Hero collides with the tablet (eats the tablet) and
        /// updates score.
        /// </summary>
        /// <param name="pacman">Copy of the Hero.</param>
        /// <returns>
        ///    TRUE = Hero collided with a tablet.
        ///    FALSE = Hero didn't collide with a tablet.
        /// </returns>
        public bool DoesHeroCollideWithTablet(Hero pacman)
        {
            CharacterGameBoardLocation heroLocation = pacman.GetCharacterGameBoardLocation();

            if (gameBoard.IsCurrentCoordTablet(heroLocation.Row, heroLocation.Col))
            {
                gameBoard.Dispatcher.BeginInvoke((Action)(() =>
                {
                    int score;
                    int.TryParse(gameBoard.labelScore.Content.ToString(), out score);
                    gameBoard.labelScore.Content = score + 1;

                    Rectangle tabletToRemove = gameBoard.GetCurrentTablet(heroLocation.Row, heroLocation.Col);
                    gameBoard.gameBoardCanvas.Children.Remove(tabletToRemove);
                    gameBoard.RemoveTablet(heroLocation.Row, heroLocation.Col);
                }), DispatcherPriority.Normal, null);

                return(true);
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// Gets the possible directions, based on the game board layout.
        /// </summary>
        /// <returns>Possible directions.</returns>
        protected CharacterPossibleDirections GetPossibleDirections()
        {
            CharacterPossibleDirections direction    = new CharacterPossibleDirections();
            CharacterGameBoardLocation  charLocation = GetCharacterGameBoardLocation();

            if (!gameBoardLayout[charLocation.Row, charLocation.Col + 1].Equals('W'))
            {
                direction.Right = (int)Directions.RIGHT;
            }
            if (!gameBoardLayout[charLocation.Row, charLocation.Col - 1].Equals('W'))
            {
                direction.Left = (int)Directions.LEFT;
            }
            if (!gameBoardLayout[charLocation.Row + 1, charLocation.Col].Equals('W'))
            {
                direction.Down = (int)Directions.DOWN;
            }
            if (!gameBoardLayout[charLocation.Row - 1, charLocation.Col].Equals('W'))
            {
                direction.Up = (int)Directions.UP;
            }

            return(direction);
        }