Example #1
0
        private void Read(string fileName)
        {
            listOfPuzzlePhrases = new List <PuzzlePhrase>();
            string line;

            using (StreamReader f = new StreamReader(fileName))
            {
                while ((line = f.ReadLine()) != null)
                {
                    // Read the line
                    line = line.Trim();
                    // Split the strings by comma
                    string[] items = line.Split('|');
                    // Determine the words per line
                    string[] wordsPerLine = items[2].Split('-');
                    int[]    wpl          = new int[wordsPerLine.Length];
                    int      index        = 0;
                    foreach (string s in wordsPerLine)
                    {
                        wpl[index++] = int.Parse(s.Trim());
                    }
                    // Create a new puzzle phrase object
                    PuzzlePhrase p = new PuzzlePhrase(items[0].Trim(), items[1].Trim(), wpl);
                    // Add the new object to the list
                    listOfPuzzlePhrases.Add(p);
                }
            }
        }
Example #2
0
        public Game(PuzzlePhrase puzzlePhrase)
        {
            _currentPuzzlePhrase = puzzlePhrase;

            // Assign the letter dictionary
            _letterDictionary = new Dictionary <char, char>();
            assignOneLetterToAnother();

            // Crete the hints dictionary
            _hintsDictionary = new Dictionary <char, char>();
        }
Example #3
0
        private void startGame(int index)
        {
            // Create the new game
            if (index != -1)
            {
                PuzzlePhrase puzzle = PuzzlePhraseFile.listOfPuzzlePhrases[index];
                _currentGame = new Game(puzzle);
                displayPuzzle(_currentGame.GetScrambledPuzzlePhrase(), _currentGame.CurrentPuzzlePhrase.Category, _currentGame.CurrentPuzzlePhrase.WordsPerLine);

                this.tbHint.Focus();
            }
        }
Example #4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Initialize the current game
            _currentGame       = null;
            currentPuzzleIndex = -1;
            // Load the list of phrases
            puzzlePhraseFile = PuzzlePhraseFile.GetInstance();
            // Shuffle the phrases
            int newIndex;

            for (int i = 0; i < PuzzlePhraseFile.listOfPuzzlePhrases.Count; i++)
            {
                newIndex = randomNumberGenerator.Next(0, PuzzlePhraseFile.listOfPuzzlePhrases.Count);
                PuzzlePhrase temp = PuzzlePhraseFile.listOfPuzzlePhrases[i];
                PuzzlePhraseFile.listOfPuzzlePhrases[i]        = PuzzlePhraseFile.listOfPuzzlePhrases[newIndex];
                PuzzlePhraseFile.listOfPuzzlePhrases[newIndex] = temp;
            }

            // Initalize the controls
            this.btnNewGame.Enabled  = true;
            this.btnPrevGame.Enabled = false;
        }