예제 #1
0
        private void battleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.player == null)
            {
                return;
            }
            ITopTrumpsResponse response = this.topTrumpsGame.Battle(this.player, (Characteristic)this.characteristicComboBox.SelectedItem);

            if (IsError(response))
            {
                return;
            }
            BattleResponse battleResponse = response as BattleResponse;

            if (battleResponse != null)
            {
                //MessageBox.Show(String.Format("{0} vs. {1}", battleResponse.card.name, battleResponse.opponentCard.name), battleResponse.outcome);
                this.topTrumpsGame.ListCards(ref this.player);
            }
        }
예제 #2
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);
        }