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"); }
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); }
public PokerTableBL GeneratePersonalCards(PokerTableBL myTable) { PersonalCards = myTable.TableDeck.GetCards(2); FirstCard = PersonalCards[0].ToString(); SecondCard = PersonalCards[1].ToString(); for (int i = 0; i < myTable.Players.Count; i++) { if (myTable.Players[i].PlayerId == PlayerId) { myTable.Players[i].PersonalCards = PersonalCards; } } return(myTable); }
public bool LeaveTable() { UserCheck(); myPlayer.IsPlayingThisGame = false; if (myTable != null) { if (myTable.Players.Count == 1) { //Closing Table: Tables.Remove(myTable); } myTable.Players.Remove(myPlayer); myState = PlayerStates.InMenu; myTable = null; } return(true); }
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); }
public void UpdateHistoryInDB() { PokerTableBL tableBL = myTable; //Updating table from static List foreach (PokerTableBL pokerTable in Tables) { if (pokerTable.Id == myTable.Id) { tableBL = pokerTable; } } PokerTable table = new PokerTable() { PokerTableName = tableBL.PokerTableName, TablePot = tableBL.TablePot, MinBet = tableBL.MinBet, DealerId = tableBL.DealerId }; switch (tableBL.TableStatus.TableCards.Count) { case 1: table.FirstCard = tableBL.TableStatus.TableCards[0].ToString(); table.SecondCard = ""; table.ThirdCard = ""; table.FourthCard = ""; table.FifthCard = ""; break; case 2: table.FirstCard = tableBL.TableStatus.TableCards[0].ToString(); table.SecondCard = tableBL.TableStatus.TableCards[1].ToString(); table.ThirdCard = ""; table.FourthCard = ""; table.FifthCard = ""; break; case 3: table.FirstCard = tableBL.TableStatus.TableCards[0].ToString(); table.SecondCard = tableBL.TableStatus.TableCards[1].ToString(); table.ThirdCard = tableBL.TableStatus.TableCards[2].ToString(); table.FourthCard = ""; table.FifthCard = ""; break; case 4: table.FirstCard = tableBL.TableStatus.TableCards[0].ToString(); table.SecondCard = tableBL.TableStatus.TableCards[1].ToString(); table.ThirdCard = tableBL.TableStatus.TableCards[2].ToString(); table.FourthCard = tableBL.TableStatus.TableCards[3].ToString(); table.FifthCard = ""; break; case 5: table.FirstCard = tableBL.TableStatus.TableCards[0].ToString(); table.SecondCard = tableBL.TableStatus.TableCards[1].ToString(); table.ThirdCard = tableBL.TableStatus.TableCards[2].ToString(); table.FourthCard = tableBL.TableStatus.TableCards[3].ToString(); table.FifthCard = tableBL.TableStatus.TableCards[4].ToString(); break; } myTable.Id = Database.InsertTable(table); foreach (PokerTableBL mytable in Tables) { if (mytable.Id == myTable.Id) { for (int i = 0; i < mytable.Players.Count; i++) { Player player = new Player() { PokerTableId = mytable.Id, PlayerId = mytable.Players[i].PlayerId, PlayerName = mytable.Players[i].PlayerName, ChipsOnTable = mytable.Players[i].ChipsOnTable, FirstCard = mytable.Players[i].PersonalCards[0].ToString(), SecondCard = mytable.Players[i].PersonalCards[1].ToString() }; PlayerIds.Add(Database.InsertPlayer(player)); } } } switch (PlayerIds.Count) { case 1: table.Player1Id = PlayerIds[0]; break; case 2: table.Player1Id = PlayerIds[0]; table.Player2Id = PlayerIds[1]; break; case 3: table.Player1Id = PlayerIds[0]; table.Player2Id = PlayerIds[1]; table.Player3Id = PlayerIds[2]; break; case 4: table.Player1Id = PlayerIds[0]; table.Player2Id = PlayerIds[1]; table.Player3Id = PlayerIds[2]; table.Player4Id = PlayerIds[3]; break; case 5: table.Player1Id = PlayerIds[0]; table.Player2Id = PlayerIds[1]; table.Player3Id = PlayerIds[2]; table.Player4Id = PlayerIds[3]; table.Player5Id = PlayerIds[4]; break; } Database.UpdateTable(table); foreach (Move move in tableBL.Moves) { move.PokerTableId = myTable.Id; Database.InsertMove(move); } }
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); }