H
Hyrax
Guest
Hello,
I am fairly new to C# and I have this hangman game pretty much working. The only thing I need help with is adding "lives" to the game. Something which would exit the game if the player goes beyond their limit. Any help is always appreciated.
Thanks a lot.
Hyrax.
if (uservalue == "1")
{
string[] arrayofwords = { "Blue", "Black", "Yellow", "Orange", "Green", "Purple" }; // my word bank
Random ran = new Random(); // created variable to randomize word bank
string mywords = arrayofwords[ran.Next(0, arrayofwords.Length)]; // retrievd this peice of code from How do I select a random number from an array?
Console.WriteLine("You chose colours");
char[] guess = new char[mywords.Length]; // cite help from this website C# Hangman Hang-up - C# | Dream.In.Code
for (int p = 0; p < mywords.Length; p++)
guess[p] = '*'; // this is for the squiglly lines you usually see on hangman games
while (true)
{
Console.Write("Please enter your guess: ");
char playerGuess = char.Parse(Console.ReadLine());
for (int j = 0; j < mywords.Length; j++)
{
if( char.ToLower( playerGuess ) == char.ToLower( mywords[j]) )
guess[j] = mywords[j]; // Hangman Help C#
}
Console.WriteLine(guess);
}
}
Continue reading...
I am fairly new to C# and I have this hangman game pretty much working. The only thing I need help with is adding "lives" to the game. Something which would exit the game if the player goes beyond their limit. Any help is always appreciated.
Thanks a lot.
Hyrax.
if (uservalue == "1")
{
string[] arrayofwords = { "Blue", "Black", "Yellow", "Orange", "Green", "Purple" }; // my word bank
Random ran = new Random(); // created variable to randomize word bank
string mywords = arrayofwords[ran.Next(0, arrayofwords.Length)]; // retrievd this peice of code from How do I select a random number from an array?
Console.WriteLine("You chose colours");
char[] guess = new char[mywords.Length]; // cite help from this website C# Hangman Hang-up - C# | Dream.In.Code
for (int p = 0; p < mywords.Length; p++)
guess[p] = '*'; // this is for the squiglly lines you usually see on hangman games
while (true)
{
Console.Write("Please enter your guess: ");
char playerGuess = char.Parse(Console.ReadLine());
for (int j = 0; j < mywords.Length; j++)
{
if( char.ToLower( playerGuess ) == char.ToLower( mywords[j]) )
guess[j] = mywords[j]; // Hangman Help C#
}
Console.WriteLine(guess);
}
}
Continue reading...