Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Hangman
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] hangMen = {" +-----+" +
- "\n O\t|" +
- "\n /|\\ \t|" +
- "\n / \\ \t|" +
- "\n ===",
- " +-----+" +
- "\n O\t|" +
- "\n /|\\ \t|" +
- "\n \t|" +
- "\n ===",
- " +-----+" +
- "\n O\t|" +
- "\n | \t|" +
- "\n \t|" +
- "\n ===",
- " +-----+" +
- "\n O\t|" +
- "\n \t|" +
- "\n \t|" +
- "\n ===",
- " +-----+" +
- "\n \t|" +
- "\n \t|" +
- "\n \t|" +
- "\n ===",
- "\n \t|" +
- "\n \t|" +
- "\n \t|" +
- "\n ===",
- "\n ===",
- ""
- };
- int lives = 7;
- string[] words = { "airplane", "car", "train", "bus", "bycicle", "motorcycle", "helicopter", "boat" };
- Random rnd = new Random();
- int num = rnd.Next(1, 8);
- string word = words[num];
- int length = word.Length;
- char[] letters = word.ToCharArray();
- List<string> blanks = new List<string>();
- int x = 0;
- while(x<length)
- {
- blanks.Add("_");
- x += 1;
- }
- int correct = 0;
- List<string> right = new List<string>();
- List<string> wrong = new List<string>();
- List<string> guessed = new List<string>();
- do
- {
- foreach(var i in blanks)
- {
- Console.Write(i);
- }
- Console.WriteLine();
- Console.WriteLine("You have {0} guess(es) remaining.", lives);
- Console.WriteLine(hangMen[lives]);
- Console.WriteLine("Enter a letter:");
- string guess = Console.ReadLine();
- if (word.Contains(guess))
- {
- Console.WriteLine("{0} is in the word!", guess);
- guessed.Add(guess);
- right.Add(guess);
- correct += 1;
- }
- else if (guessed.Contains(guess))
- {
- Console.WriteLine("{0} has already been guessed.", guess);
- }
- else
- {
- Console.WriteLine("{0} isn't in the word.", guess);
- guessed.Add(guess);
- wrong.Add(guess);
- lives -= 1;
- }
- int y = 0;
- foreach (var item in letters)
- {
- string itemString = item.ToString();
- if (guess == itemString)
- {
- blanks[y] = guess;
- }
- y += 1;
- }
- if (blanks.Contains("_"))
- {
- }
- else
- {
- Console.WriteLine("You guessed it, the word was {0}.", word);
- lives = -1;
- }
- } while (lives > 0);
- if (lives == 0)
- {
- Console.WriteLine(hangMen[lives]);
- Console.WriteLine("You failed, the word was {0}.", word);
- }
- else if (lives == -1)
- {
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement