示例#1
0
        public void JoinGame(string gameId, string playerName, int seatNo)
        {
            var game = GetGame(gameId);

            if (game == null)
            {
                Clients.Caller.GameError("Game not found");
                return;
            }

            double balance = 1000;

            var account = new PlayerAccount(id: Guid.NewGuid().ToString().Replace("-", ""), startingBalance: balance);

            game.AddPlayer(account, playerName, seatNo);
            _blackJackDAL.SaveGame(game);
            Clients.Caller.GameJoined(gameId, account);
        }
        public ActionResult <PlayerAccount> Join(string gameId, string playerName, int seatNo)
        {
            try
            {
                var game = _blackJackDAL.GetGame(gameId);
                if (game == null)
                {
                    return(NotFound("Game not found"));
                }
                double balance = 1000;

                var account = new PlayerAccount(
                    id: Guid.NewGuid().ToString().Replace("-", ""),
                    startingBalance: balance);

                game.AddPlayer(account, playerName, seatNo);
                _blackJackDAL.SaveGame(game);
                return(Ok(account));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }