Foibs

Hangman simple

Jan 7th, 2020
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         public void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Poses lekseis thes na dwseis?");
  10.             int n = int.Parse(Console.ReadLine());
  11.  
  12.             string[] pinakas = new string[n];
  13.  
  14.             Console.WriteLine("Poies {0} lekseis thes?", n);
  15.  
  16.             for (int i=0; i<n; i++)
  17.             {
  18.                 pinakas[i] = Console.ReadLine();
  19.             }
  20.  
  21.             Random rnd = new Random();
  22.             int num = rnd.Next(0, n);
  23.  
  24.             string word = pinakas[num];
  25.             char[] guess = new char[word.Length];
  26.  
  27.             int lives = 6;
  28.  
  29.             Console.WriteLine("Dwse ena gramma");
  30.             for (int i = 0; i < word.Length; i++)
  31.             {
  32.                 guess[i] = '_';
  33.             }
  34.  
  35.             while (true)
  36.             {
  37.                 char userInput = char.Parse(Console.ReadLine());
  38.                 for (int j = 0; j < word.Length; j++)
  39.                 {
  40.                     if (userInput == word[j])
  41.                     {
  42.                         guess[j] = userInput;
  43.                     }
  44.                     else
  45.                     {
  46.                         Console.WriteLine("Wrong input. You have {0} remaining lives", lives);
  47.                         lives--;
  48.                     }
  49.                 }
  50.                 Console.Write(guess);
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment