Beispiel #1
0
        public void GamePrefLessMinimalBet()
        {
            object objUser = db.getUserByName("test0");

            Assert.IsInstanceOfType(objUser, typeof(SystemUser));
            SystemUser user = (SystemUser)objUser;

            object objGame = sl.createGame(user.id, "Pot_Limit", 1000, 100, 0, 120, 4, 8, true, false);

            Assert.IsInstanceOfType(objGame, typeof(TexasHoldemGame));
            TexasHoldemGame game = (TexasHoldemGame)objGame;

            Assert.IsTrue(game.gamePreferences.isContain(new MustPreferences(new StartingAmountChipsCedPref(0, null), true)));
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)game.gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            Assert.AreEqual(0, startingChipsPref.startingChipsPolicy);

            object objUser1 = db.getUserByName("test1");

            Assert.IsInstanceOfType(objUser, typeof(SystemUser));
            SystemUser user1 = (SystemUser)objUser;

            ReturnMessage m = null;

            game.joinGame(user1, 3);
            for (int i = 0; i < game.players.Length; i++)
            {
                if (game.players[i] != null && game.players[i].systemUserID == user1.id)
                {
                    m = game.bet(game.players[i], 100);
                }
            }

            Assert.IsFalse(m.success);
        }
Beispiel #2
0
        public void TestCreateGameNoBuyinWithStartingChipsCheckTokensMoreThen0()
        {
            object objUser = db.getUserByName("test0");

            Assert.IsInstanceOfType(objUser, typeof(SystemUser));
            SystemUser user = (SystemUser)objUser;

            object objGame = sl.createGame(user.id, "Pot_Limit", 1000, null, 0, 120, 4, 8, true, false);

            Assert.IsInstanceOfType(objGame, typeof(TexasHoldemGame));
            TexasHoldemGame game = (TexasHoldemGame)objGame;

            Assert.IsTrue(game.gamePreferences.isContain(new MustPreferences(new StartingAmountChipsCedPref(0, null), true)));
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)game.gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            Assert.AreEqual(0, startingChipsPref.startingChipsPolicy);

            object objUser1 = db.getUserByName("test1");

            Assert.IsInstanceOfType(objUser, typeof(SystemUser));
            SystemUser user1 = (SystemUser)objUser;

            int user1Tokens = -1;

            game.joinGame(user1, 3);
            for (int i = 0; i < game.players.Length; i++)
            {
                if (game.players[i] != null && game.players[i].systemUserID == user1.id)
                {
                    user1Tokens = game.players[i].Tokens;
                }
            }

            Assert.AreEqual(50, user1Tokens);
        }
Beispiel #3
0
        public ReturnMessage removeUser(int userId)
        {
            for (int i = 0; i < players.Length; i++)
            {
                if (players[i] != null && players[i].systemUserID == userId)
                {
                    // Buy in handle
                    int buyIn = 50;
                    BuyInPolicyDecPref buyInPref = (BuyInPolicyDecPref)gamePreferences.getOptionalPref(new BuyInPolicyDecPref(0, null));
                    if (buyInPref != null)
                    {
                        buyIn = buyInPref.buyInPolicy;
                    }

                    // Starting chips amount policy
                    int moneyToAdd    = 0;
                    int startingChips = 1000;
                    StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));
                    if (startingChipsPref != null)
                    {
                        int policy = startingChipsPref.startingChipsPolicy;
                        if (policy == 0)
                        {
                            startingChips = buyIn;
                            moneyToAdd   += players[i].Tokens;
                        }
                        else
                        {
                            startingChips = policy;
                        }
                    }

                    // updates the rank and money of the user.
                    rankMoneyUpdateCallback(new int[] { userId, players[i].Tokens - startingChips, moneyToAdd });

                    GameLog.logLine(gameId, GameLog.Actions.Player_Left, players[i].name, i.ToString());

                    players[i] = null;

                    gameStatesObserver.Update(this);
                    spectateObserver.Update(this);
                    return(new ReturnMessage(true, ""));
                }
            }
            foreach (SystemUser u in spectators)
            {
                if (u.id == userId)
                {
                    spectators.Remove(u);
                    u.spectatingGame.Remove(this);
                    return(new ReturnMessage(true, ""));
                }
            }
            return(new ReturnMessage(true, ""));
        }
Beispiel #4
0
        public void TestCreateGameWithStartingChipsMoreThan0()
        {
            object objUser = db.getUserByName("test0");

            Assert.IsInstanceOfType(objUser, typeof(SystemUser));
            SystemUser user = (SystemUser)objUser;

            object objGame = sl.createGame(user.id, "Pot_Limit", 1000, 100, 200, 120, 4, 8, true, false);

            Assert.IsInstanceOfType(objGame, typeof(TexasHoldemGame));
            TexasHoldemGame game = (TexasHoldemGame)objGame;

            Assert.IsTrue(game.gamePreferences.isContain(new MustPreferences(new StartingAmountChipsCedPref(200, null), true)));
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)game.gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            Assert.AreEqual(200, startingChipsPref.startingChipsPolicy);
        }
Beispiel #5
0
        public TexasHoldemGame(SystemUser user, MustPreferences gamePreferences, Action <int[]> rankMoneyUpdateCallback, Action <int[]> leaderBoardUpdateCallback)
        {
            firstJoin            = true;
            gameCreatorUserId    = user.id;
            this.gamePreferences = gamePreferences;
            pot                = 0;
            active             = true;
            deck               = new Deck();
            spectators         = new List <SystemUser>();
            gameStatesObserver = new GameObserver();
            spectateObserver   = new GameObserver();
            //setting the players array according to the max players pref if entered else 9 players is the max.
            maxPlayers = 9;
            MaxPlayersDecPref maxPlayersDec = (MaxPlayersDecPref)gamePreferences.getOptionalPref(new MaxPlayersDecPref(0, null));

            if (maxPlayersDec != null)
            {
                maxPlayers = maxPlayersDec.maxPlayers;
            }
            players        = new Player[maxPlayers];
            playersStats   = new LeaderboardsStats[maxPlayers];
            availableSeats = maxPlayers - 1;
            this.rankMoneyUpdateCallback = rankMoneyUpdateCallback;
            flop            = null;
            currentBlindBet = 20;

            gameOnChips = true;
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            if (startingChipsPref != null)
            {
                if (startingChipsPref.startingChipsPolicy == 0)
                {
                    gameOnChips = false;
                }
            }

            gameId = getNextId();
            GameLog.setLog(gameId, DateTime.Now);
            GameLog.logLine(gameId, GameLog.Actions.Game_Create, gameId.ToString(), user.name, DateTime.Now.ToString());
            for (int i = 1; i < maxPlayers; i++)
            {
                players[i] = null;
            }
        }
Beispiel #6
0
        public ReturnMessage joinGame(SystemUser user, int seatIndex)
        {
            ReturnMessage m = gamePreferences.canPerformUserActions(this, user, "join");

            if (!m.success)
            {
                return(m);
            }

            if (seatIndex > players.Length)
            {
                return(new ReturnMessage(false, "cannot seat here"));
            }
            if (players[seatIndex] != null)
            {
                return(new ReturnMessage(false, "seat is taken"));
            }

            // Buy in handle
            int buyIn = 50;
            BuyInPolicyDecPref buyInPref = (BuyInPolicyDecPref)gamePreferences.getOptionalPref(new BuyInPolicyDecPref(0, null));

            if (buyInPref != null)
            {
                buyIn = buyInPref.buyInPolicy;
            }

            // Starting chips amount policy
            int startingChips = 1000;
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            if (startingChipsPref != null)
            {
                int policy = startingChipsPref.startingChipsPolicy;
                if (policy == 0)
                {
                    startingChips = buyIn;
                }
                else
                {
                    startingChips = policy;
                }
            }

            // The user pay to enter the game.
            //user.money -= buyIn;
            rankMoneyUpdateCallback(new int[] { user.id, 0, -buyIn });

            Player p = new Player(user.id, user.name, startingChips, user.rank, user.userImageByteArray);

            players[seatIndex] = p;

            playersStats[seatIndex] = new LeaderboardsStats();

            if (firstJoin)
            {
                currentDealer = seatIndex;
                firstJoin     = false;
            }

            GameLog.logLine(gameId, GameLog.Actions.Player_Join, user.name, seatIndex.ToString(), startingChips.ToString());

            spectateObserver.Update(this);
            gameStatesObserver.Update(this);
            moneyInGame += buyIn;
            return(new ReturnMessage(true, ""));
        }