Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream("../../users.bin", FileMode.Open, FileAccess.Read, FileShare.Read);

            users = (Dictionary <string, int>)formatter.Deserialize(stream);
            stream.Close();

            Stream stream2 = new FileStream("../../wordBase.bin", FileMode.Open, FileAccess.Read, FileShare.Read);

            wordBase = (WordBase)formatter.Deserialize(stream2);
            stream2.Close();

            /*
             * // Это чтобы преобразовать текстовый файл в сериализуемый бинарник
             * string[] lines = System.IO.File.ReadAllLines(@"../../word_rus.txt");
             * WordBase wb = new WordBase();
             * foreach (string word in lines)
             * {
             *
             *  if (!word.Contains('-'))
             *  {
             *      wb.Add(word.ToUpper());
             *  }
             * }
             * IFormatter formatter2 = new BinaryFormatter();
             * Stream stream2 = new FileStream("../../wordBase.bin", FileMode.Create, FileAccess.Write, FileShare.None);
             * formatter.Serialize(stream2, wb);
             * stream2.Close();*/
        }
Example #2
0
 public GameCreationForm(Dictionary <string, int> users, WordBase wordBase)
 {
     InitializeComponent();
     this.users    = users;
     this.wordBase = wordBase;
     playerNames   = new TextBox[2];
     playerTypes   = new ComboBox[2];
     for (int i = 0; i < 2; ++i)
     {
         createUserInputControls(i);
     }
 }
Example #3
0
        public Game(string startWord, List <Player> players, Rules rules, WordBase wordBase, GamingForm gamingForm)
        {
            State                 = new FieldState(startWord);
            Rules                 = rules;
            Players               = players;
            this.wordBase         = wordBase;
            this.gamingForm       = gamingForm;
            consequtiveTurnPasses = 0;
            secondsTimerCB        = new TimerCallback(timerTick);
            if (Rules.HasTimeLimit == true)
            {
                secondsTimer = new System.Threading.Timer(secondsTimerCB, null, 1000, 1000);
            }

            // now construct the prefix tree
            for (int i = 0; i < prefixTreeMaxSize; ++i)
            {
                isWord[i] = false;
                for (int j = 0; j < 32; ++j)
                {
                    prefixTree[i, j] = -1;
                }
            }
            int firstUnused = 1;

            string[] lines = System.IO.File.ReadAllLines(@"../../word_rus.txt");
            foreach (string word in lines)
            {
                int currentIndex = 0;
                for (int j = 0; j < word.Length; ++j)
                {
                    if (prefixTree[currentIndex, word[j] - 'А'] == -1)
                    {
                        prefixTree[currentIndex, word[j] - 'А'] = firstUnused;
                        currentIndex = firstUnused;
                        ++firstUnused;
                    }
                    else
                    {
                        currentIndex = prefixTree[currentIndex, word[j] - 'А'];
                    }
                    if (j == word.Length - 1)
                    {
                        isWord[currentIndex] = true;
                    }
                }
            }
        }