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[] Hangman= {" +-----+" +
- "\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 = { "tiger", "leopard", "lion", "owl", "penguin", "wolf", "bear", "monkey", "cow", "pig", "dog", "cat" };
- Random randNum = new Random();
- int number = randNum.Next(1, 12);
- string target = Words[number];
- int len = target.Length;
- char[] characters = target.ToCharArray();
- List<string> blankspaces = new List<string>();
- List<string> guessedLetters = new List<string>();
- List<string> correct = new List<string>();
- double correctLetters = 0;
- int blanks = 0;
- while (blanks < 0)
- {
- blankspaces.Add("_");
- blanks += 1;
- }
- do
- {
- foreach (var i in blankspaces)
- {
- Console.Write(i);
- }
- Console.WriteLine();
- Console.WriteLine("Lives: {0}", lives);
- Console.WriteLine(Hangman[lives]);
- Console.WriteLine("Enter a letter to guess: ");
- string playerGuess = Console.ReadLine();
- if (guessedLetters.Contains(playerGuess))
- {
- Console.WriteLine("You already guessed that letter");
- }
- else if (target.Contains(playerGuess))
- {
- Console.WriteLine("Your letter is in the word!");
- guessedLetters.Add(playerGuess);
- correct.Add(playerGuess);
- correctLetters += 1;
- }
- else
- {
- Console.WriteLine("Your letter isn't in the word.");
- guessedLetters.Add(playerGuess);
- lives -= 1;
- }
- if (len != correctLetters)
- {
- }
- else
- {
- Console.WriteLine("Well done! The target word was {0}.", target);
- lives = -1;
- }
- } while (lives > 0);
- if (lives == 0)
- {
- Console.WriteLine(Hangman[lives]);
- Console.WriteLine("You ran out of lives. The target word was {0}.", target);
- }
- else if (lives == -1)
- {
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement