示例#1
0
 private void selectPawn(Position position)
 {
     tempPos = position;
     selectedPosition = position;
     selectedPosition.isSelected = true;
     Invalidate();
     Update();
 }
示例#2
0
 private void setDiferencesXY(Position currPos, out int differenceX, out int differenceY)
 {
     differenceX = tempPos.getX() - currPos.getX();
     differenceY = tempPos.getY() - currPos.getY();
 }
示例#3
0
 private void movePawn(Position currPos)
 {
     currPos.setPawn(tempPos.getPawn()); // set pawn on position
     deletePawn();
 }
示例#4
0
        private void movePawnToEmptySpace(Position selectedPosition)
        {
            int distanceX; int distanceY;
            setDiferencesXY(selectedPosition, out distanceX, out distanceY);

            if (isMoveAllowed(selectedPosition, distanceX, distanceY))
            {
                movePawn(selectedPosition);
                nextPlayerTurn();
            }
        }
示例#5
0
 private bool isMoveAllowed(Position selectedPosition, int distanceX, int distanceY)
 {
     return checkMoveAllowance(selectedPosition, distanceX, distanceY, 1) || (checkMoveAllowance(selectedPosition, distanceX, distanceY, 2) && checkForNearbyPieces(selectedPosition, distanceX, distanceY));
 }
示例#6
0
 private bool isPositionsEqual(Position pos1, Position pos2)
 {
     if (pos1 != null && pos2 != null)
     {
         if (pos1.getX() == pos2.getX() && pos1.getY() == pos2.getY())
             return true;
     }
     return false;
 }
示例#7
0
        private void drawCell(Graphics g, int marginX, int marginY, int incValue, int a, int y, int x)
        {
            Brush cellColor;
            if (isPositionEven(y, x))
                cellColor = new SolidBrush(Color.White);
            else
                cellColor = new SolidBrush(Color.Black);

            if (validateSelectedPosition(y, x))
                cellColor = new SolidBrush(Color.LightGreen);

            if (isGeneratedStartPawnSet == false)
                positions[x, y] = new Position();

            g.FillRectangle(cellColor, marginX + x * incValue, marginY + y * incValue, a, a);
        }
示例#8
0
 private void deselectPawn()
 {
     selectedPosition.isSelected = false;
     tempPos = null;
     Invalidate();
     Update();
 }
示例#9
0
 private bool checkPlayerTurn(Position pos)
 {
     if (!pos.isEmpty && pos.getPawn().getColor().Equals(players[playerNrAllowedToMove].color))
         return true;
     else
     {
         MessageBox.Show("It's "+ (players[playerNrAllowedToMove].color.Name) + " Player move!");
         return false;
     }
 }
示例#10
0
 private bool checkMoveAllowance(Position selectedPosition, int distanceX, int distanceY, int radius)
 {
     return checkPosition(distanceX, distanceY, radius) && selectedPosition.isEmpty;
 }
示例#11
0
 private static bool checkForNearbyPieces(Position selectedPosition, int distanceX, int distance)
 {
     return !positions[selectedPosition.getX() + ((distanceX != 0 ? (distanceX > 0 ? distanceX - 1 : distanceX + 1) : 0)),
                             selectedPosition.getY() + ((distance != 0 ? (distance > 0 ? distance - 1 : distance + 1) : 0))].isEmpty;
 }