Esempio n. 1
0
        public Task <HttpResponseMessage> PostRegisterAsync(TopTrumpsPlayer player)
        {
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "register");

            message.Content = new StringContent(JsonConvert.SerializeObject(player.playerdetails), Encoding.UTF8, "application/json");
            return(httpClient.SendAsync(message));
        }
Esempio n. 2
0
        public ITopTrumpsResponse ListCards(ref TopTrumpsPlayer topTrumpsPlayer)
        {
            HttpResponseMessage httpResponseMessage = topTrumpsClient.GetCardsAsync(topTrumpsPlayer.playerid).Result;
            string             response             = httpResponseMessage.Content.ReadAsStringAsync().Result;
            ITopTrumpsResponse topTrumpsResponse    = null;

            switch (httpResponseMessage.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(response);
                topTrumpsResponse = errorResponse;
                break;

            case HttpStatusCode.OK:
                ListCardsResponse listCardsResponse = JsonConvert.DeserializeObject <ListCardsResponse>(response);
                topTrumpsPlayer.cards.Clear();
                foreach (Card card in listCardsResponse)
                {
                    topTrumpsPlayer.cards.Add(card);
                }
                topTrumpsResponse = listCardsResponse;
                break;

            default:
                break;
            }
            return(topTrumpsResponse);
        }
Esempio n. 3
0
        private void registerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string             name     = "player" + new Random().Next(1023);
            TopTrumpsPlayer    player   = new TopTrumpsPlayer(name, name + "@gmail.com", "1999-02-13");
            ITopTrumpsResponse response = this.topTrumpsGame.RegisterPlayer(ref player);

            if (IsError(response))
            {
                return;
            }
            this.players.Add(player);
            this.playersComboBox.SelectedItem = player;
        }
Esempio n. 4
0
        public ITopTrumpsResponse BuyCard(ref TopTrumpsPlayer topTrumpsPlayer)
        {
            HttpResponseMessage httpResponseMessage = topTrumpsClient.GetBuyCardAsync(topTrumpsPlayer.playerid).Result;
            string             response             = httpResponseMessage.Content.ReadAsStringAsync().Result;
            ITopTrumpsResponse topTrumpsResponse    = null;

            switch (httpResponseMessage.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(response);
                topTrumpsResponse = errorResponse;
                break;

            case HttpStatusCode.OK:
                Card card = JsonConvert.DeserializeObject <Card>(response);
                topTrumpsResponse = card;
                break;

            default:
                break;
            }
            return(topTrumpsResponse);
        }
Esempio n. 5
0
        public ITopTrumpsResponse Battle(TopTrumpsPlayer topTrumpsPlayer, Characteristic characteristic)
        {
            HttpResponseMessage httpResponseMessage = topTrumpsClient.PostBattleAsync(topTrumpsPlayer.playerid, characteristic).Result;
            string             response             = httpResponseMessage.Content.ReadAsStringAsync().Result;
            ITopTrumpsResponse topTrumpsResponse    = null;

            switch (httpResponseMessage.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(response);
                topTrumpsResponse = errorResponse;
                break;

            case HttpStatusCode.OK:
                BattleResponse battleResponse = JsonConvert.DeserializeObject <BattleResponse>(response);
                topTrumpsResponse = battleResponse;
                break;

            default:
                break;
            }
            return(topTrumpsResponse);
        }
Esempio n. 6
0
        public ITopTrumpsResponse GetProfile(ref TopTrumpsPlayer topTrumpsPlayer)
        {
            HttpResponseMessage httpResponseMessage = topTrumpsClient.GetProfileAsync(topTrumpsPlayer.playerid).Result;
            string             response             = httpResponseMessage.Content.ReadAsStringAsync().Result;
            ITopTrumpsResponse topTrumpsResponse    = null;

            switch (httpResponseMessage.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(response);
                topTrumpsResponse = errorResponse;
                break;

            case HttpStatusCode.OK:
                PlayerDetails playerDetails = JsonConvert.DeserializeObject <PlayerDetails>(response);
                topTrumpsPlayer.playerdetails = playerDetails;
                topTrumpsResponse             = playerDetails;
                break;

            default:
                break;
            }
            return(topTrumpsResponse);
        }
Esempio n. 7
0
 private void PlayersComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     this.player = this.players[this.playersComboBox.SelectedIndex];
     this.bindingSource1.DataSource = this.player.cards;
     this.dataGridView1.DataSource  = bindingSource1;
 }