Exemplo n.º 1
0
 public PokerTableBL JoinTable(int TableId)
 {
     UserCheck();
     foreach (PokerTableBL table in Tables)
     {
         if (table.Id == TableId)
         {
             if (table.NumOfPlayers != table.Players.Count)
             {
                 if (table.MinBet * 20 < myUser.Wallet)
                 {
                     myTable  = table;
                     myPlayer = new PlayerBL(myUser);
                     table.Players.Add(myPlayer);
                     myState = PlayerStates.InTable;
                     myPlayer.IsPlayingThisGame = true;
                     return(table);
                 }
                 throw new Exception("Inorder to join this table you need atleast: " + table.MinBet.ToString() + "$");
             }
             throw new Exception("The table is full");
         }
     }
     throw new Exception("An error occured while joining this table");
 }
Exemplo n.º 2
0
 public PokerTableBL CreateTable(string PokerTableName, int NumOfPlayers, int MinBetAmount)
 {
     UserCheck();
     myTable  = new PokerTableBL(PokerTableName, NumOfPlayers, MinBetAmount);
     myPlayer = new PlayerBL(myUser);
     myTable.Players.Add(myPlayer);
     Tables.Add(myTable);
     myState = PlayerStates.InTable;
     myPlayer.IsPlayingThisGame = true;
     return(myTable);
 }
Exemplo n.º 3
0
 public override bool Equals(object obj)
 {
     //Check for null and compare run-time types.
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         PlayerBL p = (PlayerBL)obj;
         return(PlayerId == p.PlayerId);
     }
 }
Exemplo n.º 4
0
 public PokerTableBL GetTableByHistory(PokerTable pokerTable)
 {
     myTable = new PokerTableBL(pokerTable.PokerTableName, 0, pokerTable.MinBet);
     if (pokerTable.Player1Id != -1)
     {
         myTable.Players.Add(new PlayerBL(Database.GetUserById(pokerTable.Player1Id), pokerTable.Id));
     }
     if (pokerTable.Player2Id != -1)
     {
         myTable.Players.Add(new PlayerBL(Database.GetUserById(pokerTable.Player2Id), pokerTable.Id));
     }
     if (pokerTable.Player3Id != -1)
     {
         myTable.Players.Add(new PlayerBL(Database.GetUserById(pokerTable.Player3Id), pokerTable.Id));
     }
     if (pokerTable.Player4Id != -1)
     {
         myTable.Players.Add(new PlayerBL(Database.GetUserById(pokerTable.Player4Id), pokerTable.Id));
     }
     if (pokerTable.Player5Id != -1)
     {
         myTable.Players.Add(new PlayerBL(Database.GetUserById(pokerTable.Player5Id), pokerTable.Id));
     }
     if (pokerTable.FirstCard != "")
     {
         myTable.TableStatus.TableCards.Add(new Card(pokerTable.FirstCard));
     }
     if (pokerTable.SecondCard != "")
     {
         myTable.TableStatus.TableCards.Add(new Card(pokerTable.SecondCard));
     }
     if (pokerTable.ThirdCard != "")
     {
         myTable.TableStatus.TableCards.Add(new Card(pokerTable.ThirdCard));
     }
     if (pokerTable.FourthCard != "")
     {
         myTable.TableStatus.TableCards.Add(new Card(pokerTable.FourthCard));
     }
     if (pokerTable.FifthCard != "")
     {
         myTable.TableStatus.TableCards.Add(new Card(pokerTable.FifthCard));
     }
     myTable.NumOfPlayers = myTable.Players.Count;
     myTable.DealerId     = pokerTable.DealerId;
     for (int i = 0; i < myTable.Players.Count; i++)
     {
         if (myTable.DealerId == myTable.Players[i].PlayerId)
         {
             myTable.DealerIndex = i;
         }
     }
     foreach (PlayerBL player in myTable.Players)
     {
         if (player.PlayerId == myUser.Id)
         {
             myPlayer = player;
         }
     }
     return(myTable);
 }
Exemplo n.º 5
0
        public StartGameStatus StartGame()
        {
            myState = PlayerStates.InGame;
            StartGameStatus startGameStatus = new StartGameStatus();

            UserCheck();
            if (HistoryMoves == null)
            {
                Move smallBlind, bigBlind;
                myPlayer = new PlayerBL(myUser);
                myTable  = myPlayer.GeneratePersonalCards(myTable);
                UpdatePersonalCardsInStaticList();
                myTable.GenerateDealerIndex();
                if (myTable.Moves.Count < 2)
                {
                    if (myTable.NumOfPlayers == 2)
                    {
                        if (myTable.DealerIndex == 0)
                        {
                            smallBlind       = new Move(Operation.Raise, myTable.MinBet / 2, myTable.Players[1].PlayerId, myTable.Id);
                            myTable.CurrTurn = 1;
                            myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet / 2;
                            myTable.Moves.Add(smallBlind);
                            myTable.CurrTurn = 0;
                        }
                        else
                        {
                            smallBlind       = new Move(Operation.Raise, myTable.MinBet / 2, myTable.Players[0].PlayerId, myTable.Id);
                            myTable.CurrTurn = 0;
                            myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet / 2;
                            myTable.Moves.Add(smallBlind);
                            myTable.CurrTurn = 1;
                        }
                        bigBlind = new Move(Operation.Raise, myTable.MinBet, myTable.DealerId, myTable.Id);
                        myTable.Moves.Add(bigBlind);
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet;
                        myTable.CurrRound     = Round.PreFlop;
                        myTable.FirstPlayerId = myPlayer.PlayerId;
                        HasRoundEnded();
                        SwitchTurns();
                    }
                    else if (myTable.DealerIndex == myTable.NumOfPlayers - 1)
                    {
                        smallBlind       = new Move(Operation.Raise, myTable.MinBet / 2, myTable.Players[0].PlayerId, myTable.Id);
                        myTable.CurrTurn = 0;
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet / 2;
                        myTable.CurrTurn = 1;
                        myTable.Moves.Add(smallBlind);
                        bigBlind = new Move(Operation.Raise, myTable.MinBet, myTable.Players[1].PlayerId, myTable.Id);
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet;
                        myTable.Moves.Add(bigBlind);
                        HasRoundEnded();
                        SwitchTurns();
                    }
                    else if (myTable.DealerIndex == myTable.NumOfPlayers - 2)
                    {
                        smallBlind       = new Move(Operation.Raise, myTable.MinBet / 2, myTable.Players[myTable.NumOfPlayers - 1].PlayerId, myTable.Id);
                        myTable.CurrTurn = myTable.NumOfPlayers - 1;
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet / 2;
                        myTable.CurrTurn = 0;
                        myTable.Moves.Add(smallBlind);
                        bigBlind = new Move(Operation.Raise, myTable.MinBet, myTable.Players[0].PlayerId, myTable.Id);
                        myTable.Moves.Add(bigBlind);
                        HasRoundEnded();
                        SwitchTurns();
                    }
                    else
                    {
                        smallBlind       = new Move(Operation.Raise, myTable.MinBet / 2, myTable.Players[myTable.DealerIndex + 1].PlayerId, myTable.Id);
                        myTable.CurrTurn = myTable.DealerIndex + 1;
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet / 2;
                        myTable.CurrTurn = myTable.DealerIndex + 2;
                        myTable.Moves.Add(smallBlind);
                        bigBlind = new Move(Operation.Raise, myTable.MinBet, myTable.Players[myTable.DealerIndex + 2].PlayerId, myTable.Id);
                        myTable.Players[myTable.CurrTurn].ChipsOnTable = myTable.MinBet;
                        myTable.Moves.Add(bigBlind);
                        HasRoundEnded();
                        SwitchTurns();
                    }
                    startGameStatus.SmallBlind = smallBlind;
                    startGameStatus.BigBlind   = bigBlind;
                    myTable.LastBid            = bigBlind.BidAmount;
                }
                myTable.TablePot            = Convert.ToInt32(myTable.MinBet * 1.5);
                startGameStatus.SmallBlind  = myTable.Moves[0];
                startGameStatus.BigBlind    = myTable.Moves[1];
                startGameStatus.PlayerCard1 = myPlayer.PersonalCards[0];
                startGameStatus.PlayerCard2 = myPlayer.PersonalCards[1];
                startGameStatus.DealerId    = myTable.DealerId;
                startGameStatus.PlayerId    = myPlayer.PlayerId;
                foreach (PlayerBL player in myTable.Players)
                {
                    if (player.PlayerId == startGameStatus.SmallBlind.PlayerId)
                    {
                        player.CurrWallet -= myTable.MinBet / 2;
                        if (myPlayer.PlayerId == player.PlayerId)
                        {
                            myPlayer.ChipsOnTable = myTable.MinBet / 2;
                        }
                    }
                    if (player.PlayerId == startGameStatus.BigBlind.PlayerId)
                    {
                        player.CurrWallet -= myTable.MinBet;
                        if (myPlayer.PlayerId == player.PlayerId)
                        {
                            myPlayer.ChipsOnTable = myTable.MinBet;
                        }
                    }
                }
            }
            else
            {
                int PlayerIndex = -1;
                startGameStatus.SmallBlind = HistoryMoves[0];
                startGameStatus.BigBlind   = HistoryMoves[1];
                startGameStatus.PlayerId   = myPlayer.PlayerId;
                for (int i = 0; i < myTable.Players.Count; i++)
                {
                    if (myTable.Players[i].PlayerId == myUser.Id)
                    {
                        PlayerIndex = i;
                    }
                }
                startGameStatus.PlayerCard1 = myTable.Players[PlayerIndex].PersonalCards[0];
                startGameStatus.PlayerCard2 = myTable.Players[PlayerIndex].PersonalCards[1];
            }
            return(startGameStatus);
        }