How to create a small game in C#(console base) ?

Total Post:44

Points:310
C#  OOPS 
C#
 542  View(s)
Ratings:
Rate this:

Like HangMan Game...

  1. Post:87

    Points:615
    Re: How to create a small game in C#(console base) ?

    using System;
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication18
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(" **** Welcome to Hangman **** ");
                string[] listwords = new string[10];
                listwords[0] = "cow";
                listwords[1] = "mango";
                listwords[2] = "sanat";
                listwords[3] = "india";
                listwords[4] = "aditya";
                listwords[5] = "arti";
                listwords[6] = "harsh";
                listwords[7] = "bachchalal";
                listwords[8] = "mindstick";
                listwords[9] = "shukla";
                Random rndmGen = new Random();
                var id_x = rndmGen.Next(0, 9);
                string mysecretWord = listwords[id_x];
                char[] guess = new char[mysecretWord.Length];
                Console.Write("\tPlease Enter your guess(word): ");

                for (int z = 0; z < mysecretWord.Length; z++)
                    guess[z] = '*';

                while (true)
                {
                    char playerGuess = char.Parse(Console.ReadLine());
                    for (int j = 0; j < mysecretWord.Length; j++)
                    {
                        if (playerGuess == mysecretWord[j])
                            guess[j] = playerGuess;
                    }
                    Console.WriteLine(guess);
                }
            }
        }
    }

    How to create a small game in C#(console base) ?

    OR

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication18
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("     **** Welcome to Hangman ****    ");
                string[] listwords = { "cow", "mango", "sanat", "india", "aditya", "arti", "harsh", "bachchalal", "mindstick", "shukla" };
                Random rndmGen = new Random();
                var id_x = rndmGen.Next(0, 9);
                string mysecretWord = listwords[id_x];
                char[] guess = new char[mysecretWord.Length];
                Console.Write("\tPlease Enter your guess(word): ");
                for (int z = 0; z < mysecretWord.Length; z++)
                    guess[z] = '*'; 
                while (true)
                {
                    string playerGuess = Convert.ToString(Console.ReadLine());
                    char[] guessWordsArray = playerGuess.ToCharArray();
                    if (guessWordsArray.Count() > 0)
                    {
                        char guessWord = guessWordsArray[0];
                        for (int j = 0; j < mysecretWord.Length; j++)
                        {
                            if (guessWord == mysecretWord[j])
                                guess[j] = guessWord;
                        }
                        Console.WriteLine(guess);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }            
            }
        }
    }
    


      Modified On Oct-10-2018 10:54:26 PM
  1. Post:8

    Points:56
    Re: How to create a small game in C#(console base) ?

    WaaW, it's a nice program.

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.