示例#1
0
        public EnemyPositions GetEnemies()
        {
            Maze           maze = APICaller.GetMaze();
            EnemyPositions cont = new EnemyPositions();

            cont.Enemies = spawnPointGenerator.generateEnemies(maze);
            APICaller.SaveEnemies(cont);
            return(cont);
        }
        /// <summary>
        /// This function resizes the board to the given size.
        /// Currently this can only be used to initialise an
        /// empty board.
        /// </summary>
        /// <param name="sizeX">The width of the board.</param>
        /// <param name="sizeY">The length of the board.</param>
        public void Resize(int sizeX, int sizeY)
        {
            if (sizeX == Width && sizeY == Height)
            {
                return;
            }


            if (m_levelMap == null)
            {
                m_levelMap = new eTileType[sizeX, sizeY];

                for (int y = 0; y < sizeY; y++)
                {
                    for (int x = 0; x < sizeX; x++)
                    {
                        m_levelMap[x, y] = eTileType.Floor;
                    }
                }
            }
            else
            {
                ////////////////////////////////////////////////////////////
                // If a game is loaded, proceed by first creating a copy of
                // the current map

                eTileType[,] previousMap = m_levelMap;

                ////////////////////////////////////////////////////////////
                // Initialise the new map

                m_levelMap = new eTileType[sizeX, sizeY];

                for (int y = 0; y < sizeY; y++)
                {
                    for (int x = 0; x < sizeX; x++)
                    {
                        ////////////////////////////////////////////////////////////
                        // Set new tile as a floor for a failsafe

                        m_levelMap[x, y] = eTileType.Floor;

                        ////////////////////////////////////////////////////////////
                        // See if previous map data can be reused

                        if (x < previousMap.GetLength(0) && y < previousMap.GetLength(1))
                        {
                            m_levelMap[x, y] = previousMap[x, y];
                        }
                    }
                }

                ////////////////////////////////////////////////////////////
                // Flag for use with entity out of bound issue checking:
                // Ie, suppose the map is reduced in size and some fires or enemies
                // are outside the new borders, they'd need to be removed

                bool complete = false;

                ////////////////////////////////////////////////////////////
                // Check if any enemies are now out of bounds due to the
                // map size change

                while (!complete)
                {
                    if (EnemyPositions.Count == 0)
                    {
                        break;                            //if there are no enemies, break out of the checking process
                    }
                    for (int i = 0; i < EnemyPositions.Count; i++)
                    {
                        if (EnemyPositions[i].X >= sizeX || EnemyPositions[i].Y >= sizeY)
                        {
                            EnemyPositions.RemoveAt(i);
                            complete = false;
                            break;
                        }
                        else
                        {
                            complete = true;
                        }
                    }
                }

                ////////////////////////////////////////////////////////////
                // Reset flag

                complete = false;

                ////////////////////////////////////////////////////////////
                // Check if any fires are now out of bounds due to the
                // map size change

                while (!complete)
                {
                    if (FirePositions.Count == 0)
                    {
                        break;                           //if there are no fires, break out of the checking process
                    }
                    for (int i = 0; i < FirePositions.Count; i++)
                    {
                        if (FirePositions[i].X >= sizeX || FirePositions[i].Y >= sizeY)
                        {
                            FirePositions.RemoveAt(i);
                            complete = false;
                            break;
                        }
                        else
                        {
                            complete = true;
                        }
                    }
                }

                ////////////////////////////////////////////////////////////
                // Check if start position is now out of bounds

                if (StartPosition != null)
                {
                    if (StartPosition.X >= sizeX || StartPosition.Y >= sizeY)
                    {
                        StartPosition = null;
                    }
                }

                ////////////////////////////////////////////////////////////
                // Check if end position is now out of bounds

                if (GoalPosition != null)
                {
                    if (GoalPosition.X >= sizeX || GoalPosition.Y >= sizeY)
                    {
                        GoalPosition = null;
                    }
                }
            }

            Width  = sizeX;
            Height = sizeY;
        }