Click Here! Juego el Ahorcado c# | Programacion orientada a objetos

Gana dinero por compartir tus enlaces!
Click Here! Click Here!

Juego el Ahorcado c#


Desarrollar en siguiente programa en C#

La empresa de videojuegos “ZANZAN”, necesita desarrollar un juego del ahorcado, el cual debe contener los siguiente: - El usuario administrador deberá y podrá ingresar las palabras con que el usuario jugador podrá jugar, y estas deberán ser ingresadas por teclado. - También el juego permitirá cargar un grupo de palabras por medio de un archivo. - Las opciones del juego será de la siguiente forma:

o Menú Ítems
o Cargar palabras por el usuario
o Cargar palabras por archivo
o Jugar Ahorcado.

Solución 

//Clase #1
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZanzanAhorcadoD
{
    public partial class IngresarPalabra
    {
        int cantiPalabras;
        string[] palabras ;
        public void ingresarPalabra()
        {
Click Here!             Console.Write("\nIngrese la cantidad de palabras que va tener el juego : \n");
            cantiPalabras = int.Parse(Console.ReadLine());
            palabras = new string[cantiPalabras];
            Console.Clear();
            Console.Write("Ingrese las...{0}...palabras con que el usuario va jugar : \n", cantiPalabras);
            for (int i = 0; i < palabras.Length; i++)
            {
                palabras[i] = Console.ReadLine();
            }
        }
        int i = 0;
        public void datosArchivo()
        {
  var archivo = "C:\\Users\\Jailer viveros\\Documents\\Visual Studio              2015\\Projects\\ZanzanAhorcadoD\\PalabrasJuego.txt";
            using (StreamReader PalabrasJuego = new StreamReader(archivo))
            {
           string linea = PalabrasJuego.ReadLine();
                Console.Write("las Palabras cargadas fueron \n");
               Console.WriteLine(linea);
                palabras = new string[2];
                palabras[0] = linea;
                  
                do
                {
                    linea = PalabrasJuego.ReadLine();
                    if (linea != null)
                        palabras[1] = linea;

                    Console.WriteLine(linea);
                  } while (linea != null);
            }
        }
        public string palabraSelccionada(string palabraAleatoria)
        {
            Random nroaleatorio = new Random();
            palabraAleatoria = palabras[nroaleatorio.Next(0,2)];
            return palabraAleatoria;
        }
    }
}
 Click aqui para descargar proyecto
//Clase #2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZanzanAhorcadoD
{
    public partial class DibujandoAhorcado
    {
    
        public  string[,] dibujo(string[,] matriz, int intentos)
        {
            Console.Clear();
            for (int i = 0; i < matriz.GetLength(0); i++)
            {
                for (int k = 0; k < matriz.GetLength(1); k++)
                {
                    matriz[i, k] = " ";
                }
            }
            for (int i = 0; i < 6; i++) matriz[0, i] = "_";
            for (int k = 1; k < 7; k++) matriz[k, 1] = "|";
            for (int j = 0; j < 6; j++) matriz[7, j] = "_";
            if (intentos >= 1) matriz[3, 4] = "O";
            if (intentos >= 2) matriz[4, 4] = "|";
            if (intentos >= 3) matriz[5, 3] = "/";
            if (intentos >= 4) matriz[5, 5] = "l";
            if (intentos >= 5) matriz[4, 3] = "-";
            if (intentos >= 6) matriz[4, 5] = "-";
            matriz[1, 4] = "|";
            matriz[2, 4] = "|";
            return matriz;
        }
    }
}               
            Click aqui para descargar proyecto             
//Clase Principal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZanzanAhorcadoD
{
    class Program
    {
        static void Main(string[] args)
        {
            DibujandoAhorcado dibujando = new DibujandoAhorcado();
            IngresarPalabra palabraAleatoria = new IngresarPalabra();
          
            string[,] matriz = new string[8, 6];
            string palabra = "null";
            bool jugar = true;
            int intentos = 0;
            string letra = " ";
            char Letrachar = ' ';
            string volverjugar = " ";
            int Gano = 0;
            int contador = 0; // para saber si la letra que se escrivio si estaba en la palabra
            int opcion = 0;

            do
            {
                Console.WriteLine("\n Menu items");
                Console.WriteLine("\n 1. Cargar palabras por el usuario");
                Console.WriteLine("\n 2. Cargar palabras por archivo");
                Console.WriteLine("\n 3. Jugar ahorcado");
                Console.WriteLine("\n 4. Salir");

                opcion = int.Parse(Console.ReadLine());
                Console.Clear();

                switch (opcion)
                {

                    case 1:
                        //metodo que permite al administrador ingresar las palabras
                         palabraAleatoria.ingresarPalabra();
                        Console.Clear();
                        break;
                    case 2:
                        palabraAleatoria.datosArchivo();
                        break;
                    case 3:
                        while (jugar == true)
                        {
                            palabra = palabraAleatoria.palabraSelccionada(palabra);
                            char[] palabravector = palabra.ToCharArray();
                            char[] espaciosEnBlanco = new char[palabra.Length];
                            for (int i = 0; i < palabra.Length; i++) espaciosEnBlanco[i] = '_';
                            Gano = 0;
                            while (intentos <= 6)
                            {
                                // para saber si la letra ingresadda fue solo una y si se puede convertir en char
                                bool letraMayorQueUno = true;
                                dibujando.dibujo(matriz, intentos);
                                MostrarMatriz(matriz);
                                Console.WriteLine();
                                MostrarEpaciosEnBlanco(espaciosEnBlanco);
                                Console.WriteLine();
                                while (letraMayorQueUno == true)
                                {
                                    Console.Write("dijite la letra: ");
                                    letra = Console.ReadLine();
                                    if (letra.Length == 1)
                                    {
                                        Letrachar = Convert.ToChar(letra);
                                        letraMayorQueUno = false;
                                    }
                                }

                                for (int i = 0; i < espaciosEnBlanco.Length; i++)
                                {
                                    if (Letrachar == espaciosEnBlanco[i])
                                    {
                                        Console.WriteLine("esa letra ya estaba escrivir otra");
                                        Console.ReadKey();
                                        contador++;
                                    }
                                    else
                                    {
                                        if (Letrachar == palabravector[i])
                                        {
                                            espaciosEnBlanco[i] = Letrachar;
                                            contador++;
                                            Gano++;
                                        }
                                    }
                                }
                                if (contador == 0)
                                {
                                    intentos++;
                                }
                                if (Gano == palabra.Length) break;
                                else contador = 0;
                            }
                            if (Gano == palabra.Length)
                            {
                                dibujando.dibujo(matriz, intentos);
                                MostrarMatriz(matriz);
                                Console.WriteLine();
                                MostrarEpaciosEnBlanco(espaciosEnBlanco);
                                Console.WriteLine();
                                Console.WriteLine("¡FELICIRACIONES!... la palabra era {0} ganaste!! quieres                                 volver a jugar : S / N", palabra);
                                volverjugar = Console.ReadLine();
                                if (volverjugar == "n") jugar = false;
                                else intentos = 0;

                            }
                            else
                            {
                             Console.WriteLine("se te acabaron los intentos la palabra era {0} quieres juegar                                    de nuevo : S /  N", palabra);
                                volverjugar = Console.ReadLine();
                                if (volverjugar == "n") jugar = false;

                                else intentos = 0;
                            }
                        }
                        break;
                    case 4:
                    default:
                        Console.WriteLine("\n Escriba una opcion valida");
                        Console.ReadKey();

                        break;
                }
            } while (opcion != 4);
            Console.ReadKey();
        }

       public static void MostrarEpaciosEnBlanco(char[] Espacios)
        {
            for (int i = 0; i < Espacios.Length; i++)
            {
                Console.Write(Espacios[i] + " ");
            }
        }
        public static void MostrarMatriz(string[,] matriz)
        {
            int pasarcolumnna = 0;
            int pasarfila = 0;
            while (pasarfila <= 7)
            {
                while (pasarcolumnna <= 5)
                {
                    Console.Write(matriz[pasarfila, pasarcolumnna]);
                    pasarcolumnna++;
                    if (pasarcolumnna > 5)
                        Console.WriteLine();
                }
                pasarcolumnna = 0;
                pasarfila++;
            }
        }
    }
}  
                                      Click aqui para descargar proyecto                                     

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
Click Here!
Click Here!
    Blogger Comment
    Facebook Comment

0 comentarios:

Publicar un comentario