Exemplo n.º 1
0
        /// <summary>
        /// Cycle through System list, randomly placing systems
        /// checking to see if there is already a system there
        /// before placing
        /// </summary>
        /// <param name="systemList"></param>
        private void SeedSystems(SystemList systemList)
        {
            Random      rand   = new Random();
            RangeFinder finder = new RangeFinder(_hexArray);
            ArrayList   taken  = finder.Find(_wormhole.X, _wormhole.Y, 3);

            //Assign hexes within two of the wormhole as Empty
            foreach (object hex in taken)
            {
                DataHex dataHex = (DataHex)hex;
                dataHex.System = new StarSystem(StarSystem.SystemType.Empty);
            }
            for (int i = 0; i < systemList.Count; i++)
            {
                bool placed = false;
                //Genrate random locations for systems until a viable one is found
                while (!placed)
                {
                    int x = rand.Next(_width);
                    int y = rand.Next(_height);
                    //if this hex has been assigned as Empty, skip it.
                    if (_hexArray[x, y].System != null &&
                        _hexArray[x, y].System.Type == StarSystem.SystemType.Empty)
                    {
                        continue;
                    }
                    //if this System slot has not been assigned and its not
                    //reserved for the black hole
                    if (null == _hexArray[x, y].System &&
                        x != _wormhole.X && y != _wormhole.Y)
                    {
                        //generate a list of hexes surrounding this one
                        taken.Clear();
                        taken = finder.Find(x, y, 1);
                        //assume there is room
                        bool gotRoom = true;
                        //check to see if any systems within one hex
                        foreach (object hex in taken)
                        {
                            DataHex dataHex = (DataHex)hex;
                            if (dataHex.System != null &&
                                dataHex.System.Type != StarSystem.SystemType.Empty)
                            {
                                gotRoom = false;
                                break;
                            }
                        }
                        if (gotRoom)
                        {
                            _hexArray[x, y].System    = systemList[i];
                            systemList[i].MapLocation = new Point(x, y);
                            placed = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        }                           //should never be used, hence private

        /// <summary>
        /// Default constructor
        /// </summary>
        public MapBoard(GameData gameData, int PlayerID)
        {
            //unassigned players have an ID of -1
            if (PlayerID != -1)
            {
                _playerID = PlayerID;
            }
            _gameData    = gameData;
            _hexArray    = new HexArray(gameData.DataMap);
            _rangeFinder = new RangeFinder(_hexArray.Array);
            _tokenList   = new TokenList(gameData.PlayerList,
                                         gameData.SystemList, _hexArray, PlayerID);


            ReSetMap();
        }