Пример #1
0
        private IEnumerable <KeyValuePair <int, PlanetData> > GeneratePlanets()
        {
            var totalCells   = _map.CellsCount;
            var totalPlanets = _state.NeutralPlanetsCount + _state.Players.Count;
            var planets      = Sequences
                               .NumbersRangeLong(0, totalCells)
                               .Shuffle()
                               .Take(totalPlanets)
                               .Select(GeneratePlanet);

            return(planets);
        }
Пример #2
0
        public void PlacePlanet(Guid playerId)
        {
            if (_state.Players.Contains(playerId))
            {
                return;
            }
            if (!CanPlacePlanet)
            {
                throw new InvalidOperationException("No free cells on the map");
            }
            _state.Players.Add(playerId);
            var freeCoordinate = Sequences
                                 .NumbersRangeLong(0, _map.CellsCount)
                                 .Where(x => !_map.ContainsPlanet(x))
                                 .Shuffle()
                                 .First();

            _namesEnumerator.MoveNext();
            var planet = _playerPlanetGenerator.Generate(_namesEnumerator.Current, playerId);

            _map[freeCoordinate] = planet;
        }