⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 board.cpp

📁 qgo-1.5.4-r3.tar.gz linux下一个很好玩的游戏
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        return NULL;  // Oops}#ifndef NO_DEBUGvoid Board::debug(){    qDebug("Board::debug()");	#if 1    Mark *m = NULL;    for (m=marks->first(); m != NULL; m=marks->next())    {		qDebug("posX:%d posY:%d  rtti:%d", m->posX(), m->posY(), m->rtti());    }#endif	#if 0    QCanvasItemList list = canvas->allItems();    int numC = list.count() - 42;  // 19 + 19 + 4	    int numS = boardHandler->getStoneHandler()->numStones();        qDebug("We currently have %d stones in the canvas, and %d stones in the stonehandler.",		numC, numS);#endif	#if 1    boardHandler->debug();#endif}#endifvoid Board::leaveEvent(QEvent*){    curStone->hide();    canvas->update();}int Board::convertCoordsToPoint(int c, int o){    int p = c - o + square_size/2;    if (p >= 0)		return p / square_size + 1;    else		return -1;}void Board::contentsMouseMoveEvent(QMouseEvent *e){    int x = convertCoordsToPoint(e->x(), offsetX),		y = convertCoordsToPoint(e->y(), offsetY);        // Outside the valid board?    if (x < 1 || x > board_size || y < 1 || y > board_size)    {		curStone->hide();		canvas->update();		curX = curY = -1;		return;    }	    // Nothing changed    if (curX == (short)x && curY == (short)y)		return;	    // Update the statusbar coords tip    emit coordsChanged(x, y, board_size,showSGFCoords);	    // Remember if the cursor was hidden meanwhile.    // If yes, we need to repaint it at the old position.    bool flag = curX == -1;	    curX = (short)x;    curY = (short)y;        if (!showCursor || //setting->readBoolEntry("CURSOR") ||		(boardHandler->getGameMode() == modeEdit &&		boardHandler->getMarkType() != markNone) ||		boardHandler->getGameMode() == modeScore ||		(curStone->posX() == x &&		curStone->posY() == y && !flag))		return;        curStone->setX(offsetX + square_size * (x-1));    curStone->setY(offsetY + square_size * (y-1));    curStone->setPos(x, y);    bool notMyTurn = 	(curStone->getColor() == stoneBlack && !myColorIsBlack ||			 curStone->getColor() == stoneWhite && myColorIsBlack);        if (navIntersectionStatus ||                      boardHandler->getGameMode() == modeObserve ||	( boardHandler->getGameMode() == modeMatch && notMyTurn) ||	( boardHandler->getGameMode() == modeComputer && notMyTurn))			curStone->hide();    else		curStone->show();        canvas->update();}void Board::contentsWheelEvent(QWheelEvent *e){    // leave if observing or playing    if (//boardHandler->getGameMode() == modeObserve ||		boardHandler->getGameMode() == modeMatch ||		boardHandler->getGameMode() == modeTeach)		return;        // Check delay    if (QTime::currentTime() < wheelTime)		return;	    // Needs an extra check on variable mouseState as state() does not work on Windows.    if (e->delta() != 120) // QQQ weel down to next    {		if (e->state() == RightButton || mouseState == RightButton)			nextVariation();		else			nextMove();    }    else    {		if (e->state() == RightButton || mouseState == RightButton)			previousVariation();		else			previousMove();    }        // Delay of 100 msecs to avoid too fast scrolling    wheelTime = QTime::currentTime();    wheelTime = wheelTime.addMSecs(50);        e->accept();}void Board::contentsMouseReleaseEvent(QMouseEvent* e){	mouseState = NoButton;    	int 	x = convertCoordsToPoint(e->x(), offsetX),		y = convertCoordsToPoint(e->y(), offsetY);		//qDebug("Mouse should be released after %d,%03d", wheelTime.second(),wheelTime.msec());	//qDebug("Mouse released at time         %d,%03d", QTime::currentTime().second(),QTime::currentTime().msec());		if ( 	(boardHandler->getGameMode()==modeMatch) &&     		(QTime::currentTime() > wheelTime))	{					if (boardHandler->getBlackTurn())		{			if (myColorIsBlack)			{				boardHandler->addStone(stoneBlack, x, y);				emit signal_addStone(stoneBlack, x, y);			}		}		else		{			if (!myColorIsBlack)			{				boardHandler->addStone(stoneWhite, x, y);				emit signal_addStone(stoneWhite, x, y);			}		}  		}			 }void Board::contentsMousePressEvent(QMouseEvent *e){    setFocus();        mouseState = e->button();        int x = convertCoordsToPoint(e->x(), offsetX),		y = convertCoordsToPoint(e->y(), offsetY);	    // Button gesture outside the board?    if (x < 1 || x > board_size || y < 1 || y > board_size)    {		if (e->button() == LeftButton &&			e->state() == RightButton)			previousMove();		else if (e->button() == RightButton &&			e->state() == LeftButton)			nextMove();		else if (e->button() == LeftButton &&			e->state() == MidButton)			gotoVarStart();		else if (e->button() == RightButton &&			e->state() == MidButton)			gotoNextBranch();				return;    }	    // Lock accidental gesture over board    if ((e->button() == LeftButton && e->state() == RightButton) ||		(e->button() == RightButton && e->state() == LeftButton) ||		(e->button() == LeftButton && e->state() == MidButton) ||		(e->button() == RightButton && e->state() == MidButton))		return;          // Ok, we are inside the board, and it was no gesture.    // We just handle the case of getting where the mouse was clicked    if (navIntersectionStatus) // added eb 11    {        navIntersectionStatus = false;//   *** Several unsuccessfull tries with clean method ***        //      unsetCursor();//      setCursor(ArrowCursor);//      this->topLevelWidget()->setCursor(ArrowCursor);//   *** Therefore we apply thick method :        QApplication::restoreOverrideCursor();          boardHandler->findMoveByPos(x, y);                                 //SL added eb 11	return;	}                         // end add eb 11    // resume normal proceeding    switch (boardHandler->getGameMode())    {    case modeNormal:		switch (e->button())		{		case LeftButton:			if (e->state() == ShiftButton)   // Shift: Find move in main branch			{				navIntersectionStatus = false;				boardHandler->findMoveByPos(x, y);                                 //SL added eb 11				return;			}			else if (e->state() == ControlButton)  // Control: Find move in all following variations			{				if (boardHandler->findMoveInVar(x, y))  // Results found?				{					// Init dialog if not yet done					if (nodeResultsDlg == NULL)					{						nodeResultsDlg = new NodeResults(this, "noderesult", WType_TopLevel);						connect(nodeResultsDlg, SIGNAL(doFump(Move*)), this, SLOT(gotoMove(Move*)));					}					nodeResultsDlg->setNodes(boardHandler->nodeResults);					nodeResultsDlg->show();					nodeResultsDlg->raise();				}				return;			}			if (boardHandler->getBlackTurn())				boardHandler->addStone(stoneBlack, x, y);			else				boardHandler->addStone(stoneWhite, x, y);						break;					case RightButton:			if (e->state() == ShiftButton)  // Shift: Find move in this branch			{				boardHandler->findMoveByPosInVar(x, y);				return;			}			break;					default:			break;		}		break;			case modeEdit:		switch (e->button())		{		case LeftButton:			if (boardHandler->getMarkType() == markNone)				boardHandler->addStone(stoneBlack, x, y);			else			{				// Shift-click setting a text mark				if (boardHandler->getMarkType() == markText &&					e->state() == ShiftButton)				{					// Dont open dialog if a text mark already exists					Mark *m;					QString oldTxt = NULL;					// If its a text mark, get the old text and put it in the dialog					if ((m = hasMark(x, y)) != NULL &&						m->getType() == markText)						oldTxt = boardHandler->getTree()->getCurrent()->getMatrix()->getMarkText(x, y);					// Get the label string from the dialog. Moved to inferface handler					// to keep the dialog stuff out of this class.					QString txt = getInterfaceHandler()->getTextLabelInput(this, oldTxt);					if (txt.isNull() || txt.isEmpty())  // Aborted dialog						break;					setMark(x, y, markText, true, txt);				}				else					setMark(x, y, boardHandler->getMarkType());				canvas->update();			}			break;		case RightButton:			if (boardHandler->getMarkType() == markNone)				boardHandler->addStone(stoneWhite, x, y);			else			{				removeMark(x, y);				canvas->update();			}			break;		default:			break;		}		break;			case modeScore:		switch (e->button())		{		case LeftButton:			if (get_isLocalGame())				boardHandler->markDeadStone(x, y);  // Mark or unmark as dead			emit signal_addStone(stoneBlack, x, y); // the client accepts a coordinate in scoring mode			break;		case RightButton:			if (get_isLocalGame())				boardHandler->markSeki(x, y);  // Mark group as alive in seki			emit signal_addStone(stoneBlack, x, y); // the client accepts a coordinate in scoring mode			break;		default:			break;		}		break;			case modeObserve:		// do nothing but observe		break;			case modeMatch:		// Delay of 250 msecs to avoid clickos    		wheelTime = QTime::currentTime();    		//qDebug("Mouse pressed at time %d,%03d", wheelTime.second(),wheelTime.msec());		if (antiClicko)			wheelTime = wheelTime.addMSecs(250);						/*if (boardHandler->getBlackTurn())		{			if (myColorIsBlack)			{				boardHandler->addStone(stoneBlack, x, y);				emit signal_addStone(stoneBlack, x, y);			}		}		else		{			if (!myColorIsBlack)			{				boardHandler->addStone(stoneWhite, x, y);				emit signal_addStone(stoneWhite, x, y);			}		}*/		break;	case modeComputer:                          //added eb 12			if (boardHandler->getBlackTurn())		{			if (myColorIsBlack)			{				boardHandler->addStone(stoneBlack, x, y);				emit signal_Stone_Computer(stoneBlack, x, y);			}		}		else		{			if (!myColorIsBlack)			{				boardHandler->addStone(stoneWhite, x, y);				emit signal_Stone_Computer(stoneWhite, x, y);			}		}		break;                                   // end add eb 12        			case modeTeach:		if (boardHandler->getBlackTurn())		{			boardHandler->addStone(stoneBlack, x, y);			emit signal_addStone(stoneBlack, x, y);		}		else		{			boardHandler->addStone(stoneWhite, x, y);			emit signal_addStone(stoneWhite, x, y);		}		break;			default:		qWarning("   *** Invalid game mode! ***");    }}void Board::increaseSize(){    resizeBoard(canvas->width() + 20, canvas->height() + 20);}void Board::decreaseSize(){    QSize s = viewportSize(width()-5, height()-5);    if (canvas->width() - 20 < s.width() ||		canvas->height() - 20 < s.height())		return;    resizeBoard(canvas->width() - 20, canvas->height() - 20);}void Board::changeSize(){#ifdef Q_WS_WIN    resizeDelayFlag = false;#endif    QSize s = viewportSize(width()-5, height()-5);    resizeBoard(s.width(), s.height());}void Board::hideAllStones(){    QCanvasItemList list = canvas->allItems();    QCanvasItem *item;        QCanvasItemList::Iterator it;    for(it = list.begin(); it != list.end(); ++it)    {		item = *it;		if (item->rtti() == RTTI_STONE)			item->hide();    }}void Board::hideAllMarks(){    MarkText::maxLength = 1;    marks->clear();		    gatter->showAll();    for (int i=0; i<400; i++)    {		if (i < 52)			letterPool[i] = false;		numberPool[i] = false;    }}bool Board::openSGF(const QString &fileName, const QString &filter){	    // Load the sgf    if (!boardHandler->loadSGF(fileName, filter, fastLoad))		return false;	    canvas->update();    setModified(false);    return true;}bool Board::startComputerPlay(QNewGameDlg * dlg,const QString &fileName, const QString &filter,const QString &computer_path){     // Clean up everything and get to last move    //clearData();        // Initiate the dialog with computer    if (!boardHandler->openComputerSession(dlg,fileName,filter,computer_path))    		return false;       canvas->update();    setModified(false);    return true;}void Board::clearData(){    hideAllStones();    hideAllMarks();    ghosts->clear();    removeLastMoveMark();    boardHandler->clearData();    if (curStone != NULL)		curStone->setColor(stoneBlack);    canvas->update();    isModified = false;    if (nodeResultsDlg != NULL)    {		nodeResultsDlg->hide();		delete nodeResultsDlg;		nodeResultsDlg = NULL;    }}void Board::updateComment(){    boardHandler->updateComment();}void Board::updateComment2(){	// emit signal to opponent in online game	sendcomment(getInterfaceHandler()->getComment2());}void Board::modifiedComment(){    setModified();}void Board::setMark(int x, int y, MarkType t, bool update, QString txt, bool overlay){    if (x == -1 || y == -1)		return;	    Mark *m;    // We already have a mark on this spot? If it is of the same type,    // do nothing, else overwrite with the new mark.    if ((m = hasMark(x, y)) != NULL)    {		if (m->getType() == t && m->getType() != markText)  // Text labels are overwritten			return;				removeMark(x, y, update);    }        if (lastMoveMark != NULL &&		lastMoveMark->posX() == x &&		lastMoveMark->posY() == y)		removeLastMoveMark();	    QColor col = black;	    // Black stone or black ghost underlying? Then we need a white mark.    if ((boardHandler->hasStone(x, y) == 1 &&		boardHandler->getStoneHandler()->getStoneAt(x, y)->getColor() == stoneBlack) ||		(setting->readIntEntry("VAR_GHOSTS") && hasVarGhost(stoneBlack, x, y)))		col = white;        short n = -1;	    switch(t)    {    case markSquare:		m = new MarkSquare(x, y, square_size, canvas, col);		break;		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -