El Ahorcado en C#

EL AHORCADO EN C#

Hola amigos como para estrenar mi blog les quiero poner el juego que me toco hacer hace rato en C#. Saben porque lo hago, porque talvez cuantos de uds al  igual que yo se lo dejaron de deber. Y que hicimos irlo a buscar al internet pero que lastima que no lo encontremos como lo queremos.

Entonces que paso me toco hacerlo, asi que se los voy a poner aqui para que no se maten buscando en otro lado.

Y talvez no es que no sabemos hacerlo si no que porque a veces no tenemos  tiempo, nos da pereza o simplemente vagancia.

Como soy estudiante al igual que uds, pero no importa ahi les va.

Ah por cierto el nombre que le di es EL AHORACADO no piense que ve equivoque.

——————————————————————————————————————————–

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Collections ;

namespace Ahoracado

{

  

 public partial class frmjuego : Form

    {

/// <summary>

/// DECLARACIONES DE VECTORES Y VARIABLES

/// </summary>

 

#region DECLARACIONES DE VARIABLES

        Dictionary<int, char> frase ;

        char[] fraseFinal ;

        string[] vectortotal = new string[10];

        string[] animales = new string[10];

        string[] cosas = new string[10];

        string[] marcas = new string[10];

        string[] nombres = new string[10];

        string[] colores = new string[10];

        string[] paises = new string[10];

        int i, y, a, tamaño, j, x = -1 , contador, contador1;

        string secreta;

        int superior = 9; int inferior = 0;

        Random rand = new Random();

#endregion

 

        public frmjuego()

        {

            InitializeComponent();    

        }

 

   private void frmjuego_Load(object sender, EventArgs e)

        {

            label3.Visible = false;

 

/// <summary>

/// AGREGACION DE VECTORES

/// </summary>

#region Vectores

            animales[0] = “AGUILA”;

            animales[1] = “BISONTE”;

            animales[2] = “IMPALA”;

            animales[3] = “ZORZAL”;

           

            marcas[0] = “LACOSTE”;

            marcas[1] = “DIESEL”;

            marcas[2] = “WILSON”;

            marcas[3] = “NIKE”;

           

            cosas[0] = “RELOJ”;

            cosas[1] = “CAMISETILLAS”;

            cosas[2] = “PILAS”;

            cosas[3] = “LINTERNA”;

 

            nombres[0] = “ISAAC”;

            nombres[1] = “JOHANNA”;

            nombres[2] = “CLAUDIO”;

            nombres[3] = “JENIFFER”;

           

            paises[0] = “COMOROS”;

            paises[1] = “GROELANDIA”;

            paises[2] = “NICARAGUA”;

            paises[3] = “ECUADOR”;

 

            colores[0] = “CYAN”;

            colores[1] = “PLATEADO”;

            colores[2] = “DORADO”;

            colores[3] = “PURPURA”;

           

#endregion

        }

 

        public void btnJugar_Click(object sender, EventArgs e)

        {

            tiempo.Value = 0;

            timer.Stop();

            timer.Start();

            pictureBox1.Visible = true;

            label1.Text = ” “;

            lblvocales.Text = ” “;

            label3.Visible = true;

            pictureBox7.Visible = false;

            pictureBox2.Visible = false;

            pictureBox3.Visible = false;

            pictureBox4.Visible = false;

            pictureBox5.Visible = false;

            pictureBox6.Visible = false;

            btnadivinar.Enabled = true;

            txtadivinar.Enabled = true;

 

 

            /// <summary>

            /// SELECCION DE CATEGORIAS PARA JUGAR

            /// (SELECCION DE VECTOR)

            /// </summary>

 #region SELECCION DE CATEGORIAS

             switch (cmbcategoria.Text)

                {

                    case “Animales”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = animales[j];

                            tamaño = secreta.Length;

                            break;

                        }

                    case “Cosas”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = cosas[j];

                            tamaño = secreta.Length;

                            break;

                        }

                    case “Colores”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = colores[j];

                            tamaño = secreta.Length;

                            break;

                        }

                    case “Nombres de Personas”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = nombres[j];

                            tamaño = secreta.Length;

                            break;

                        }

                    case “Marcas”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = marcas[j];

                            tamaño = secreta.Length;

                            break;

                        }

                    case “Paises”:

                        {

                            j = (int)(Math.Floor((superior – inferior + 1) * rand.NextDouble() + inferior));

                            secreta = paises[j];

                            tamaño = secreta.Length;

                            break;

                        }

                }

 

                string[] totalvector = new string[tamaño];

                for (int i = 0; i < secreta.Length; i++)

                {

                    label1.Text = label1.Text +  ” – “;

                   

                }

                frase = new Dictionary<int, char>();

                CargarFraseDictionary();

                fraseFinal = new char[frase.Count];

 

                foreach (KeyValuePair<int, char> var in frase)

                {

                    fraseFinal[var.Key] = ‘-’;

                }

                contador1 = 0;

               }

          

#endregion

 

 

 

            private void mensajeGanador()

            {

                string mensaje=“”;

                 foreach (char var1 in label1.Text)

                 {

                     if (var1!=‘ ‘ && var1!=‘-’)

                     {

                         mensaje += var1;  

                     }   

                 }

                 if (mensaje==secreta)

                 {

                     MessageBox.Show(“GANASTE!!!!!!!!!!”,“FELICIDADES”);

                     timer.Stop();

                     tiempo.Value = 0;

                     label1.Text = secreta;

                     pictureBox1.Visible = true;

                     pictureBox2.Visible = false ;

                     pictureBox3.Visible = false;

                     pictureBox4.Visible = false;

                     pictureBox5.Visible = false;

                     pictureBox6.Visible = false;

                     pictureBox7.Visible = false;

                     btnadivinar.Enabled = false;

                     txtadivinar.Enabled = false;

                     txtadivinar.Text = “”;

                     lblvocales.Text = “”;

                     label1.Text = ” “;

                 }   

            }

 

 

        private void button30_Click(object sender, EventArgs e)

        {

           // mensajeGanador();

            if (txtadivinar.Text != “”)

            {

                lblvocales.Text = txtadivinar.Text + ” “ + lblvocales.Text;

                int bandera = 0;

                label1.Text = “”;

 

                foreach (KeyValuePair<int, char> var in frase)

                {

                    if (fraseFinal[var.Key] == ‘-’)

                    {

                        if (var.Value == char.Parse(txtadivinar.Text))

                        {

                            fraseFinal[var.Key] = var.Value;

                            bandera = 1;

                        }

                        else

                            fraseFinal[var.Key] = ‘-’;

                    }

                }

 

                foreach (Char var in fraseFinal)

                {

                    i++;

                    label1.Text += ” “ + var;

                }

 

                if (bandera == 0)

                {

                    contador1++;

                    DibujarGrafico();

                }

                txtadivinar.Text = “”;

            }

            else

                MessageBox.Show(“Ingrese Caracter”, “Error”);

            mensajeGanador();   

      }

 

 

        /// <summary>

        /// para ir cargando el dibujo dependiendo del error

        /// </summary>

 

      #region dibujar grafico

 

      private void DibujarGrafico()

      {

          if (contador == secreta.Length)

          {

              contador1 = contador1 + 1;

              txtadivinar.Text = “”;

          }

          if (contador1 == 1)

          {

              pictureBox1.Visible = false;

              pictureBox2.Visible = true;

              txtadivinar.Text = “”;

          }

          else if (contador1 == 2)

          {

              pictureBox2.Visible = false;

              pictureBox3.Visible = true;

              txtadivinar.Text = “”;

          }

          else if (contador1 == 3)

          {

              pictureBox3.Visible = false;

              pictureBox4.Visible = true;

              txtadivinar.Text = “”;

          }

          else if (contador1 == 4)

          {

              pictureBox4.Visible = false;

              pictureBox5.Visible = true;

              txtadivinar.Text = “”;

          }

          else if (contador1 == 5)

          {

              pictureBox5.Visible = false;

              pictureBox6.Visible = true;

              txtadivinar.Text = “”;

          }

          else if (contador1 == 6)

          {

              pictureBox1.Visible = true;

              label1.Text = secreta;

              pictureBox6.Visible = false;

              pictureBox7.Visible = true;

              btnadivinar.Enabled = false;

              txtadivinar.Enabled = false;

              MessageBox.Show(“Ahorcado… Perdiste el juego”, secreta);

              txtadivinar.Text = “”;

              lblvocales.Text = “”;

              label1.Text = ” “;

              pictureBox7.Visible = false;

              pictureBox1.Visible = true;

          }

      }

      #endregion

 

        private void CargarFraseDictionary()

        {

            int indice = -1;

            foreach (char var in secreta)

            {

                indice++;

                frase.Add(indice, var);

            }

        }

 

 

        private void intruccionesToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Form2 f2 = new Form2();

            f2.Show();

        }

 

        private void creditosToolStripMenuItem_Click(object sender, EventArgs e)

        {

            creditos f4 = new creditos();

            f4.Show();

        }

 

        private void timer1_Tick(object sender, EventArgs e)

        {

            tiempo.Value += 1;

            if (tiempo.Value == 100)

            {

                timer.Stop();

                MessageBox.Show(“Se te termino el tiempo…. ¡PeRdIsTeS¡”, “JaJaJaJa”);

                tiempo.Value = 0;

                pictureBox1.Visible = true;

                label1.Text = secreta;

                pictureBox6.Visible = false;

                pictureBox7.Visible = true;

                btnadivinar.Enabled = false;

                txtadivinar.Enabled = false;

                txtadivinar.Text = “”;

                lblvocales.Text = “”;

                label1.Text = ” “;

                pictureBox7.Visible = false;

                pictureBox1.Visible = true;

                MessageBox.Show(“Seleccione Categoria”, “JaJaJaJa”);

            }

        }

      }

 

Listo amigos ya tienen el 10 aceguradito ahí le toca no mas mejorarle cositas y etc….

Asi hubiera querido conseguir uno

 

Advertisement

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s


Seguir

Get every new post delivered to your Inbox.