Exemple #1
0
        /// <summary>
        /// Checks if _player is in the same position as a powerup.
        /// </summary>
        /// <param name="x">X position of _player.</param>
        /// <param name="y">Y posiiton of _player.</param>
        /// <returns>What type of powerup the _player stays on.</returns>
        private Enums.TypePowerUp CheckPlayerOnPowerUp(int x, int y)
        {
            Cel cel = GetSingleCell(x, y);

            if (cel.GetPowerUp() != null)
            {
                if (cel.GetPowerUp().TypePowerUp != Enums.TypePowerUp.None)
                {
                    cel.GetPowerUp().PickedUp = true;
                    return(cel.GetPowerUp().TypePowerUp);
                }
            }

            return(Enums.TypePowerUp.None);
        }
Exemple #2
0
        /// <summary>
        /// Moves all the _bots to the _player if the _player is in a cel next to the bot.
        /// If _player is not in a cel next to the bot, the bot moves randomly.
        /// </summary>
        public void MoveBots()
        {
            int  direction;
            int  botX    = 0;
            int  botY    = 0;
            bool botMove = true;

            for (int a = 0; a < AmountOfBots - 1; a++)
            {
                botMove = true;
                if (DetectPlayer(_bots[a].LocationX, _bots[a].LocationY - CellSize))
                {
                    botY = _bots[a].LocationY - CellSize;
                    botX = _bots[a].LocationX;
                }
                else if (DetectPlayer(_bots[a].LocationX, _bots[a].LocationY + CellSize))
                {
                    botY = _bots[a].LocationY + CellSize;
                    botX = _bots[a].LocationX;
                }
                else if (DetectPlayer(_bots[a].LocationX - CellSize, _bots[a].LocationY))
                {
                    botY = _bots[a].LocationY;
                    botX = _bots[a].LocationX - CellSize;
                }
                else if (DetectPlayer(_bots[a].LocationX + CellSize, _bots[a].LocationY))
                {
                    botY = _bots[a].LocationY;
                    botX = _bots[a].LocationX + CellSize;
                }
                else
                {
                    direction = _Random.Next(1, 5);
                    switch (direction)
                    {
                    case 1:
                        botY = _bots[a].LocationY - CellSize;
                        botX = _bots[a].LocationX;
                        break;

                    case 2:
                        botY = _bots[a].LocationY;
                        botX = _bots[a].LocationX - CellSize;
                        break;

                    case 3:
                        botY = _bots[a].LocationY + CellSize;
                        botX = _bots[a].LocationX;
                        break;

                    case 4:
                        botY = _bots[a].LocationY;
                        botX = _bots[a].LocationX + CellSize;
                        break;

                    default:
                        botY = _bots[a].LocationY - CellSize;
                        botX = _bots[a].LocationX;
                        break;
                    }
                }

                Cel cel = GetSingleCell(botX, botY);

                if (botX > CellSize * (MapSize - 1) || botX < 0 || botY > CellSize * (MapSize - 1) || botY < 0)
                {
                    botMove = false;
                }
                else if (cel.GetTypeCel() != Enums.Object.Grass || DetectBot(botX, botY))
                {
                    botMove = false;
                }
                if (botMove)
                {
                    _bots[a].Move(cel.GetX(), cel.GetY());
                }
            }
        }