예제 #1
0
        private static bool IsAbleToJumpRight(CheckersPiece piece, AllCheckerPieces allPieces)
        {
            bool canJumpRight = false;

            int[,] takenSquares = allPieces.GetTakenSquares();
            bool isWhite = piece.IsWhite();
            int  row     = piece.GetPosition()[0];
            int  column  = piece.GetPosition()[1];

            if (column == 7)
            {
                return(canJumpRight);
            }

            else if (isWhite && takenSquares[row - 1, column + 1] != 0)
            {
                return(canJumpRight);
            }

            else if (!isWhite && takenSquares[row + 1, column + 1] != 0)
            {
                return(canJumpRight);
            }

            else
            {
                return(!canJumpRight);
            }
        }
예제 #2
0
 public static bool[] IsAbleToEat(CheckersPiece piece, AllCheckerPieces allPieces)
 {
     bool[] canEat = new bool[2] {
         IsAbleToEatLeft(piece, allPieces), IsAbleToEatRight(piece, allPieces)
     };
     return(canEat);
 }
예제 #3
0
 public static bool[] IsAbleToJump(CheckersPiece piece, AllCheckerPieces allPieces)
 {
     bool[] canJump = new bool[2] {
         IsAbleToJumpLeft(piece, allPieces), IsAbleToJumpRight(piece, allPieces)
     };
     return(canJump);
 }
예제 #4
0
        public void AddPiece(CheckersPiece piece)
        {
            checkersPieces.Add(piece);
            int[] pos = piece.GetPosition();
            if (piece.IsWhite())
            {
                takenSquares[pos[0], pos[1]] = 1;
            }

            else
            {
                takenSquares[pos[0], pos[1]] = 2;
            }
        }
예제 #5
0
        public MainWindow()
        {
            InitializeComponent();
            WhitePieceImageBrush.ImageSource         = new BitmapImage(new Uri("../../img/WhiteCheckersPiece.png", UriKind.Relative));
            WhitePieceSelectedImageBrush.ImageSource = new BitmapImage(new Uri("../../img/WhiteCheckersPieceSelected.png", UriKind.Relative));

            BlackPieceImageBrush.ImageSource         = new BitmapImage(new Uri("../../img/BlackCheckersPiece.png", UriKind.Relative));
            BlackPieceSelectedImageBrush.ImageSource = new BitmapImage(new Uri("../../img/BlackCheckersPieceSelected.png", UriKind.Relative));

            MoveButtonImageBrush.ImageSource = new BitmapImage(new Uri("../../img/MoveButtonImage.png", UriKind.Relative));

            initPieces();
            lastPiece = Checkerboard.Children.Cast <UIElement>().First(e => Grid.GetRow(e) == 7 && Grid.GetColumn(e) == 0) as CheckersPiece;
            WhiteTurn = true;
        }
예제 #6
0
        private static bool IsAbleToEatLeft(CheckersPiece piece, AllCheckerPieces allPieces)
        {
            bool canEatLeft = false;

            int[,] takenSquares = allPieces.GetTakenSquares();
            bool isWhite = piece.IsWhite();
            int  row     = piece.GetPosition()[0];
            int  column  = piece.GetPosition()[1];

            if (column == 0 || column == 1)
            {
                return(canEatLeft);
            }

            return(false);
        }
예제 #7
0
        private void initPieces()
        {
            bool isWhite = false;

            int[] pos;

            CheckersPiece piece;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 7 - i % 2; j >= 0; j = j - 2)
                {
                    pos    = new int[2];
                    pos[0] = i;
                    pos[1] = j;

                    piece        = new CheckersPiece(isWhite, pos);
                    piece.Click += BlackPiece_Click;
                    piece.SetPieceBackground(BlackPieceImageBrush);
                    allPieces.AddPiece(piece);
                }
            }

            isWhite = true;
            for (int i = 5; i < 8; i++)
            {
                for (int j = 7 - i % 2; j >= 0; j = j - 2)
                {
                    pos    = new int[2];
                    pos[0] = i;
                    pos[1] = j;

                    piece        = new CheckersPiece(isWhite, pos);
                    piece.Click += WhitePiece_Click;
                    piece.SetPieceBackground(WhitePieceImageBrush);
                    allPieces.AddPiece(piece);
                }
            }

            foreach (CheckersPiece aPiece in allPieces.GetCheckersPieces())
            {
                Grid.SetRow(aPiece, aPiece.GetPosition()[0]);
                Grid.SetColumn(aPiece, aPiece.GetPosition()[1]);
                Checkerboard.Children.Add(aPiece);
            }
        }
예제 #8
0
 private void WhitePiece_Click(object sender, RoutedEventArgs e)
 {
     if (WhiteTurn)
     {
         CheckersPiece piece             = sender as CheckersPiece;
         bool          isAbleToJumpLeft  = UtilityClass.IsAbleToJump(piece, allPieces)[0];
         bool          isAbleToJumpRight = UtilityClass.IsAbleToJump(piece, allPieces)[1];
         bool          isAbleToEatLeft   = UtilityClass.IsAbleToEat(piece, allPieces)[0];
         bool          isAbleToEatRight  = UtilityClass.IsAbleToEat(piece, allPieces)[1];
         if (isAbleToEatLeft || isAbleToEatRight || isAbleToJumpLeft || isAbleToJumpRight)
         {
             piece.SetPieceBackground(WhitePieceSelectedImageBrush);
             lastPiece.SetPieceBackground(WhitePieceImageBrush);
             lastPiece = piece;
         }
     }
 }