Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace DemoHangman
- {
- class Program
- {
- static void Main(string[] args)
- {
- int amountOfLettersRevealed = 0;
- int minusPoints = 0;
- Console.WriteLine("Welcome to Hangman!!!!!!!!!!");
- Console.InputEncoding = Encoding.Default;
- string[] listwords = File.ReadAllLines(@"/Users/annamusterfrau/Desktop/C#_co/italian.txt");
- Random randGen = new Random();
- var idx = randGen.Next(0, 9);
- string mysteryWord = listwords[idx];
- char[] hangman = new char[mysteryWord.Length];
- Console.Write("Please enter your guess: ");
- for (int p = 0; p < mysteryWord.Length; p++)
- {
- hangman[p] = '*';
- }
- while (true)
- {
- string playerGuess;
- string charLength = string.Empty;
- playerGuess = Console.ReadLine();
- char guessed = playerGuess[0];
- if (playerGuess.Length > 1)
- {
- int count = 0;
- for (int i = 0; i < playerGuess.Length; i++)
- {
- if (playerGuess[0] == playerGuess[i])
- {
- count++;
- }
- }
- charLength += playerGuess[0] + count;
- if (charLength.Length > 1)
- {
- Console.WriteLine("enter only one char at a time");
- }
- }
- if (!mysteryWord.Contains(guessed))
- {
- minusPoints++;
- }
- for (int j = 0; j < mysteryWord.Length; j++)
- {
- if (guessed == mysteryWord[j])
- {
- hangman[j] = guessed;
- amountOfLettersRevealed++;
- }
- }
- Console.WriteLine(hangman);
- if (hangman.Length == amountOfLettersRevealed)
- {
- Console.WriteLine("hip hip hooray, you got it all right!");
- Console.WriteLine("your total minus point is: " + minusPoints);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment