//-------------------------------------------------------------------------- // MoveToPoint // ----------- // General : Checks if active target can move to the // given target, and moves the checker // there if its true // Parameters : opp1 - x coordinate of chosen target // opp2 - y coordinate of chosen target // opp3 - must jump in this turn or not // opp4 - handle to window // Return Value : Moved to the target point or not //-------------------------------------------------------------------------- MoveType CPlay::MoveToPoint(int destX, int destY,HDC &hdc,HWND &hWnd,bool pc) { MoveType moved = NOMOVE; //increasing to match the game board if(!pc) { destY = destY + WALL_SIZE; destX = destX + WALL_SIZE; } if(pc || IsPossibleMove(destX,destY)) //checks if possible to move { ClearPossibleMoves(hWnd); //moves the checker if( (destY == WALL_SIZE && m_Board[m_Active.y][m_Active.x] == BLUECHECKER) || (destY == GAMEBOARD_SIZE - WALL_SIZE - 1 && m_Board[m_Active.y][m_Active.x] == REDCHECKER) ) m_Board[destY][destX] = m_Board[m_Active.y][m_Active.x]*2; else m_Board[destY][destX] = m_Board[m_Active.y][m_Active.x]; m_Board[m_Active.y][m_Active.x] = EMPTY; MoveCheckerPt(m_Turn,m_Active.x,m_Active.y,destX,destY); moved = MOVE; if (m_MustJump !=0) //jump was made { //captured checker = 0 m_Board[m_Active.y + (destY - m_Active.y)/2] [m_Active.x + (destX - m_Active.x)/2] = EMPTY; MoveCheckerPt(-m_Turn, m_Active.x + (destX - m_Active.x)/2, m_Active.y + (destY - m_Active.y)/2,-1,-1); moved = JUMP; } ClearPossibleMoves(); if(!pc && m_MustJump) { //checks for more possible moves m_MustJump = CheckJump(destX,destY,true); if(m_MustJump) { moved = MULTIJUMP; m_Active.x = destX; m_Active.y = destY; DrawPossibleMoves(hdc); } } else { m_Active.x = NONE; m_Active.y = NONE; } } return moved; }
void MainWindow::paintEvent(QPaintEvent* event){ QPainter painter(this); DrawBoard(painter); if (!promotion && startPiece){ QPen pen(Qt::red); painter.setPen(pen); painter.drawRect(startX*CELL_SIZE, startY*CELL_SIZE, CELL_SIZE, CELL_SIZE); DrawPossibleMoves(painter); } DrawStatus(painter); }
//-------------------------------------------------------------------------- // ActivateChecker // --------------- // General : Runs checks in order to determine if // a checker the user wants to select is // able to make a move // Parameters : opp1 - x coordinate of chosen checker // opp2 - y coordinate of chosen checker // opp3 - HDC (device context) // Return Value : Possible to move this checker or not //-------------------------------------------------------------------------- int CPlay::ActivateChecker(int x, int y, HDC &hdc,HWND &hWnd) { //increasing to match the game board x = x + WALL_SIZE; y = y + WALL_SIZE; ClearPossibleMoves(hWnd); ClearPossibleMoves(); int Moving = 0; if(m_MustJump == 1) Moving = CheckJump(x,y,true); else Moving = CheckMove(x,y,true); if(Moving) { //draws moves possibilites DrawPossibleMoves(hdc); //creates brushes for coloring HBRUSH red,blue; red = CreateSolidBrush(RGB(200,130,130)); blue = CreateSolidBrush(RGB(180,180,250)); //choosing color if(m_Board[y][x]==REDCHECKER || m_Board[y][x]==REDKING) SelectObject(hdc,red); else SelectObject(hdc,blue); //drawing the checker Ellipse(hdc,(x - WALL_SIZE)*SQUARE_SIZE,(y - WALL_SIZE)*SQUARE_SIZE, SQUARE_SIZE + (x - WALL_SIZE)*SQUARE_SIZE, SQUARE_SIZE + (y - WALL_SIZE)*SQUARE_SIZE); DeleteObject(red); DeleteObject(blue); m_Active.x = x; m_Active.y = y; return Moving; } return Moving; }