Hi,
I wrote a "hangman" program, but now I'm using a temp string "test" and I can't get it to read a word from file, random word, I tryed with the Streamreader but no success, any advise please.
thanks,
Mike
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.IO;
namespace
_4564356
{
class Program
{
static void Main(string[] args)
{
const string FILE_NAME = "test";
bool continueRunning = true;
while (continueRunning == true)
{
int counter = 6;
int count;
int temp;
int mone = 0;
Console.WriteLine("Welcome to Hangman game");
char[] empty = new char[FILE_NAME.Length];
for (int j = 0; j < FILE_NAME.Length; j++)
{
empty[j] =
'-';
}
start:
Console.Clear();
for (int i = 0; i < FILE_NAME.Length; i++)
{
if (FILE_NAME[i] == empty[i])
{
mone++;
}
}
if (mone == FILE_NAME.Length)
{
goto END;
}
mone = 0;
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
Label7:
Console.Write("You're guess: ");
for (int j = 0; j < FILE_NAME.Length; j++)
{
Console.Write(empty[j]);
}
Console.WriteLine();
count = 0;
if (counter > 0)
{
string guess = Console.ReadLine();
guess = guess.ToLower();
for (int j = 0; j < FILE_NAME.Length; j++)
{
if (guess[0] == FILE_NAME[j])
{
empty[j] = guess[0];
count++;
}
}
if (count == 0)
{
Console.Write("Wrong Guess\n");
counter--;
}
switch (counter)
{
case 5:
goto Label5;
case 4:
goto Label4;
case 3:
goto Label3;
case 2:
goto Label2;
case 1:
goto Label1;
case 0:
goto Label0;
default:
goto start;
}
}
Label5:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
goto Label7;
Label4:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t | |");
Console.WriteLine("\t | |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
goto Label7;
Label3:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t | /|");
Console.WriteLine("\t | |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
goto Label7;
Label2:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t | /|\\");
Console.WriteLine("\t | |");
Console.WriteLine("\t |");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
goto Label7;
Label1:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t | /|\\");
Console.WriteLine("\t | |");
Console.WriteLine("\t | /");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
goto Label7;
Label0:
Console.Clear();
Console.WriteLine("Welcome to Hangman game");
Console.WriteLine("\t |---------");
Console.WriteLine("\t | |");
Console.WriteLine("\t | O");
Console.WriteLine("\t | /|\\");
Console.WriteLine("\t | |");
Console.WriteLine("\t | / \\");
Console.WriteLine("\t |");
Console.WriteLine("\t---");
Console.Write("\n");
END:
Console.WriteLine("You lose, do you want to paly again ?");
string runAgain = Console.ReadLine().ToUpper();
while (runAgain != "Y" && runAgain != "N")
{
Console.Write("Please enter Y or N: ");
runAgain =
Console.ReadLine().ToUpper();
}
if ((runAgain.Equals("y")))
{
continueRunning =
true;
}
else
{
continueRunning =
false;
}
}
}
}
}