Exemple #1
0
void CStageBox::StageTouchMoved(Point a_ptTouchPosition)
{
	if (m_isSelectMapLayer)
		return;

	if (m_ptBeganTouchPosition.x - a_ptTouchPosition.x > 0 &&
		m_pBoxPiece[2][0]->getScale() < 1)
	{
		PieceMove(-ScrollValue);
	}
	else if (m_ptBeganTouchPosition.x - a_ptTouchPosition.x <= 0 &&
		m_pBoxPiece[0][0]->getScale() < 1)
	{
		PieceMove(ScrollValue);
	}

	m_ptBeganTouchPosition = a_ptTouchPosition;
}
Exemple #2
0
/*
 * ChessMovePerform:  Perform the move from p1 to p2 on the given board.  Assumes
 *   that the move is legal.
 *   If interactive is True, ask user for piece on pawn promotion if necessary.
 */
void ChessMovePerform(Board *b, POINT p1, POINT p2, Bool interactive)
{
   BYTE piece;
   POINT p3, p4;
   int direction;

   piece = b->squares[p1.y][p1.x].piece;
   if (piece == PAWN && interactive &&
       ((b->move_color == WHITE && p2.y == BOARD_HEIGHT - 1) ||
	(b->move_color == BLACK && p2.y == 0)))
   {
      // Ask for pawn promotion piece
      piece = ChessGetPromotionPiece();
   }

   b->squares[p1.y][p1.x].piece = piece;  // In case piece changed due to promotion
   PieceMove(b, p1, p2);
   
   // If a castling move, move the rook also (assumes move is legal; rook must be in place)
   if (piece == KING && abs(p2.x - p1.x) > 1)
   {
      // Move rook at p3 to new location at p4
      p3.y = p2.y;
      p4.y = p2.y;
      if (p2.x == 1)
      {
	 p3.x = 0;
	 p4.x = 2;
      }
      else
      {
	 p3.x = 7;
	 p4.x = 4;
      }
      PieceMove(b, p3, p4);
   }

   // Check for en passant capture
   if (piece == PAWN && b->en_passant &&
       p2.x == b->passant_square.x && p2.y == b->passant_square.y)
   {
      direction = (b->move_color == WHITE) ? 1 : -1;
      b->squares[p2.y - direction][p2.x].piece = NONE;
   }

   
   // Set castling flags if king or rook moved
   if (piece == KING)
   {
      b->pdata[b->move_color].can_castle_left  = False;
      b->pdata[b->move_color].can_castle_right = False;
   }
   else if (piece == ROOK)
   {
      if (((b->move_color == WHITE && p1.y == 0) || (b->move_color == BLACK && p1.y == 7)))
	 if (p1.x == 0)
	    b->pdata[b->move_color].can_castle_left = False;
	 else if (p1.x == 7)
	    b->pdata[b->move_color].can_castle_right = False;
   }

   // Set en passant information
   if (piece == PAWN && abs(p2.y - p1.y) > 1) 
   {
      b->en_passant = True;
      b->passant_square.x = p1.x;
      b->passant_square.y = (p1.y + p2.y) / 2;
   }
   else b->en_passant = False;
   
   if (b->move_color == WHITE)
      b->move_color = BLACK;
   else b->move_color = WHITE;
}
Exemple #3
0
void CStageBox::PieceAutoMove()
{
	float  CheckPositionX[3];

	CheckPositionX[0] = fabsf(635 - m_pBoxPiece[0][0]->getPositionX());
	CheckPositionX[1] = fabsf(635 - m_pBoxPiece[1][0]->getPositionX());
	CheckPositionX[2] = fabsf(635 - m_pBoxPiece[2][0]->getPositionX());

	if (CheckPositionX[0] < CheckPositionX[1])
	{
		if (CheckPositionX[0] < CheckPositionX[2])
			m_nNowStageNumber = 0;
		else
			m_nNowStageNumber = 2;
	}
	else
	{
		if (CheckPositionX[1] < CheckPositionX[2])
			m_nNowStageNumber = 1;
		else
			m_nNowStageNumber = 2;
	}

	switch (m_nNowStageNumber)
	{
	case 0:
		if (m_pBoxPiece[0][0]->getPositionX() < 635)
		{
			m_isCanTouch = false;
			PieceMove(5);
		}
		else
		{
			m_isCanTouch = true;
		}
		break;
	case 1:
		if (m_pBoxPiece[1][0]->getPositionX() < 635)
		{
			m_isCanTouch = false;
			PieceMove(5);
		}
		else if (m_pBoxPiece[1][0]->getPositionX() > 635)
		{
			m_isCanTouch = false;
			PieceMove(-5);
		}
		else
		{
			m_isCanTouch = true;
		}

		break;
	case 2:
		if (m_pBoxPiece[2][0]->getPositionX() > 635)
		{
			PieceMove(-5);
			m_isCanTouch = false;
		}
		else
		{
			m_isCanTouch = true;
		}
		break;
	default:
		break;
	}
}