Beispiel #1
0
        private void hardButton_Click(object sender, EventArgs e)
        {
            problem saved = readPuzzles("hard", "saved"); //Try fetching saved puzzle first (to check if there is saved one first)

            if (saved != null)                            //If there is saved puzzle
            {
                MessageBox.Show("Saved puzzle detected! You will continue playing it.");
                currentPuzzle         = saved;
                currentPuzzle.isSaved = true;
                gameWindow gw = new gameWindow();
                gw.ShowDialog();
                return;
            }
            saved = readPuzzles("hard", "unsolved");
            if (saved != null) //If there is unsolved puzzle for that difficulty
            {
                currentPuzzle = saved;
                gameWindow gw = new gameWindow();
                gw.ShowDialog();
                return;
            }
            else
            {
                MessageBox.Show("There is no more unsolved puzzles for hard difficulty, please choose another difficulty.");
            }
        }
Beispiel #2
0
        //Reading directory.txt folder, checking if the next puzzle is one that we are looking for, if yes we are returning it
        private problem readPuzzles(string difficulty, string needed)
        {
            string  line;
            problem currentLoaded = null;

            //Read the file line by line
            System.IO.StreamReader file = new System.IO.StreamReader(puzzleFolder + "/directory.txt");
            while ((line = file.ReadLine()) != null)
            {
                string[] words = line.Split('/'); //Splitting string by / to see it's difficulty and puzzle file name
                if (words[0] == difficulty)
                {
                    if (needed == "unsolved")
                    {
                        currentLoaded = loadUnsolvedPuzzle(Path.Combine(puzzleFolder, line));
                        if (currentLoaded != null)   //If we loaded what we need return it
                        {
                            currentDifficulty = difficulty;
                            file.Close();
                            return(currentLoaded);
                        }
                    }
                    else if (needed == "saved")
                    {
                        currentLoaded = loadSavedPuzzle(Path.Combine(puzzleFolder, line));
                        if (currentLoaded != null) //If we loaded what we need return it
                        {
                            currentDifficulty = difficulty;
                            file.Close();
                            return(currentLoaded);
                        }
                    }
                }
            }
            file.Close();
            return(currentLoaded);
        }