コード例 #1
0
 // Used to check eneme cell
 private bool CheckCellEnemy(int x, int y, bool brickChange)
 {
     // Check enemys for white brick
     if (brickChange == true)
     {
         for (int i = 97; i < 103; i++)
         {
             if (ChessMap.CheckMapArray(x, y, (char)i))
             {
                 return(true);
             }
         }
     }
     // Check enemys for black brick
     else
     {
         for (int i = 65; i < 71; i++)
         {
             if (ChessMap.CheckMapArray(x, y, (char)i))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #2
0
 private void MenuItem_NewGame(object sender, RoutedEventArgs e)
 {
     ChessMap.tSecond = -1;
     ChessMap.tMin    = 0;
     ChessMap.Reset();
     chessBoard.Update();
 }
コード例 #3
0
        protected void CheckWin()
        {
            bool kingWhite = false;
            bool kingBlack = false;

            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    if (ChessMap.CheckMapArray(x, y, 'F'))
                    {
                        kingWhite = true;
                    }
                    if (ChessMap.CheckMapArray(x, y, 'f'))
                    {
                        kingBlack = true;
                    }
                }
            }
            if (kingWhite == false)
            {
                Win("Black wins!");
            }
            if (kingBlack == false)
            {
                Win("White wins!");
            }
        }
コード例 #4
0
        /*******************************************************************/
        // KING LOGIC                                                      */
        /*******************************************************************/
        protected void CheckKing(int y, int x, char brickChar, bool brickChange)
        {
            // Used to set what direction the brick should go on the y axis
            CheckBrickChange(brickChange);

            if (ChessMap.CheckMapArray(x, y, brickChar))
            {
                // Set marker where the queen brick can move on y- axis
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 2; j++)
                    {
                        // Set marker where the queen can kill
                        if ((CheckCellEnemy(x + (-j * brickDire), y + (-i * brickDire), brickChange)))
                        {
                            ChessMap.SetMoveArray(x + (-j * brickDire), y + (-i * brickDire), '#');
                        }

                        // Set marker where the queen can move
                        if (ChessMap.CheckMapArray(x + (-j * brickDire), y + (-i * brickDire), ' '))
                        {
                            ChessMap.SetMoveArray(x + (-j * brickDire), y + (-i * brickDire), '*');
                            ChessMap.SetMapArray(x + (-j * brickDire), y + (-i * brickDire), '*');
                        }
                    }
                }
                // Used to set brick variables
                SetBrickVariables(brickChar, x, y);
            }
        }
コード例 #5
0
 void Win(string message)
 {
     ChessMap.stopTimer = true;
     MessageBox.Show(message, "Checkmate", MessageBoxButton.OK, MessageBoxImage.Information);
     ChessMap.stopTimer = false;
     ChessMap.tSecond   = -1;
     ChessMap.tMin      = 0;
     ChessMap.Reset();
 }
コード例 #6
0
ファイル: ChessBoard.cs プロジェクト: jonash871j/Chess-WPF
        void ImportImage(int x, int y, char character, string path)
        {
            if (ChessMap.CheckMapArray(x, y, character))
            {
                BitmapImage btm = new BitmapImage(new Uri(path, UriKind.Relative));
                btm.UriSource = new Uri(path, UriKind.Relative);

                img[y, x].Source = btm;

                mapButton[y, x].Content = img[y, x];
            }
        }
コード例 #7
0
        /*******************************************************************/
        // BISHOP LOGIC                                                    */
        /*******************************************************************/
        protected void CheckBishop(int y, int x, char brickChar, bool brickChange)
        {
            // Used to set what direction the brick should go on the y axis
            CheckBrickChange(brickChange);

            if (ChessMap.CheckMapArray(x, y, brickChar))
            {
                // Set marker where the bishop brick can move and kill
                CheckMovement(8, x, y, brickDire, brickDire, brickChange, true);   // xy-    axis
                CheckMovement(8, x, y, -brickDire, -brickDire, brickChange, true); // xy+    axis
                CheckMovement(8, x, y, brickDire, -brickDire, brickChange, true);  // x-, y+ axis
                CheckMovement(8, x, y, -brickDire, brickDire, brickChange, true);  // x+, y- axis

                // Used to set brick variables
                SetBrickVariables(brickChar, x, y);
            }
        }
コード例 #8
0
        /*******************************************************************/
        // PAWN LOGIC                                                      */
        /*******************************************************************/
        protected void CheckPawn(int y, int x, char brickChar, bool brickChange)
        {
            // Used to set what direction the brick should go on the y axis
            CheckBrickChange(brickChange);

            if (ChessMap.CheckMapArray(x, y, brickChar))
            {
                // Start position with pawn allows to move 1 step more forward
                int cellMove = 1;
                if ((y == 6) && (brickChange == true))
                {
                    cellMove = 2;
                }
                if ((y == 1) && (brickChange == false))
                {
                    cellMove = 2;
                }

                // Set marker where the pawn brick can move on the y- axis
                for (int i = 1; i < 1 + cellMove; i++)
                {
                    if (ChessMap.CheckMapArray(x, y + (-i * brickDire), ' '))
                    {
                        ChessMap.SetMoveArray(x, y + (-i * brickDire), '*');
                        ChessMap.SetMapArray(x, y + (-i * brickDire), '*');
                    }
                    else
                    {
                        break;
                    }
                }
                // Set stafe marker where the pawn brick can kill
                for (int j = -1; j < 2; j++)
                {
                    if ((CheckCellEnemy(x + j, y + (-1 * brickDire), brickChange)) && (j != 0))
                    {
                        ChessMap.SetMoveArray(x + j, y + (-1 * brickDire), '#');
                    }
                }

                // Used to set brick variables
                SetBrickVariables(brickChar, x, y);
            }
        }
コード例 #9
0
 // Used to check where the brick is allowed to move
 private void CheckMovement(int loopLength, int x, int y, int xDire, int yDire, bool brickChange, bool brickBlock)
 {
     for (int i = 1; i < loopLength; i++)
     {
         if ((CheckCellEnemy(x + (-i * xDire), y + (-i * yDire), brickChange)))
         {
             ChessMap.SetMoveArray(x + (-i * xDire), y + (-i * yDire), '#');
         }
         if (ChessMap.CheckMapArray(x + (-i * xDire), y + (-i * yDire), ' '))
         {
             ChessMap.SetMoveArray(x + (-i * xDire), y + (-i * yDire), '*');
             ChessMap.SetMapArray(x + (-i * xDire), y + (-i * yDire), '*');
         }
         else if (brickBlock == true)
         {
             return;
         }
     }
 }
コード例 #10
0
        // Used to move the brick
        protected void MoveBrick(int y, int x)
        {
            if ((y != yLast) || (x != xLast))
            {
                if ((ChessMap.CheckMoveArray(x, y, '*')) || (ChessMap.CheckMoveArray(x, y, '#')))
                {
                    // Pawn rule when touching the edge of the map
                    if ((y == 0) && (brickStore == 'A'))
                    {
                        brickStore = 'E';
                    }
                    if ((y == 7) && (brickStore == 'a'))
                    {
                        brickStore = 'e';
                    }

                    int brickCounter = 0;
                    if (ChessMap.CheckMoveArray(x, y, '#'))
                    {
                        brickCounter = 1;
                        if (ChessMap.enableSound == true)
                        {
                            snd_click02.Play();
                        }
                    }
                    else if (ChessMap.enableSound == true)
                    {
                        snd_click01.Play();
                    }

                    ChessMap.SetMapArray(x, y, brickStore);
                    ChessMap.SetMoveArray(x, y, ' ');
                    ChessMap.SetMapArray(xLast, yLast, ' ');
                    brickStore = '!';

                    // Changes the brick team
                    TeamChange(brickCounter);
                }
                ChessMap.brickSelected = false;
            }
        }
コード例 #11
0
ファイル: ChessBoard.cs プロジェクト: jonash871j/Chess-WPF
        public ChessBoard(Grid grid, TextBlock UI01, TextBlock UI02, TextBlock UI03, TextBlock UI04)
        {
            ChessMap.Reset();
            this.grid = grid;
            this.UI01 = UI01;
            this.UI02 = UI02;
            this.UI03 = UI03;
            this.UI04 = UI04;

            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    mapButton[y, x]        = new Button();
                    mapButton[y, x].Tag    = y * 8 + x;
                    mapButton[y, x].Click += new RoutedEventHandler(button_Click);

                    img[y, x] = new Image();
                }
            }
        }
コード例 #12
0
        /*******************************************************************/
        // KNIGHT LOGIC                                                    */
        /*******************************************************************/
        protected void CheckKnight(int y, int x, char brickChar, bool brickChange)
        {
            // Used to set what direction the brick should go on the y axis
            CheckBrickChange(brickChange);

            if (ChessMap.CheckMapArray(x, y, brickChar))
            {
                // Set marker where the horse brick can move and kill
                CheckMovement(2, x, y, brickDire, brickDire * 2, brickChange, false);
                CheckMovement(2, x, y, -brickDire, brickDire * 2, brickChange, false);
                CheckMovement(2, x, y, brickDire, -brickDire * 2, brickChange, false);
                CheckMovement(2, x, y, -brickDire, -brickDire * 2, brickChange, false);
                CheckMovement(2, x, y, brickDire * 2, brickDire, brickChange, false);
                CheckMovement(2, x, y, brickDire * 2, -brickDire, brickChange, false);
                CheckMovement(2, x, y, -brickDire * 2, brickDire, brickChange, false);
                CheckMovement(2, x, y, -brickDire * 2, -brickDire, brickChange, false);

                // Used to set brick variables
                SetBrickVariables(brickChar, x, y);
            }
        }
コード例 #13
0
 // Used clear all brick markers
 protected void ClearBrickMarker()
 {
     for (int y = 0; y < 8; y++)
     {
         for (int x = 0; x < 8; x++)
         {
             if (ChessMap.brickSelected == false)
             {
                 if (ChessMap.CheckMoveArray(x, y, '*'))
                 {
                     ChessMap.SetMoveArray(x, y, ' ');
                     ChessMap.SetMapArray(x, y, ' ');
                 }
                 if (ChessMap.CheckMoveArray(x, y, '#'))
                 {
                     ChessMap.SetMoveArray(x, y, ' ');
                 }
             }
         }
     }
 }