int CPiece::moveTo(const CGameBoard::CSquare& _to) { //check validity of moving ... int res = 0; if(isAllowedMoveTo(_to)){ if(_to.isBusyByOther(color)){ //notice about attack } _to.setPiece(this); res = setPos(_to); } return res; }
void Figure::mouseReleaseEvent(QGraphicsSceneMouseEvent* apEvent) { QGraphicsPixmapItem::mouseReleaseEvent(apEvent); QPointF tPoint = this->pos(); tPoint.setX(tPoint.x() + this->boundingRect().width() / 2.f); tPoint.setY(tPoint.y() + this->boundingRect().height() / 2.f); tPoint.setX(XTopWorld - tPoint.x()); tPoint.setY(XTopWorld - tPoint.y()); uint tX = abs(tPoint.x() / WordCeilSize) + 1u; uint tY = 8u - abs(tPoint.y() / WordCeilSize); switch (mpContext->isFreeFor(mFraction, tX, tY)) { case FreeType::Busy: moveTo(mX, mY); break; case FreeType::Fight: if(isAllowedFightAt(tX, tY)) { makeFight(tX, tY); } else { moveTo(mX, mY); } break; case FreeType::Free: if(isAllowedMoveTo(tX, tY)) { moveTo(tX, tY); } else { moveTo(mX, mY); } break; default: break; } setZValue(0); }