예제 #1
0
        public Game(ICollection <string> userIds, IMapInfo mapInfo, IGameSettings settings)
        {
            if (userIds == null)
            {
                throw new ArgumentNullException(nameof(userIds));
            }
            if (mapInfo == null)
            {
                throw new ArgumentNullException(nameof(mapInfo));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.actionPoints = settings.ActionPoints;

            var tanks = userIds.Select(x => new Tank(new Health(settings.TankHealthPoint), x)).ToArray();

            var map = new Map(new MapCreationData(mapInfo, tanks), new BattlefieldBuilder(),
                              new RandomSpawnService());

            // намерено скрываем типы используемых интерфейсов внутри класса игры
            this.mapAdapter    = new MapAdapter(map);
            this.bulletService = new BulletService(this.mapAdapter, settings.BulletActionPoints);
            this.moveService   = new MoveService(this.mapAdapter);
            this.zoneService   = new ZoneService(this.mapAdapter, settings.ZoneRadius);

            this.DestroyedObjects = new DestroyedInfo(new Dictionary <string, Coordinates>(), new ICellContentInfo[0]);
        }
예제 #2
0
        public void GameSetup()
        {
            scoreboard = new ScoreboardRound();
            foreach (Player player in playerList)
            {
                scoreboard.AddPlayer(player);
            }
            Random      rand = new Random();
            int         r    = rand.Next(100);
            MapDirector mapDirector;

            if (r < 30)
            {
                mapDirector = new MapDirector(new ConcreteMapBuilder());
            }
            else if (r < 60)
            {
                mapDirector = new MapDirector(new DefaultMapBuilder());
            }
            else
            {
                mapDirector = new MapDirector(new TeleporterMapBuilder());
            }

            Map mapFromCache = Server.GetMapByName(mapDirector.getMap().mapName);

            //If the map was already generated, clone it
            //If the map was not generated before, generate it and put a copy of it in cache
            if (mapFromCache != null)
            {
                map = new MapAdapter(mapFromCache);
            }
            else
            {
                mapDirector.constructMap();
                Map temp = mapDirector.getMap();
                map = new MapAdapter(temp);
                Server.AddMap(temp);
            }
            Server.current = map.GetMapFacade();
        }
예제 #3
0
 public MoveService(IMapAdapter mapAdapter)
 {
     this.mapAdapter = mapAdapter;
 }
예제 #4
0
 public BulletService(IMapAdapter mapAdapter, byte bulletActionPointCount)
 {
     this.mapAdapter             = mapAdapter;
     this.bulletActionPointCount = bulletActionPointCount;
 }
예제 #5
0
 public ZoneService(IMapAdapter mapAdapter, byte radius)
 {
     this.mapAdapter = mapAdapter;
     this.Radius     = radius;
 }