using System;
using System.Text;
namespace HangmanGame {
class App {
static void Main() {
Hangman h = new Hangman();
h.Start();
}
}
class Hangman {
public void Start() {
String hangman = @"
___________
| |
| 0
| /|\
| / \
|
|";
Console.WriteLine(hangman);
Console.WriteLine("Welcome to a basic hangman game. You simply try to guess random word one letter at a time");
string[] words = new string[] {"test", "programming", "microsoft"};
Random random = new Random();
String guess = words[random.Next(0, words.Length)];
StringBuilder word = new StringBuilder(" ");
bool gameOn = true;
for (int i = 0; i < guess.Length; i++) {
if (word[i] == ' ') {
word[i] = '_';
}
}
Console.WriteLine(word);
while (gameOn) {
string letter = Console.ReadLine();
for (int i = 0; i < guess.Length; i++) {
if (guess[i].ToString() == letter) {
word[i] = Convert.ToChar(letter);
}
}
if (word.ToString().Trim() == guess) {
gameOn = false;
Console.WriteLine("You won the game!");
}
Console.WriteLine(word);
}
}
}
}