示例#1
0
 public void GenLogs(SystemList sysList)
 {
     foreach (Player player in _playerArray)
     {
         player.GenLog(sysList, player.ID);
     }
 }
示例#2
0
 public GameData(DataMap dataMap, SystemList systemList,
                 PlayerList playerList)
 {
     _wormhole   = dataMap.Wormhole;
     _dataMap    = dataMap;
     _systemList = systemList;
     _playerList = playerList;
 }
示例#3
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;
                        }
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Constructor creates array of DataHexes, assignes them
        /// locations and seeds them with systems from the system
        /// list
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="systemList"></param>
        public DataMap(int x, int y, SystemList systemList, Point wormhole)
        {
            _width  = x;
            _height = y;

            _wormhole = wormhole;

            _hexArray = new DataHex[x, y];
            for (int j = 0; j < y; j++)
            {
                for (int i = 0; i < x; i++)
                {
                    _hexArray[i, j] = new DataHex(i, j);
                }
            }
            SeedSystems(systemList);
            //Console.WriteLine("DataMap created");//test string
        }
示例#5
0
 public void GenLog(SystemList sysList, int ID)
 {
     _systemLog = new SystemLog(sysList, ID);
 }
示例#6
0
        /// <summary>
        /// populate TokenList with all visible tokens drawn from
        /// GameData, compile these in order for re-paint and hit-
        /// testing purposes: system tokens, non-movable ships
        /// including players own ships, then moveable
        /// tokens, i.e. current players fleet
        /// </summary>
        public TokenList(PlayerList playerList, SystemList systemList,
                         HexArray hexArray, int playerID)
        {
            //
            //  Create token for Worm hole, assign it to its hex and
            //  add it to the token list
            //
            Token wormholeToken = new Token("Wormhole.ico", hexArray.Wormhole);

            hexArray[hexArray.Wormhole.X,
                     hexArray.Wormhole.Y].SystemToken = wormholeToken;
            _tokenArray.Add(wormholeToken);
            //  Cycle through systemList, creating tokens for
            //  each system, adding them to the list and
            //	assigning them to their home hex.
            for (int i = 0; i < systemList.Count; i++)
            {
                StarSystem system   = systemList[i];
                Point      location = system.MapLocation;            //Hex index of system
                Token      token    = CreateSystemToken(system, location);
                _tokenArray.Add(token);
                hexArray[location.X, location.Y].SystemToken = token;
            }
            //
            //  Cycle through playerlist, getting Fleets and creating
            //  Tokens for fleets and adding them to the list
            //  and assigning their to a home hex. Skip this player
            //  and create moveable tokens assigning them.
            //

            int count = playerList.Count;

            for (int i = 0; i < count; i++)
            {
                Fleet fleet = playerList[i].Fleet;
                //skip this players icons for now
                if (i == playerID)
                {
                    continue;
                }

                for (int j = 0; j < fleet.Count; j++)
                {
                    Ship ship = fleet[j];
                    if (ship.Type == Ship.ShipType.Trader)
                    {
                        continue;
                    }
                    Token token = CreateShipToken(ship, i);
                    _tokenArray.Add(token);
                    hexArray[ship.HexLocation.X,
                             ship.HexLocation.Y].TokenList.AddToken(token);
                }
            }
            //if this is the controller view, we're done
            if (playerID == -1)
            {
                return;
            }
            //otherwise
            //create this players fleet tokens
            //add them to the list and assign them to their hexes
            for (int i = 0; i < playerList[playerID].Fleet.Count; i++)
            {
                Ship ship = playerList[playerID].Fleet[i];
                if (ship.Type == Ship.ShipType.Trader)
                {
                    continue;
                }
                MoveableToken token = CreatePlayerShipToken(ship, playerID);
                _tokenArray.Add(token);
                hexArray[ship.HexLocation.X,
                         ship.HexLocation.Y].TokenList.AddToken(token);
            }
        }