View difference between Paste ID: g0CVUrpx and vkvZ6hKC
SHOW: | | - or go back to the newest paste.
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
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-
        int round;
20+
21
        public void run()
22-
        public Akasztofa()
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-
            round = 1;
56+
57-
            int errorCount = 0;
57+
58
59
        private string pickWord()
60-
                bool allFound = displayMaskedWord(word);
60+
61-
                if (allFound)
61+
            return "alma";
62
        }
63-
                    Console.WriteLine("Done with " + errorCount + " errors.");
63+
64-
                    break;
64+
65
        {
66-
                char c = askForChar();
66+
67-
                guesses.Add(c);
67+
68-
                if (!word.Contains(c))
68+
            for(int i=0; i<4/* ... */; i++)
69
            {
70-
                    errorCount += 1;
70+
                Console.Write(".");
71
            }
72-
                round += 1;
72+
            Console.WriteLine();
73
            return allFound;
74
        }
75
76
        private char askForChar()
77
        {
78
            while (true)
79-
            int index = rnd.Next(words.Count);
79+
80-
            return words[index];
80+
                Console.Write(" ? ");
81
                string line = Console.ReadLine();
82
83
                if (line.Length > 0)
84
                {
85
                    return line[0];
86
                }
87-
            for(int i=0; i<word.Length; i++)
87+
88
        }
89-
                if (guesses.Contains(word[i]))
89+
90
}