lundi 26 février 2018

Beginners "Hangman" break [on hold]

The game allows the user to input an unlimited number of attempts, even after the word is is fully spelled out.I cant figure out how to incorporate a break or an if statement for the code to stop after 5 attempts.

using System;

class Hang
{
    static void Main(string[] args)
    {
        Console.WriteLine("Welcome to Hangman!");

        Random r = new Random();
        string[] wordBank = { "One", "Two", "Three", "Four"};
        string wordGuess = wordBank[r.Next(0, wordBank.Length)];

        char[] guess = new char[wordGuess.Length];
        for (int i = 0; i < wordGuess.Length; i++)
        guess[i] = '_';

        while(true)
        {
            {
                Console.Write("enter your guess: ");
                char myGuess = char.Parse(Console.ReadLine());

                for (int j = 0; j < wordGuess.Length; j++)

                    if (char.ToLower(myGuess) == char.ToLower(wordGuess[j]))
                        guess[j] = wordGuess[j];
            }

            Console.WriteLine(guess);
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire