Пример #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;
                        }
                    }
                }
            }
        }
Пример #2
0
 public void ShowRange(int X, int Y, int move)
 {
     ClearRange();
     _range = _rangeFinder.Find(X, Y, move);
     foreach (Hex hex in _range)
     {
         hex.Highlighted = true;
     }
 }