Exemplo n.º 1
0
 public GameMap(GameMapModel model)
 {
     Size     = model.Size;
     _tiles   = new List <Tile>();
     Entities = new List <Entity>();
     BuildMap(model.Tiles);
 }
Exemplo n.º 2
0
        private HandlerWorkResult HandleMapInfo(BufferStream stream, WebsocketClient client)
        {
            var map = new GameMapModel(stream);

            map.SavePicture(map.Author + "___" + map.Name + ".tga");

            Console.WriteLine("Map: " + map.Name + "Author: " + map.Author);

            return(new HandlerWorkResult()
            {
                IsOk = true,
            });
        }
        internal static GameMapModel GenerateModel(int seed)
        {
            var session = Controller.Session;
            var random  = new Random(seed);
            var model   = new GameMapModel();

            var tiles = new List <TileModel>();

            for (int x = 0; x < MAP_SIZE; x++)
            {
                for (int y = 0; y < MAP_SIZE; y++)
                {
                    if (x == 4 && y == 4)
                    {
                        tiles.Add(new TileModel
                        {
                            X      = x,
                            Y      = y,
                            Id     = Guid.NewGuid().ToString(),
                            Type   = TileType.Ground.ToString(),
                            Entity = CreateBase(session.Participants[0])
                        });
                    }
                    else if (x == MAP_SIZE - 4 && y == MAP_SIZE - 4)
                    {
                        tiles.Add(new TileModel
                        {
                            X      = x,
                            Y      = y,
                            Id     = Guid.NewGuid().ToString(),
                            Type   = TileType.Ground.ToString(),
                            Entity = CreateBase(session.Participants[0])
                        });
                    }
                    else
                    {
                        tiles.Add(new TileModel
                        {
                            X      = x,
                            Y      = y,
                            Id     = Guid.NewGuid().ToString(),
                            Type   = TileType.Ground.ToString(),
                            Entity = null
                        });
                    }
                }
            }
            model.Tiles = tiles.ToArray();

            return(model);
        }
Exemplo n.º 4
0
        public GameSimulator(
            string gameId,
            string weatherApiUri,
            GameMapModel map)
        {
            _gameId = gameId;

            Logger  = new Logger(gameId);
            _random = new Random();

            _tanks = new List <Tank>();
            _map   = new GameMap(map);

            _weatherApiClient = new WeatherApiClient(weatherApiUri);
        }
Exemplo n.º 5
0
        public async Task <GameDataModel> SimulateAsync(string gameId, TankModel tank1, TankModel tank2, GameMapModel map)
        {
            var gameData = await _resultsApiClient.GetScoreAsync(gameId);

            GameSimulator simulator = new GameSimulator(gameData.Id, Environment.GetEnvironmentVariable("WEATHER_API_URL"), map);

            simulator.GameFinished += OnGameFinished;

            gameData.Status = GameStatus.InProgress;
            await _resultsApiClient.UpdateAsync(gameData);

            simulator.Start(tank1, tank2);

            return(gameData);
        }
Exemplo n.º 6
0
        public static int GetPlayer(GameMapModel _map, dsreplay replay, Player pl, int gameloop = 0)
        {
            dsplayer dspl = replay.PLAYERS.SingleOrDefault(x => x.REALPOS == pl.Pos);

            if (dspl == null)
            {
                return(gameloop);
            }

            pl.SoftReset();
            if (pl.Name == "")
            {
                pl.Name = dspl.NAME;
                pl.Pos  = dspl.REALPOS;
                UnitRace race = UnitRace.Terran;
                if (dspl.RACE == "Protoss")
                {
                    race = UnitRace.Protoss;
                }
                else if (dspl.RACE == "Zerg")
                {
                    race = UnitRace.Zerg;
                }
                pl.Race  = race;
                pl.Units = UnitPool.Units.Where(x => x.Race == race && x.Cost > 0).ToList();
            }

            if (gameloop == 0)
            {
                gameloop = _map.plSpawns[pl.Pos].OrderBy(o => o).First();
            }

            foreach (var unit in _map.Spawns[gameloop].Where(x => x.Owner == pl.Pos))
            {
                Unit myunit = unit.DeepCopy();
                if (pl.Pos <= 3)
                {
                    //myunit.PlacePos = UnitService.mirrorImage(myunit.PlacePos);
                    //myunit.PlacePos = new Vector2(Battlefield.Xmax - myunit.PlacePos.X, myunit.PlacePos.Y);
                    myunit.PlacePos = new Vector2(myunit.PlacePos.X, 2 * 5 - myunit.PlacePos.Y - 1);
                }
                UnitService.NewUnit(pl, myunit);
                pl.Units.Add(myunit);
                pl.MineralsCurrent -= myunit.Cost;
            }

            foreach (var dic in _map.Upgrades[pl.Pos].OrderBy(x => x.Key))
            {
                if (dic.Key > gameloop)
                {
                    break;
                }
                foreach (var upgrade in dic.Value)
                {
                    pl.MineralsCurrent -= UnitService.UpgradeUnit(upgrade.Upgrade, pl);
                }
            }
            foreach (var dic in _map.AbilityUpgrades[pl.Pos].OrderBy(x => x.Key))
            {
                if (dic.Key > gameloop)
                {
                    break;
                }
                foreach (var upgrade in dic.Value)
                {
                    pl.MineralsCurrent -= UnitService.AbilityUpgradeUnit(upgrade, pl);
                }
            }
            pl.MineralsCurrent = 10000;
            return(gameloop);
        }