コード例 #1
0
ファイル: JokenpoHttp.cs プロジェクト: ederzed/HttpTeste
        public Jogo getHttp()
        {
            var requisicaoWeb = WebRequest.CreateHttp("https://api.myjson.com/bins/v5ck6");

            requisicaoWeb.Method    = "GET";
            requisicaoWeb.UserAgent = "RequisicaoWebDemo";

            using (var resposta = requisicaoWeb.GetResponse())
            {
                var          streamDados = resposta.GetResponseStream();
                StreamReader reader      = new StreamReader(streamDados);
                object       objResponse = reader.ReadToEnd();

                Jogo j = JsonConvert.DeserializeObject <Jogo>(objResponse.ToString());



                streamDados.Close();
                resposta.Close();

                return(j);
            }
        }
コード例 #2
0
ファイル: JokenpoHttp.cs プロジェクト: ederzed/HttpTeste
        private void tmResultado_Tick(object sender, EventArgs e)
        {
            Jogo result = getHttp();

            if (result.confirmado == 3)
            {
                putHttp("-", "-", 0);
                player            = 0;
                jogada            = "";
                lblResultado.Text = "Aguardando conexão";
                jp1 = null;
                jp2 = null;
                btnConectar.Enabled = true;
                btnPapel.Enabled    = false;
                btnPedra.Enabled    = false;
                btnTesoura.Enabled  = false;
                btnConfirma.Enabled = false;
                tmResultado.Enabled = false;
            }
            if (result.confirmado == 2)
            {
                if (player == 1)
                {
                    if (result.player2 == "tesoura")
                    {
                        jp2 = Properties.Resources.tesouraop;
                        pbPlayer2.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer2.Image    = jp2;
                    }
                    if (result.player2 == "pedra")
                    {
                        jp2 = Properties.Resources.pedraop;
                        pbPlayer2.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer2.Image    = jp2;
                    }
                    if (result.player2 == "papel")
                    {
                        jp2 = Properties.Resources.papelop;
                        pbPlayer2.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer2.Image    = jp2;
                    }
                }
                else
                {
                    if (result.player1 == "tesoura")
                    {
                        jp1 = Properties.Resources.tesoura;
                        pbPlayer1.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer1.Image    = jp1;
                    }
                    if (result.player1 == "pedra")
                    {
                        jp1 = Properties.Resources.pedra;
                        pbPlayer1.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer1.Image    = jp1;
                    }
                    if (result.player1 == "papel")
                    {
                        jp1 = Properties.Resources.papel;
                        pbPlayer1.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbPlayer1.Image    = jp1;
                    }
                }
                if (checarResultado(result) == 0)
                {
                    lblResultado.Text = "Você perdeu. Aguarde para jogar novamente";
                }
                if (checarResultado(result) == 1)
                {
                    lblResultado.Text = "Você venceu. Aguarde para jogar novamente";
                }
                if (checarResultado(result) == 2)
                {
                    lblResultado.Text = "Empate. Aguarde para jogar novamente";
                }
                putHttp("-", "-", 3);
            }
        }