Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
        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);
            }
        }