Exemplo 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._3DWindow = ((Tic_Tac_Toe.ThreeDWindow)(target));

            #line 10 "..\..\ThreeDWindow.xaml"
                this._3DWindow.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.Grid13d = ((System.Windows.Controls.Grid)(target));
                return;

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

            #line 47 "..\..\ThreeDWindow.xaml"
                this._a0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 48 "..\..\ThreeDWindow.xaml"
                this._b0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 49 "..\..\ThreeDWindow.xaml"
                this._c0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 50 "..\..\ThreeDWindow.xaml"
                this._d0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 51 "..\..\ThreeDWindow.xaml"
                this._e0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 52 "..\..\ThreeDWindow.xaml"
                this._f0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 53 "..\..\ThreeDWindow.xaml"
                this._g0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            #line 54 "..\..\ThreeDWindow.xaml"
                this._h0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 12:
                this._i0 = ((System.Windows.Controls.Button)(target));

            #line 55 "..\..\ThreeDWindow.xaml"
                this._i0.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 13:
                this._3dGrid2 = ((System.Windows.Controls.Grid)(target));
                return;

            case 14:
                this._a1 = ((System.Windows.Controls.Button)(target));

            #line 77 "..\..\ThreeDWindow.xaml"
                this._a1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 15:
                this._b1 = ((System.Windows.Controls.Button)(target));

            #line 78 "..\..\ThreeDWindow.xaml"
                this._b1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 16:
                this._c1 = ((System.Windows.Controls.Button)(target));

            #line 79 "..\..\ThreeDWindow.xaml"
                this._c1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 17:
                this._d1 = ((System.Windows.Controls.Button)(target));

            #line 80 "..\..\ThreeDWindow.xaml"
                this._d1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 18:
                this._e1 = ((System.Windows.Controls.Button)(target));

            #line 81 "..\..\ThreeDWindow.xaml"
                this._e1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 19:
                this._f1 = ((System.Windows.Controls.Button)(target));

            #line 82 "..\..\ThreeDWindow.xaml"
                this._f1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 20:
                this._g1 = ((System.Windows.Controls.Button)(target));

            #line 83 "..\..\ThreeDWindow.xaml"
                this._g1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 21:
                this._h1 = ((System.Windows.Controls.Button)(target));

            #line 84 "..\..\ThreeDWindow.xaml"
                this._h1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 22:
                this._i1 = ((System.Windows.Controls.Button)(target));

            #line 85 "..\..\ThreeDWindow.xaml"
                this._i1.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 23:
                this._3dGrid3 = ((System.Windows.Controls.Grid)(target));
                return;

            case 24:
                this._a2 = ((System.Windows.Controls.Button)(target));

            #line 108 "..\..\ThreeDWindow.xaml"
                this._a2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 25:
                this._b2 = ((System.Windows.Controls.Button)(target));

            #line 109 "..\..\ThreeDWindow.xaml"
                this._b2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 26:
                this._c2 = ((System.Windows.Controls.Button)(target));

            #line 110 "..\..\ThreeDWindow.xaml"
                this._c2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 27:
                this._d2 = ((System.Windows.Controls.Button)(target));

            #line 111 "..\..\ThreeDWindow.xaml"
                this._d2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 28:
                this._e2 = ((System.Windows.Controls.Button)(target));

            #line 112 "..\..\ThreeDWindow.xaml"
                this._e2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 29:
                this._f2 = ((System.Windows.Controls.Button)(target));

            #line 113 "..\..\ThreeDWindow.xaml"
                this._f2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 30:
                this._g2 = ((System.Windows.Controls.Button)(target));

            #line 114 "..\..\ThreeDWindow.xaml"
                this._g2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 31:
                this._h2 = ((System.Windows.Controls.Button)(target));

            #line 115 "..\..\ThreeDWindow.xaml"
                this._h2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 32:
                this._i2 = ((System.Windows.Controls.Button)(target));

            #line 116 "..\..\ThreeDWindow.xaml"
                this._i2.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

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

            case 34:

            #line 120 "..\..\ThreeDWindow.xaml"
                ((System.Windows.Controls.ComboBox)(target)).Loaded += new System.Windows.RoutedEventHandler(this.regularComboBox);

            #line default
            #line hidden

            #line 120 "..\..\ThreeDWindow.xaml"
                ((System.Windows.Controls.ComboBox)(target)).SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.regularComboBox_SelectionChanged);

            #line default
            #line hidden
                return;

            case 35:

            #line 121 "..\..\ThreeDWindow.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btn_RuleClick);

            #line default
            #line hidden
                return;

            case 36:

            #line 122 "..\..\ThreeDWindow.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btn_SettingClick);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Exemplo 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);
                }
            }
        }
Exemplo 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();
            }
        }