Example #1
0
        // Initialize a new game and set the pieces on the board
        public void NewGame()
        {
            ParentForm.ChessCaptureBar.Clear();
            NewGame NewGameDlg = new NewGame();

            NewGameDlg.ResourceFolderPath = ResourceFolder;
            NewGameDlg.ShowDialog();

            // Start the new game
            if (NewGameDlg.bStartGame)
            {
                ChessGame = new Game();

                // Handle the events fired by the library
                ChessGame.ComputerThinking += new ChessLibrary.Game.ChessComputerThinking(ComputerThinking);

                ChessGame.Reset();                      // Reset the game board
                IsRunning  = true;
                LogCounter = 0;

                ChessGame.WhitePlayer.Name = NewGameDlg.WhitePlayerName.Text;
                ChessGame.BlackPlayer.Name = NewGameDlg.BlackPlayerName.Text;

                // Start Human Vs. Computer Game
                if (NewGameDlg.PlayersHvC.Checked)
                {
                    ChessGame.BlackPlayer.PlayerType = Player.Type.Computer;    // Set the black player as computer
                    ChessGame.WhitePlayer.PlayerType = Player.Type.Human;       // Set the white player as computer (as he has the first move)
                }


                // Beginner Player
                if (NewGameDlg.PlayerLevel1.Checked)
                {
                    ChessGame.WhitePlayer.TotalThinkTime = 4;                           // set maximum thinking time
                    ChessGame.BlackPlayer.TotalThinkTime = 4;                           // set maximum thinking time
                }

                // Intermediate Player
                if (NewGameDlg.PlayerLevel2.Checked)
                {
                    ChessGame.WhitePlayer.TotalThinkTime = 7;                           // set maximum thinking time
                    ChessGame.BlackPlayer.TotalThinkTime = 7;                           // set maximum thinking time
                }

                // Chess Master Player
                if (NewGameDlg.PlayerLevel3.Checked)
                {
                    ChessGame.WhitePlayer.TotalThinkTime = 10;                          // set maximum thinking time
                    ChessGame.BlackPlayer.TotalThinkTime = 10;                          // set maximum thinking time
                }

                InitPlayers();
                RedrawBoard();                          // Make the chess board visible on screen
                NextPlayerTurn();                       // When the both players are computer this start the game
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.NewGameWindow = ((Chess.NewGame)(target));

            #line 5 "..\..\NewGame.xaml"
                this.NewGameWindow.MouseMove += new System.Windows.Input.MouseEventHandler(this.Mouse_Move);

            #line default
            #line hidden
                return;

            case 2:
                this.onePlayerBtn = ((System.Windows.Controls.RadioButton)(target));
                return;

            case 3:
                this.twoPlayerBtn = ((System.Windows.Controls.RadioButton)(target));
                return;

            case 4:
                this.networkBtn = ((System.Windows.Controls.RadioButton)(target));
                return;

            case 5:
                this.horse = ((System.Windows.Controls.Image)(target));
                return;

            case 6:
                this.Difficulty = ((System.Windows.Controls.Canvas)(target));
                return;

            case 7:
                this.AI = ((System.Windows.Controls.Slider)(target));
                return;

            case 8:
                this.Network = ((System.Windows.Controls.Canvas)(target));
                return;

            case 9:
                this.ipBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 10:
                this.portBox = ((System.Windows.Controls.TextBox)(target));

            #line 27 "..\..\NewGame.xaml"
                this.portBox.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.portBox_PreviewTextInput);

            #line default
            #line hidden
                return;

            case 11:
                this.Color = ((System.Windows.Controls.Canvas)(target));
                return;

            case 12:
                this.lightBtn = ((System.Windows.Controls.RadioButton)(target));
                return;

            case 13:
                this.darkBtn = ((System.Windows.Controls.RadioButton)(target));
                return;

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

            #line 33 "..\..\NewGame.xaml"
                this.okBtn.Click += new System.Windows.RoutedEventHandler(this.okBtn_Click);

            #line default
            #line hidden
                return;

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

            #line 34 "..\..\NewGame.xaml"
                this.cancelBtn.Click += new System.Windows.RoutedEventHandler(this.cancelBtn_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }