Exemple #1
0
        private void Beginbutton_Click(object sender, EventArgs e)
        {
            try
            {
                client    = new TcpClient(this.ServertextBox.Text, 2000);
                ns        = client.GetStream();
                sr        = new StreamReader(ns);
                sw        = new StreamWriter(ns);
                idJugador = client.Client.LocalEndPoint.ToString();

                sw.WriteLine("#INSCRIBIR#" + this.PlayertextBox.Text + "#");
                sw.Flush();
                dato += sr.ReadLine();

                DelegadoRespuesta dr = new DelegadoRespuesta(EscribirFormulario);
                this.Invoke(dr);

                string[] str = sr.ReadLine().Split('/');
                cartasMesa[0] = str[0];
                cartasMesa[1] = str[1];
                cartasMesa[2] = str[2];
                cartasMesa[3] = str[3];
                for (int i = 0; i < cartasMesa.Length; i++)
                {
                    printCardTable(i);
                }

                sw.WriteLine("#REPARTECARTAS#");
                sw.Flush();

                str          = sr.ReadLine().Split('/');
                cartasJug[0] = str[0];
                cartasJug[1] = str[1];
                cartasJug[2] = str[2];
                for (int i = 0; i < cartasJug.Length; i++)
                {
                    printCardPlayer(i);
                }


                PlayerPanel.Visible        = true;
                TableroPanel.Visible       = true;
                MessagePanel.Visible       = true;
                PanelConfiguration.Enabled = false;

                Turnotimer.Enabled = true;
                sw.WriteLine("#TURNO#");
                sw.Flush();
                turnoId = sr.ReadLine().Split('#');
                if (turnoId[1].Equals(idJugador))
                {
                    EnterButton.Enabled = true;
                }
                turno = turnoId[1];
                MessageTextBox.Text += turno + Environment.NewLine;
                CheckCardstimer.Start();
            }
            catch (Exception error)
            {
                Console.WriteLine("Error: " + error.ToString());
            }
        }
Exemple #2
0
        private void EnterButton_Click(object sender, EventArgs e)
        {
            if (turno.Equals(idJugador))
            {
                Button b = buttonClicked.Find(h => h.Name.StartsWith("Player"));

                if (buttonClicked.Count == 1 && buttonClicked.Contains(b))
                {
                    //Colocar carta jugador en la mesa
                    string mesaActualizada = "";

                    for (int i = 0; i < cartasMesa.Length; i++)
                    {
                        if (String.IsNullOrEmpty(cartasMesa[i]))
                        {
                            cartasMesa[i] = GetNameCardPlayer(b.Name.Substring(6));
                            printCardTable(i);
                            b.Visible = false;
                            break;
                        }
                    }
                    for (int x = 0; x < cartasMesa.Length; x++)
                    {
                        if (!String.IsNullOrEmpty(cartasMesa[x]))
                        {
                            mesaActualizada += cartasMesa[x] + "/";
                        }
                    }
                    sw.WriteLine("#JUGADA#0#" + mesaActualizada);
                    sw.Flush();
                    EnterButton.Enabled = false;
                }
                else
                {
                    sw.WriteLine(GetJugada());
                    sw.Flush();
                    string d = sr.ReadLine();
                    if (d.Equals("No se puede hacer baza. Intentalo de nuevo"))
                    {
                        MessageBox.Show(d, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        foreach (Button button in buttonClicked)
                        {
                            button.FlatAppearance.BorderSize = 1;
                            button.FlatStyle = FlatStyle.Standard;
                        }
                    }
                    else
                    {
                        foreach (Button button in buttonClicked)
                        {
                            button.BackgroundImage = null;
                        }
                        string[] points = sr.ReadLine().Split('#');

                        numCartas += Convert.ToInt16(points[0]);
                        oros      += Convert.ToInt16(points[1]);
                        sietes    += Convert.ToInt16(points[2]);
                        sieteOros += Convert.ToInt16(points[3]);

                        NumCartastextBox2.Text = numCartas.ToString();
                        OrostextBox3.Text      = oros.ToString();
                        SietestextBox4.Text    = sietes.ToString();
                        SieteOrostextBox5.Text = sieteOros.ToString();

                        MessageTextBox.Text += d + Environment.NewLine;
                        EnterButton.Enabled  = false;
                        string mesaActualizada = "";
                        RemoveCardsTable();

                        for (int i = 0; i < cartasMesa.Length; i++)
                        {
                            if (!String.IsNullOrEmpty(cartasMesa[i]))
                            {
                                mesaActualizada += cartasMesa[i] + "/";
                            }
                        }
                        sw.WriteLine("#UPDATETABLE#" + mesaActualizada);
                        sw.Flush();
                    }
                }
                MessageTextBox.Text += GetNumCardsTable() + Environment.NewLine;
                buttonClicked.Clear();
                CheckCardstimer.Enabled = true;
                CheckCardstimer.Start();
            }
        }