//private bool playerTurn = false;


        public void createWindow(CustomWindow w)
        {
            CustomWindow customWindow = w;
            StackPanel   stackPanel   = new StackPanel();
            Grid         dynamicGrid  = new Grid();

            dynamicGrid.Height            = 500;
            dynamicGrid.Width             = 500;
            dynamicGrid.VerticalAlignment = VerticalAlignment.Bottom;

            //Goes through and adds the correct number of rows and columns to grid
            for (int i = 0; i < (int)Application.Current.Properties["BoardSize"]; i++)
            {
                ColumnDefinition gridCol = new ColumnDefinition();
                RowDefinition    gridRow = new RowDefinition();

                dynamicGrid.ColumnDefinitions.Add(gridCol);
                dynamicGrid.RowDefinitions.Add(gridRow);
            }

            //Creates a button and sets the button to a section in the grid
            //Then adds the button to the grid children
            for (int i = 0; i < (int)Application.Current.Properties["BoardSize"]; i++)
            {
                for (int j = 0; j < (int)Application.Current.Properties["BoardSize"]; j++)
                {
                    Button gridBtn = new Button();

                    Grid.SetRow(gridBtn, i);
                    Grid.SetColumn(gridBtn, j);
                    gridBtn.Click   += Button_Click;
                    gridBtn.FontSize = 40;

                    if (loadFromSave)
                    {
                        if (gameBoard.Grid[j, i].symbol != '\0')
                        {
                            gridBtn.Content = gameBoard.Grid[i, j].symbol;
                        }
                    }

                    board.Add(gridBtn);
                    dynamicGrid.Children.Add(gridBtn);
                }
            }

            createMenu(stackPanel);
            stackPanel.Children.Add(dynamicGrid);

            //Adds grid to the next window about to be opened
            customWindow.Content = stackPanel;


            customWindow.Show();
        }
示例#2
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();
        }
示例#3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.customWindow = ((Tic_Tac_Toe.CustomWindow)(target));

            #line 9 "..\..\CustomWindow.xaml"
                this.customWindow.Loaded += new System.Windows.RoutedEventHandler(this.Colors_OnLoaded);

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