Beispiel #1
0
        public ActionResponse StartGame(StartGameAction action)
        {
            var result = TryToResolve(action.User);

            if (result)
            {
                //todo move this out
                foreach (var p in Players)
                {
                    GameRule.PaymentTransaction(p, 50);
                }
                GameRule.ChangeTurnOrder(_container.GameContext);
                return(new StartGameResponse());
            }

            return(new StartGameResponse(Constants.Instance.ErrorMessage.Not_Everybody_Checked_ReadyMark));
        }
        //todo need to move it outside
        public bool Build(City city)
        {
            var context = GameContext.GetContextByPlayer(Player);
            var builts  = context.GameBoard.BuildPlayersCities.Values.SelectMany(m => m.Cities)
                          .Where(m => m.City.Id == city.Id);
            var level = builts.Any() ? builts.Max(m => m.Level) : -1;

            level++;
            if (level <= city.Levels.Max(m => m.Key))
            {
                var cost = city.Levels[level];
                if (GameRule.CanPay(Player, cost))
                {
                    Cities.Add(new BuiltCity(city, level));
                    GameRule.PaymentTransaction(Player, -cost);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        public GameContext(GameRoom room, string mapId = null)
        {
            Room      = room;
            GameBoard = new GameBoard(this, mapId);

            _playerBoards = new Dictionary <string, PlayerBoard>();
            foreach (var p in room.Players)
            {
                _playerBoards.Add(p.Key, new PlayerBoard(this, p.Value.Player));
            }

            var deck = GameRule.CreateDeck();

            StationBoard = new StationBoard(this, deck);

            if (Contexts == null)
            {
                Contexts = new List <GameContext>();
            }
            Contexts.Add(this);
        }