Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- namespace ConsoleApplication1
- {
- class Program
- {
- static List<String> Words { get; set; }
- static Int32 GuessCount { get; set; }
- static void Main(string[] args)
- {
- Words = new List<String>();
- DrawMenu();
- }
- static void DrawMenu()
- {
- Console.Clear();
- Console.WriteLine("1. Lägg till.");
- Console.WriteLine("2. Visa alla.");
- Console.WriteLine("3. Spela.");
- Console.WriteLine("4. Avsluta.");
- switch (Console.ReadKey().Key)
- {
- case ConsoleKey.D1:
- AddWord();
- break;
- case ConsoleKey.D2:
- DisplayWords();
- break;
- case ConsoleKey.D3:
- Play();
- break;
- case ConsoleKey.D4:
- Exit();
- break;
- default:
- DrawMenu();
- break;
- }
- }
- static void AddWord()
- {
- Console.Clear();
- Console.WriteLine("Skriv ett ord och tryck på enter:");
- Words.Add(Console.ReadLine());
- Console.WriteLine();
- Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
- Console.ReadKey();
- DrawMenu();
- }
- static void DisplayWords()
- {
- Console.Clear();
- Console.WriteLine("Dessa ord är tillagda:");
- foreach (String word in Words)
- {
- Console.WriteLine(word);
- }
- Console.WriteLine();
- Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
- Console.ReadKey();
- DrawMenu();
- }
- static void Play()
- {
- String randomWord = Words.OrderBy(x => Guid.NewGuid()).First();
- String guessWord = String.Empty;
- GuessCount = 0;
- Console.Clear();
- Console.WriteLine("Gissa vilket ord:");
- while (guessWord.ToLower() != randomWord.ToLower())
- {
- guessWord = Console.ReadLine();
- if (guessWord.ToLower() != randomWord.ToLower())
- {
- GuessCount++;
- Console.WriteLine(String.Format("Du har gissat fel {0} gånger.", GuessCount));
- }
- }
- Console.WriteLine("Du gissade rätt.");
- Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
- Console.ReadKey();
- DrawMenu();
- }
- static void Exit()
- {
- Console.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement