Inheritance: StateClass
Example #1
0
 void Awake()
 {
     rigidbody = this.transform.GetComponent <Rigidbody>();
     moveState = new MoveState(this.transform.GetComponent <Rigidbody>(), this.transform.GetComponent <Animator>(), this.transform);
     hangState = new HangState(this.transform.GetComponent <Rigidbody>(), this.transform.GetComponent <Animator>(), this.transform);
     inventory = new Inventory(inventoryUI);
     inventoryUI.Setup(inventory);
     pState = moveState;
 }
 //Resetear paneles y controles
 private void ResetControls()
 {
     // Resetting things
     flowLayoutPanel1.Controls.Clear();
     AddButtons();
     CurrentHangState = HangState.Nada;
     panel1.Invalidate();
     txtWrongguesses.Clear();
     lblInfo.Text = "";
 }
Example #3
0
 private void ResetControls()
 {
     P_KeyBoard.Controls.Clear();
     KeyBoard();
     CurrentHangState = HangState.Waiting;
     PBX_Pics.Invalidate();
     L_WrongCount.Text  = "";
     L_Info.Text        = "";
     P_KeyBoard.Enabled = true;
 }
        //Acaba la ronda i/o la partida
        public void RecibirJugada2(int idOrigen, string user, int ronda, string mensajerecibido)
        {
            if (idOrigen == ID)
            {
                string[] trozos = mensajerecibido.Split('/');
                if (trozos[4] == "1" && trozos[2] != "NO")  //si la ronda ha acabado y alguien ha acertado la palabra
                {
                    char[] charArray = Palabra.ToCharArray();
                    for (int i = 0; i < Palabra.Length; i++)
                    {
                        if (charArray[i] == Convert.ToChar(trozos[5]))
                        {
                            labels[i].Text = trozos[5].ToString();
                        }
                        labels[i].BringToFront();
                    }
                }

                if (user != "NO")
                {
                    if (user == username)
                    {
                        lblInfo.ForeColor = Color.White;
                        lblInfo.Text      = "Buen trabajo " + username + "! Has adivinado la palabra. Ronda terminada!";
                        b.BackColor       = Color.Green;
                        lblInfo.ForeColor = Color.White;
                    }

                    else
                    {
                        lblInfo.ForeColor = Color.White;
                        lblInfo.Text      = user + " ha adivinado la palabra. Ronda terminada!";
                    }

                    jugadorqueescoge = ListaJugadores[ronda];


                    if (ronda == NumJugadores - 1)
                    {
                        turno = 0;
                    }

                    else
                    {
                        turno = ronda + 1;
                    }
                }

                else
                {
                    //Dibujar la ultima parte del muñeco
                    lblInfo.ForeColor = Color.Red;
                    lblInfo.Text      = "La habeis cagado. Ronda terminada! La palabra correcta era: " + Palabra;
                    if (CurrentHangState != HangState.PieSDerecho)
                    {
                        CurrentHangState++;
                    }
                    panel1.Invalidate();

                    if (user == username)
                    {
                        b.BackColor = Color.Red;
                    }

                    jugadorqueescoge = ListaJugadores[ronda];


                    if (ronda == NumJugadores - 1)
                    {
                        turno = 0;
                    }

                    else
                    {
                        turno = ronda + 1;
                    }
                }

                System.Threading.Thread.Sleep(2000); //damos tiempo a que el usuario lea el mensaje

                if (ronda != NumJugadores)           //Cuando acaba la partida no hay siguiente turno
                {
                    lblInfo.Text = "Prepárate! " + jugadorqueescoge + " escoge la palabra";
                    System.Threading.Thread.Sleep(2000); //damos tiempo a que el programa cree los formularios

                    if (username == jugadorqueescoge)
                    {
                        //Hacer invisible y disabled el teclado y visible y enabled el text box
                        PalabraText.Enabled      = true;
                        PalabraText.Visible      = true;
                        button1.Visible          = true;
                        button1.Enabled          = true;
                        flowLayoutPanel1.Enabled = false;
                        flowLayoutPanel1.Visible = false;
                    }

                    else
                    {
                        //Hacer invisible y disabled el text box y visible y disabled el teclado
                        PalabraText.Enabled      = false;
                        PalabraText.Visible      = false;
                        button1.Visible          = false;
                        button1.Enabled          = false;
                        flowLayoutPanel1.Enabled = false;
                        flowLayoutPanel1.Visible = true;
                    }

                    //Reseteo la configuracion de los botones
                    foreach (Button b in buttons)
                    {
                        b.BackColor = Color.White;
                        b.Enabled   = true;
                    }

                    //Reseteo la configuración de los labels

                    label4.Visible  = false;
                    label5.Visible  = false;
                    label6.Visible  = false;
                    label7.Visible  = false;
                    label8.Visible  = false;
                    label9.Visible  = false;
                    label10.Visible = false;
                    label11.Visible = false;
                    label12.Visible = false;
                    label13.Visible = false;
                    label14.Visible = false;
                    label15.Visible = false;
                    label16.Visible = false;

                    labels.Clear();                    //Vaciamos el vector de labels para la proxima ronda, pues no se ha acabado la partida

                    letrasescogidas.Clear();           //Resetea las letras escogidas en la ronda anterior
                    CurrentHangState = HangState.Nada; //Reseta el Hangman state
                    panel1.Invalidate();
                    txtWrongguesses.Clear();
                    lblInfo.Text         = "";
                    txtWordLen.Text      = "";
                    txtGuessesLeft.Text  = "";
                    txtWrongguesses.Text = "";
                }

                //MessageBox.Show("Soy el usuario " + username + " , es el turno: " + turno + " .El jugador que escoje es: " + jugadorqueescoge);
            }
        }
Example #5
0
        private void ClickFunctions_Click(object sender, EventArgs e)
        {
            Button b           = (Button)sender;
            char   charClicked = b.Text.ToCharArray()[0];

            b.Enabled = false;

            if ((currentWord = currentWord.ToUpper()).Contains(charClicked))
            {
                // char is there (right guess)
                L_Info.Text      = "Hea Valik!";
                L_Info.ForeColor = Color.Green;
                b.BackColor      = Color.LawnGreen;
                char[] charArray = currentWord.ToCharArray();
                for (int i = 0; i < currentWord.Length; i++)
                {
                    if (charArray[i] == charClicked)
                    {
                        labels[i].Text = charClicked.ToString();
                    }
                }

                // Winning condition
                if (labels.Where(x => x.Text.Equals(DefaultChar)).Any())
                {
                    return;
                }

                CurrentHangState = HangState.Win;
                Wins++;
                L_Wins.Text        = Wins.ToString();
                L_Info.ForeColor   = Color.Green;
                L_Info.Text        = "Võitsid!";
                P_KeyBoard.Enabled = false;
            }
            else
            {
                //WrongGuess
                L_Info.Text      = "Halb Valik...";
                L_Info.ForeColor = Color.Maroon;
                b.BackColor      = Color.Red;
                if (CurrentHangState != HangState.Lost)
                {
                    CurrentHangState++;
                }
                L_TryCount.Text        = (HangStateSize - (int)CurrentHangState).ToString();
                L_WrongCount.Text     += string.IsNullOrWhiteSpace(L_WrongCount.Text) ? charClicked.ToString() : "," + charClicked;
                L_WrongCount.ForeColor = Color.Red;

                PBX_Pics.Invalidate();

                if (CurrentHangState == HangState.Lost)
                {
                    Lost++;
                    L_Lost.Text        = Lost.ToString();
                    L_Info.Text        = "Kaotasid...";
                    L_Info.ForeColor   = Color.Maroon;
                    P_KeyBoard.Enabled = false;

                    //Reveal the word
                    for (int i = 0; i < currentWord.Length; i++)
                    {
                        if (labels[i].Text.Equals(DefaultChar))
                        {
                            labels[i].Text      = currentWord[i].ToString();
                            labels[i].ForeColor = Color.Red;
                        }
                    }
                }
            }
        }