Esempio n. 1
0
        // Sit on table Api
        public async void SitOnTableApi(int id)
        {
            Double _minBetTable = 0;

            foreach (var item in ListTable)
            {
                if (item.Id == id)
                {
                    _minBetTable = item.Min_bet;
                }
            }

            if (this.Api.user.stack >= _minBetTable)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://demo.comte.re");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this._api.token.access_token);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response = await client.GetAsync("/api/user/" + this.Api.user.email + "/table/" + id + "/sit");

                    //Debug.WriteLine(response);
                    string res = await response.Content.ReadAsStringAsync();

                    //Debug.WriteLine(res);



                    if (response.IsSuccessStatusCode)
                    {
                        TableToGameNav navParam = null;
                        foreach (var item in _listTable)
                        {
                            if (item.Id == id)
                            {
                                navParam = new TableToGameNav(this.Api, item);
                            }
                        }

                        currentFrame.Navigate(typeof(GameView), navParam);
                    }
                    else if (response.IsSuccessStatusCode != true)
                    {
                        ErrorApi erAp = new ErrorApi();
                        erAp = JsonConvert.DeserializeObject <ErrorApi>(res);
                        if (erAp.Error_code == "user_already_on_table")
                        {
                            LeaveTable(id);
                        }
                    }
                }
            }
            else
            {
                this.dialog = new MessageDialog("Votre Stack est insufisant pour cette table");
                BadTextBox(this.dialog);
            }
        }
Esempio n. 2
0
        public GameViewModel(TableToGameNav nav)
        {
            this.Nav        = nav;
            this.MyGame     = new Game();
            this.MyUser     = this.Nav.MyApi.user;
            this._indexList = 0;
            this.GameTable  = nav.GameTable;

            // guive a new hand
            this.MyUser.UserHands.Add(new UserHand(this.Nav.GameTable.Min_bet));
            this.MyUser.stack -= this.Nav.GameTable.Min_bet;


            //set Bank player
            this.Bank = new User();
            this.Bank.UserHands.Add(new UserHand());

            //2 starting cards for player and 1 for bank
            ResetPlayerHand();
            GetCard(Bank.UserHands[0]);
            GetCard(MyUser.UserHands[0]);
            GetCard(MyUser.UserHands[0]);
        }