Ejemplo n.º 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();
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.window2 = ((Tic_Tac_Toe.RegularWindow)(target));

            #line 10 "..\..\RegularWindow - Copy.xaml"
                this.window2.Loaded += new System.Windows.RoutedEventHandler(this.Colors_OnLoaded);

            #line default
            #line hidden
                return;

            case 2:
                this.RegularGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.btn1 = ((System.Windows.Controls.Button)(target));

            #line 36 "..\..\RegularWindow - Copy.xaml"
                this.btn1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.btn2 = ((System.Windows.Controls.Button)(target));

            #line 37 "..\..\RegularWindow - Copy.xaml"
                this.btn2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.btn3 = ((System.Windows.Controls.Button)(target));

            #line 38 "..\..\RegularWindow - Copy.xaml"
                this.btn3.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 6:
                this.btn4 = ((System.Windows.Controls.Button)(target));

            #line 40 "..\..\RegularWindow - Copy.xaml"
                this.btn4.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 7:
                this.btn5 = ((System.Windows.Controls.Button)(target));

            #line 41 "..\..\RegularWindow - Copy.xaml"
                this.btn5.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 8:
                this.btn6 = ((System.Windows.Controls.Button)(target));

            #line 42 "..\..\RegularWindow - Copy.xaml"
                this.btn6.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 9:
                this.btn7 = ((System.Windows.Controls.Button)(target));

            #line 44 "..\..\RegularWindow - Copy.xaml"
                this.btn7.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 10:
                this.btn8 = ((System.Windows.Controls.Button)(target));

            #line 45 "..\..\RegularWindow - Copy.xaml"
                this.btn8.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 11:
                this.btn9 = ((System.Windows.Controls.Button)(target));

            #line 46 "..\..\RegularWindow - Copy.xaml"
                this.btn9.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 12:
                this.RegularMenu = ((System.Windows.Controls.Menu)(target));
                return;

            case 13:

            #line 50 "..\..\RegularWindow - Copy.xaml"
                ((System.Windows.Controls.ComboBox)(target)).Loaded += new System.Windows.RoutedEventHandler(this.regularComboBox);

            #line default
            #line hidden

            #line 50 "..\..\RegularWindow - Copy.xaml"
                ((System.Windows.Controls.ComboBox)(target)).SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.regularComboBox_SelectionChanged);

            #line default
            #line hidden
                return;

            case 14:

            #line 51 "..\..\RegularWindow - Copy.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btn_RuleClick);

            #line default
            #line hidden
                return;

            case 15:

            #line 52 "..\..\RegularWindow - Copy.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btn_SettingClick);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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();
            }
        }