Ejemplo n.º 1
0
        public void Showdown()
        {
            delUpdateUITurn delUpdateUITurn = new delUpdateUITurn(UpdateUITurn);

            var message  = "http://" + client.apiAddress + ":" + client.apiPort + "/table/" + client.tableCode + "/showdown";
            var response = client.MakeRequest(message, 0)[0];
            List <ShowdownSchema> showdownresp = new List <ShowdownSchema>();

            showdownresp = JsonConvert.DeserializeObject <List <ShowdownSchema> >(response);
            if (showdownresp != null)
            {
                for (int i = 0; i < showdownresp.Count; i++)
                {
                    this.turnLabel.BeginInvoke(delUpdateUITurn, "Koniec Rundy");
                    var schema = showdownresp[i];
                    int pot    = schema.pot + 1;
                    var prefix = "";
                    //if (schema.winners.Count > 1)
                    //{
                    //    prefix = "Wygrali:";
                    //}
                    //else
                    //{
                    //     prefix = "Wygrał: ";
                    //}
                    var winners = string.Join(", ", schema.winners);
                    winners = prefix + winners;
                    delUpadateUIPools delUpadateUIPools = new delUpadateUIPools(UpdateUIPool);
                    poolAmounts[schema.pot].BeginInvoke(delUpadateUIPools, new object[] { i, winners, 0 });
                    if (schema.players_hands != null)
                    {
                        for (int j = 0; j < schema.players_hands.Count; j++)//RĘCE GRACZY
                        {
                            var cards = schema.players_hands;
                            foreach (var item in cards)//GRACZE
                            {
                                int k = 0;
                                for (k = 0; k < labels.Count; k++)  //SZUKANIE GRACZA
                                {
                                    if (labels[k].Text == item.Key) //PRZYPISYWANIE WARTOŚCI RĘKI DO TEKSTU
                                    {
                                        delUpdateUIPoints2 delUpdateUIPoints = new delUpdateUIPoints2(UpdateUIPoints2);

                                        string type = GetHand(item.Value.hand_type);
                                        this.money[k].BeginInvoke(delUpdateUIPoints, new object[] { type, k });
                                        var rank = item.Value.hand[0].rank;
                                        var suit = item.Value.hand[0].suit;
                                        suit = suit.Replace("hearts", "H");
                                        suit = suit.Replace("diamonds", "D");
                                        suit = suit.Replace("spades", "S");
                                        suit = suit.Replace("clubs", "C");
                                        var            card           = rank + suit;
                                        var            directory      = "";
                                        delUpdateCards delUpdateCards = new delUpdateCards(UpdateCards);
                                        if (card != "null")
                                        {
                                            directory = client.path + card + ".png";

                                            this.cards[k * 2].BeginInvoke(delUpdateCards, new object[] { k * 2, directory });
                                        }
                                        rank = item.Value.hand[1].rank;
                                        suit = item.Value.hand[1].suit;
                                        suit = suit.Replace("hearts", "H");
                                        suit = suit.Replace("diamonds", "D");
                                        suit = suit.Replace("spades", "S");
                                        suit = suit.Replace("clubs", "C");
                                        card = rank + suit;
                                        if (card != "null")
                                        {
                                            directory = client.path + card + ".png";
                                            this.cards[k * 2 + 1].BeginInvoke(delUpdateCards, new object[] { k * 2 + 1, directory });
                                        }
                                        break;
                                    }
                                }
                            }

                            // cards[j].
                        }
                    }

                    //schema.players_hands
                }
            }
            else
            {
                showdown = false;
            }
        }
Ejemplo n.º 2
0
        private void CheckGameStatus()
        {
            while (true)
            {
                var    message = "http://" + client.apiAddress + ":" + client.apiPort + "/table/" + client.tableCode + "?playerID=" + client.userCode;
                string table   = client.MakeRequest(message, 0)[0];
                //table = table.Replace()
                table = Regex.Replace(table, @"[^0-9a-zA-Z:,_[+\]]", "");

                var MyTable = table.Split(':', ',');
                client.game.Load(MyTable);
                //UPDATE puli, posiadanej kasy, zaznaczenie aktywnego użytkownika
                var cards = client.game.Cards;
                //var pool = client.game.Pool;
                var players = client.game.Players;

                if (players.Count() < 2 && !end)
                {
                    MessageBox.Show("Wszyscy gracze wyszli. Opuść rozgrywkę.");
                    end = true;
                    delReturnButton delReturnButton = new delReturnButton(updateReturnButton);
                    this.mainMenu.BeginInvoke(delReturnButton);
                    break;
                }
                else if (end)
                {
                    break;
                }


                //jeśli playerów jest 1 to wtedy zamknij
                var turn      = client.game.Turn;
                var gamePools = client.game.Pools;
                if (players != null && players.Count > 0)
                {
                    while (players[0].name != client.userName)
                    {
                        var player = players[0];
                        players.RemoveAt(0);
                        players.Add(player);
                    }
                    if (!showdown)
                    {
                        delUpdateUILabel       delUpdateUILabel       = new delUpdateUILabel(UpdateUILabel);
                        delUpdateUIPoints      delUpdateUIPoints      = new delUpdateUIPoints(UpdateUIPoints);
                        delUpdateUIPool        delUpdateUIPool        = new delUpdateUIPool(UpdateUIPool);
                        delUpdateUITurn        delUpdateUITurn        = new delUpdateUITurn(UpdateUITurn);
                        delUpdateUISharedCards delUpdateUISharedCards = new delUpdateUISharedCards(UpdateUISharedCards);
                        delUpadateUIPools      delUpadateUIPools      = new delUpadateUIPools(UpdateUIPool);
                        delUpdateUIPoolNames   delUpdateUIPoolNames   = new delUpdateUIPoolNames(UpdateUIPoolNames);
                        this.turnLabel.BeginInvoke(delUpdateUITurn, turn);
                        // this.poolLabel1.BeginInvoke(delUpdateUIPool, pool);
                        for (int i = 0; i < gamePools.Count; i++)
                        {
                            this.pools[i].BeginInvoke(delUpdateUIPoolNames, i, 0);
                            this.poolAmounts[i].BeginInvoke(delUpadateUIPools, i, gamePools[i].amount, 0);
                            if (gamePools[i].members.Contains(client.userName))
                            {
                                this.pools[i].BeginInvoke(delUpdateUIPoolNames, i, 1);
                                this.poolAmounts[i].BeginInvoke(delUpadateUIPools, i, gamePools[i].amount, 1);
                            }
                            else
                            {
                                this.pools[i].BeginInvoke(delUpdateUIPoolNames, i, 3);
                                this.poolAmounts[i].BeginInvoke(delUpadateUIPools, i, gamePools[i].amount, 3);
                            }

                            // this.poolAmounts[i].
                        }
                        for (int i = 0; i < 6; i++)
                        {
                            this.labels[i].BeginInvoke(delUpdateUILabel, players, i);
                        }
                        for (int i = 0; i < 6; i++)
                        {
                            this.money[i].BeginInvoke(delUpdateUIPoints, players, i);
                        }
                        for (int i = 0; i < cards.Count; i++)
                        {
                            this.sharedCards[i].BeginInvoke(delUpdateUISharedCards, cards, i);
                        }
                    }
                }

                //this.labels.BeginInvoke()
                Thread.Sleep(1000);
            }
        }