Advertisement
prampec

C# Akasztofa - Template

Oct 3rd, 2019
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Oktatas
  7. {
  8.     // https://github.com/laszlonemeth/magyarispell/tree/master/szotar
  9.     public class Akasztofa_Template
  10.     {
  11.         static string[] dictFiles = new string[]
  12.         {
  13.             "resources/alap/fonev.1"
  14.         };
  15.         static Regex rx = new Regex(@"^(\w*)",
  16.           RegexOptions.Compiled | RegexOptions.IgnoreCase);
  17.         List<string> words = new List<string>();
  18.         List<char> guesses = new List<char>();
  19.         Random rnd = new Random();
  20.  
  21.         public void run()
  22.         {
  23.             readDict();
  24.             string word = pickWord();
  25.  
  26.             // ...
  27.             bool allFound = displayMaskedWord(word);
  28.             // ...
  29.             char c = askForChar();
  30.             // ...
  31.             guesses.Add(c);
  32.         }
  33.  
  34.         private void readDict()
  35.         {
  36.             foreach (string dicFile in dictFiles)
  37.             {
  38.                 System.IO.StreamReader file = new System.IO.StreamReader(dicFile);
  39.                 string line;
  40.                 while ((line = file.ReadLine()) != null)
  41.                 {
  42.                     MatchCollection matches = rx.Matches(line);
  43.                     Match match = rx.Match(line);
  44.                     if (match.Success)
  45.                     {
  46.                         // System.Console.Write(line + " -> '");
  47.                         // System.Console.WriteLine(match.Value + "'");
  48.                         if (match.Value.Length > 0)
  49.                         {
  50.                             words.Add(match.Value);
  51.                         }
  52.                     }
  53.                 }
  54.  
  55.                 file.Close();
  56.             }
  57.         }
  58.  
  59.         private string pickWord()
  60.         {
  61.             return "alma";
  62.         }
  63.  
  64.         private bool displayMaskedWord(string word)
  65.         {
  66.             Console.Write("      ");
  67.             bool allFound = true;
  68.             for(int i=0; i<4/* ... */; i++)
  69.             {
  70.                 Console.Write(".");
  71.             }
  72.             Console.WriteLine();
  73.             return allFound;
  74.         }
  75.  
  76.         private char askForChar()
  77.         {
  78.             while (true)
  79.             {
  80.                 Console.Write(" ? ");
  81.                 string line = Console.ReadLine();
  82.  
  83.                 if (line.Length > 0)
  84.                 {
  85.                     return line[0];
  86.                 }
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement