Example #1
0
        //Method that handles a button click event
        //Mainly used for the close button
        private void btn_CloseClick(object sender, RoutedEventArgs e)
        {
            MainWindow     mainWindow     = new MainWindow();
            RegularWindow  regularWindow  = new RegularWindow(gameMode);
            UltimateWindow ultimateWindow = new UltimateWindow(String.Empty);
            CustomWindow   customWindow   = new CustomWindow(gameMode);
            ThreeDWindow   threeDWindow   = new ThreeDWindow(String.Empty);

            //This conditional is used to open the previous window that was open before the settings window
            if ((string)Application.Current.Properties["WindowIndex"] == mainWindow.Name)
            {
                mainWindow.Show();

                //Sets background and foreground color
                mainWindow.mainGrid.Background   = settingGrid.Background;
                mainWindow.title.Foreground      = settingLabel.Foreground;
                mainWindow.boardLabel.Foreground = settingLabel.Foreground;
            }
            else if ((string)Application.Current.Properties["WindowIndex"] == regularWindow.Name)
            {
                //Setting these variables will set the background and foreground color for this window
                Application.Current.Properties["Background"] = settingGrid.Background;
                Application.Current.Properties["FontColor"]  = settingLabel.Foreground;

                regularWindow.Show();
            }
            else if ((string)Application.Current.Properties["WindowIndex"] == ultimateWindow.Name)
            {
                //Setting these variables will set the background and foreground color for this window
                Application.Current.Properties["Background"] = settingGrid.Background;
                Application.Current.Properties["FontColor"]  = settingLabel.Foreground;

                ultimateWindow.Show();
            }
            else if ((string)Application.Current.Properties["WindowIndex"] == customWindow.Name)
            {
                //Setting these variables will set the background and foreground color for this window
                Application.Current.Properties["Background"] = settingGrid.Background;
                Application.Current.Properties["FontColor"]  = settingLabel.Foreground;

                customWindow.createWindow(customWindow);
            }
            else if ((string)Application.Current.Properties["WindowIndex"] == threeDWindow.Name)
            {
                //Setting these variables will set the background and foreground color for this window
                Application.Current.Properties["Background"] = settingGrid.Background;
                Application.Current.Properties["FontColor"]  = settingLabel.Foreground;

                threeDWindow.Show();
            }

            //Closes the setting window
            this.Close();
        }
Example #2
0
        //Method that handles the event of a selection changed within the combo box
        //Another window should open when a selection is picked
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Get the ComboBox.
            var comboBox = sender as ComboBox;

            // Set SelectedItem as Window Title.
            string value = comboBox.SelectedItem as string;

            if (mainText.Text == "")
            {
                if (value == "Play")
                {
                    //We don't want the program to do anything if play is selected so it returns here
                    return;
                }
                else if (value == "Normal Tic-tac-toe" ||
                         value == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                         value == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                         value == "Nokato Tic-tac-toe" ||
                         value == "Wild Tic-tac-toe (Your Choice Tic-tac-toe)" ||
                         value == "Devil's Tic-tac-toe" ||
                         value == "Revenge Tic-tac-toe" ||
                         value == "Random Tic-tac-toe")
                {
                    //Creates the new Window
                    RegularWindow regularWindow = new RegularWindow(value);

                    //Closes initial window
                    this.Close();

                    //These startup variables should be colors
                    //Assigns these variables so the next window that is open can use them to have the same colors
                    Application.Current.Properties["Background"] = mainGrid.Background;
                    Application.Current.Properties["FontColor"]  = title.Foreground;

                    //Show next window
                    regularWindow.Show();
                }
                else if (value == "Ultimate Tic-tac-toe")
                {
                    UltimateWindow ultimateWindow = new UltimateWindow(value);

                    this.Close();

                    //These startup variables should be colors
                    //Assigns these variables so the next window that is open can use them to have the same colors
                    Application.Current.Properties["Background"] = mainGrid.Background;
                    Application.Current.Properties["FontColor"]  = title.Foreground;

                    //Show next window
                    ultimateWindow.Show();
                }
                else if (value == "3D Tic-tac-toe")
                {
                    ThreeDWindow threeDWindow = new ThreeDWindow(value);

                    this.Close();

                    //These startup variables should be colors
                    //Assigns these variables so the next window that is open can use them to have the same colors
                    Application.Current.Properties["Background"] = mainGrid.Background;
                    Application.Current.Properties["FontColor"]  = title.Foreground;

                    //Show next window
                    threeDWindow.Show();
                }
            }
            else if (value == "Ultimate Tic-tac-toe")
            {
                UltimateWindow ultimateWindow = new UltimateWindow(value);

                this.Close();

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Show next window
                ultimateWindow.Show();
            }
            else if (value == "3D Tic-tac-toe")
            {
                ThreeDWindow threeDWindow = new ThreeDWindow(value);

                this.Close();

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Show next window
                threeDWindow.Show();
            }
            else
            {
                if (int.Parse(mainText.Text) <= 3)
                {
                    if (value == "Play")
                    {
                        //We don't want the program to do anything if play is selected so it returns here
                        return;
                    }
                    else if (value == "Normal Tic-tac-toe" ||
                             value == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                             value == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                             value == "Nokato Tic-tac-toe" ||
                             value == "Wild Tic-tac-toe (Your Choice Tic-tac-toe)" ||
                             value == "Devil's Tic-tac-toe" ||
                             value == "Revenge Tic-tac-toe" ||
                             value == "Random Tic-tac-toe")
                    {
                        //Creates the new Window
                        RegularWindow regularWindow = new RegularWindow(value);

                        //Closes initial window
                        this.Close();

                        //These startup variables should be colors
                        //Assigns these variables so the next window that is open can use them to have the same colors
                        Application.Current.Properties["Background"] = mainGrid.Background;
                        Application.Current.Properties["FontColor"]  = title.Foreground;

                        //Show next window
                        regularWindow.Show();
                    }
                }
                else
                {
                    int size = int.Parse(mainText.Text);
                    Application.Current.Properties["BoardSize"] = size <= 10 ? size : 10; // Max board size of 10

                    CustomWindow customWindow = new CustomWindow(value);

                    //These startup variables should be colors
                    //Assigns these variables so the next window that is open can use them to have the same colors
                    Application.Current.Properties["Background"] = mainGrid.Background;
                    Application.Current.Properties["FontColor"]  = title.Foreground;

                    //Closes first window opens another
                    this.Close();

                    customWindow.createWindow(customWindow);
                }
            }
        }
Example #3
0
        private void btn_LoadClick(object sender, RoutedEventArgs e)
        {
            string fileContent = string.Empty;
            string filePath    = string.Empty;

            // Restores a previsouly saved game and starts it in a new window
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "dat files (*.dat)|*.dat|All files (*.*)|*.*";
            openFileDialog.RestoreDirectory = true;

            openFileDialog.ShowDialog();

            filePath = openFileDialog.FileName;

            if (filePath.Equals(String.Empty))
            {
                return;
            }

            Stream         fileStream = openFileDialog.OpenFile();
            TicTacToeBoard boardFromFile;

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (Stream fStream = File.OpenRead(filePath))
            {
                boardFromFile = (TicTacToeBoard)binaryFormatter.Deserialize(fStream);
            }

            if (boardFromFile.N == 3 && boardFromFile.gameMode != "3D")
            {
                RegularWindow regularWindow = new RegularWindow(string.Empty, boardFromFile);

                //Closes initial window
                this.Close();

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Show next window
                regularWindow.Show();
            }
            else if ((boardFromFile.gameMode == "Normal Tic-tac-toe" ||
                      boardFromFile.gameMode == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                      boardFromFile.gameMode == "Misere Tic-tac-toe (Avoidance Tic-tac-toe)" ||
                      boardFromFile.gameMode == "Nokato Tic-tac-toe" ||
                      boardFromFile.gameMode == "Wild Tic-tac-toe (Your Choice Tic-tac-toe)" ||
                      boardFromFile.gameMode == "Devil's Tic-tac-toe" ||
                      boardFromFile.gameMode == "Revenge Tic-tac-toe" ||
                      boardFromFile.gameMode == "Random Tic-tac-toe") &&
                     boardFromFile.N > 3)
            {
                Application.Current.Properties["BoardSize"] = boardFromFile.N; // Max board size of 10

                CustomWindow customWindow = new CustomWindow(boardFromFile.gameMode, boardFromFile);

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Closes first window opens another
                this.Close();

                customWindow.createWindow(customWindow);
            }
            else if (boardFromFile.gameMode == "Ultimate Tic-tac-toe")
            {
                UltimateWindow ultimateWindow = new UltimateWindow(boardFromFile.gameMode, boardFromFile);

                this.Close();

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Show next window
                ultimateWindow.Show();
            }
            else if (boardFromFile.gameMode == "3D")
            {
                ThreeDWindow threeDWindow = new ThreeDWindow(boardFromFile.gameMode, boardFromFile);

                this.Close();

                //These startup variables should be colors
                //Assigns these variables so the next window that is open can use them to have the same colors
                Application.Current.Properties["Background"] = mainGrid.Background;
                Application.Current.Properties["FontColor"]  = title.Foreground;

                //Show next window
                threeDWindow.Show();
            }
        }