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

📄 board.cpp

📁 qgo-1.5.4-r3.tar.gz linux下一个很好玩的游戏
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    case markCircle:		m = new MarkCircle(x, y, square_size, canvas, col, true);//setting->readBoolEntry("SMALL_STONES"));        break;		    case markTriangle:		m = new MarkTriangle(x, y, square_size, canvas, col);		break;		    case markCross:		m = new MarkCross(x, y, square_size, canvas, col);		break;		    case markText:		if (txt == NULL)		{			n = 0;			while (letterPool[n] && n < 51)				n++;			letterPool[n] = true;						txt = QString(QChar(static_cast<const char>('A' + (n>=26 ? n+6 : n))));						// Update matrix with this letter			boardHandler->getTree()->getCurrent()->getMatrix()->setMarkText(x, y, txt);		}		else if (txt.length() == 1)		{			// Text was given as argument, check if it can converted to a single letter			n = -1;			if (txt[0] >= 'A' && txt[0] <= 'Z')				n = txt[0].latin1() - 'A';			else if (txt[0] >= 'a' && txt[0] <= 'a')				n = txt[0].latin1() - 'a' + 26;						if (n > -1)				letterPool[n] = true;		}		m = new MarkText(imageHandler, x, y, square_size, txt, canvas, col, n, false, overlay);		gatter->hide(x,y);//setMarkText(x, y, txt);		break;		    case markNumber:		if (txt == NULL)		{			n = 0;			while (numberPool[n] && n < 399)				n++;						txt = QString::number(n+1);						// Update matrix with this letter			boardHandler->getTree()->getCurrent()->getMatrix()->setMarkText(x, y, txt);	    		}		else			n = txt.toInt() - 1;		numberPool[n] = true;		m = new MarkNumber(imageHandler, x, y, square_size, n, canvas, col, false);		setMarkText(x, y, txt);		gatter->hide(x,y);		break;		    case markTerrBlack:		m = new MarkTerr(x, y, square_size, stoneBlack, canvas);		if (boardHandler->hasStone(x, y) == 1)		{			boardHandler->getStoneHandler()->getStoneAt(x, y)->setDead(true);			boardHandler->getStoneHandler()->getStoneAt(x, y)->setSequence(imageHandler->getGhostPixmaps());			boardHandler->getStoneHandler()->getStoneAt(x, y)->shadow->hide();			boardHandler->markedDead = true;		}		boardHandler->getTree()->getCurrent()->setScored(true);		break;		    case markTerrWhite:		m = new MarkTerr(x, y, square_size, stoneWhite, canvas);		if (boardHandler->hasStone(x, y) == 1)		{			boardHandler->getStoneHandler()->getStoneAt(x, y)->setDead(true);			boardHandler->getStoneHandler()->getStoneAt(x, y)->setSequence(imageHandler->getGhostPixmaps());			boardHandler->getStoneHandler()->getStoneAt(x, y)->shadow->hide();			boardHandler->markedDead = true;		}		boardHandler->getTree()->getCurrent()->setScored(true);		break;		    default:		qWarning("   *** Board::setMark() - Bad mark type! ***");		return;    }	    CHECK_PTR(m);    m->setX(offsetX + square_size * (x-1) - m->getSizeX()/2);    m->setY(offsetY + square_size * (y-1) - m->getSizeY()/2);    m->show();	    marks->append(m);	    if (update)		boardHandler->editMark(x, y, t, txt);}void Board::removeMark(int x, int y, bool update){    Mark *m = NULL;	    if (lastMoveMark != NULL &&		lastMoveMark->posX() == x &&		lastMoveMark->posY() == y)		removeLastMoveMark();	    for (m=marks->first(); m != NULL; m=marks->next())    {		if (m->posX() == x && m->posY() == y)		{			if (m->getCounter() != -1)			{				if (m->getType() == markText)					letterPool[m->getCounter()] = false;				else if (m->getType() == markNumber)					numberPool[m->getCounter()] = false;			}						marks->remove(m);			gatter->show(x,y);			if (update)				boardHandler->editMark(x, y, markNone);			return;		}    }}void Board::setMarkText(int x, int y, const QString &txt){    Mark *m;        // Oops, no mark here, or no text mark    if (txt.isNull() || txt.isEmpty() ||		(m = hasMark(x, y)) == NULL || m->getType() != markText)		return;	    m->setText(txt);    // Adjust the position on the board, if the text size has changed.    m->setSize((double)square_size, (double)square_size);    m->setX(offsetX + square_size * (x-1) - m->getSizeX()/2);    m->setY(offsetY + square_size * (y-1) - m->getSizeY()/2);	}Mark* Board::hasMark(int x, int y){    Mark *m = NULL;	    for (m=marks->first(); m != NULL; m=marks->next())		if (m->posX() == x && m->posY() == y)			return m;				return NULL;}void Board::updateLastMove(StoneColor c, int x, int y){  delete lastMoveMark;	lastMoveMark = NULL;	if (x == 20 && y == 20)  // Passing		removeLastMoveMark();	else if (c != stoneNone && x != -1 && y != -1 && x <= board_size && y <= board_size)	{		if (isHidingStones)			lastMoveMark = new MarkRedCircle(x, y, square_size, canvas,				c == stoneBlack ? white : black, true); // QQQ		else			lastMoveMark = new MarkCross(x, y, square_size, canvas,				c == stoneBlack ? white : black, true);		ASSERT(lastMoveMark);		lastMoveMark->setX(offsetX + square_size * (x-1) - lastMoveMark->getSizeX()/2);		lastMoveMark->setY(offsetY + square_size * (y-1) - lastMoveMark->getSizeY()/2);		lastMoveMark->show();	}	setCurStoneColor();}void Board::setCurStoneColor(){    // Switch the color of the ghost stone cursor    if (curStone != NULL)		curStone->setColor(boardHandler->getBlackTurn() ? stoneBlack : stoneWhite);}void Board::removeLastMoveMark(){    if (lastMoveMark != NULL)    {		lastMoveMark->hide();		delete lastMoveMark;		lastMoveMark = NULL;    }}void Board::checkLastMoveMark(int x, int y){    Mark *m = NULL;        for (m=marks->first(); m != NULL; m=marks->next())    {		if (m->posX() == x && m->posY() == y &&			m->rtti() != RTTI_MARK_TERR &&			m->getColor() == white)		{			m->setColor(black);			break;		}    }	    if (lastMoveMark == NULL ||		lastMoveMark->posX() != x ||		lastMoveMark->posY() != y)		return;	    removeLastMoveMark();}void Board::updateMarkColor(StoneColor c, int x, int y){    Mark *m = NULL;	    for (m=marks->first(); m != NULL; m=marks->next())    {		if (m->posX() == x && m->posY() == y && m->rtti() != RTTI_MARK_TERR)		{			m->setColor(c == stoneBlack ? white : black);			break;		}    }}void Board::setVarGhost(StoneColor c, int x, int y){    Stone *s = NULL;	    if (setting->readIntEntry("VAR_GHOSTS") == vardisplayGhost)		s = new Stone(imageHandler->getGhostPixmaps(), canvas, c, x, y);    else if (setting->readIntEntry("VAR_GHOSTS") == vardisplaySmallStone)		s = new Stone(imageHandler->getAlternateGhostPixmaps(), canvas, c, x, y, 1);    else		return;	    ghosts->append(s);        if (x == 20 && y == 20)  // Pass    {		s->setX(offsetX + square_size * (board_size+1));		s->setY(offsetY + square_size * board_size);		setMark(board_size+2, board_size+1, markText, false, tr("Pass"), false);    }    else    {		s->setX(offsetX + square_size * (x-1));		s->setY(offsetY + square_size * (y-1));    }}bool Board::hasVarGhost(StoneColor c, int x, int y){    Stone *s;    for (s=ghosts->first(); s != NULL; s=ghosts->next())		if (s->posX() == x && s->posY() == y &&			s->getColor() == c)			return true;		return false;}void Board::setVariationDisplay(VariationDisplay d){    if (d == vardisplayNone)    {		ghosts->clear();		canvas->update();    }}void Board::setShowCursor(bool b){    if (!b && curStone != NULL)		curStone->hide();}void Board::removeGhosts(){    // Remove all variation ghosts    if (!ghosts->isEmpty())		ghosts->clear();}void Board::setShowCoords(bool b){    bool old = showCoords;    showCoords = b;    if (old != showCoords)		changeSize();  // Redraw the board if the value changed.}void Board::setShowSGFCoords(bool b){	bool old = showSGFCoords;	showSGFCoords = b;	if(old != showSGFCoords)		changeSize();  // Redraw the board if the value changed.}void Board::initGame(GameData *d, bool sgf){	CHECK_PTR(d);		int oldsize = board_size;	board_size = d->size;		// Clear up everything	clearData();		// Different board size? Redraw the canvas.	if (board_size != oldsize)	{		delete gatter;		gatter = new Gatter(canvas, board_size);			changeSize();	}	boardHandler->initGame(d, sgf);	updateCaption();}void Board::setModified(bool m){    if (m == isModified || boardHandler->getGameMode() == modeObserve)		return;     isModified = m;    updateCaption();}void Board::updateCaption(){    // Print caption    // example: qGo 0.0.5 - Zotan 8k vs. tgmouse 10k    // or if game name is given: qGo 0.0.5 - Kogo's Joseki Dictionary    topLevelWidget()->setCaption(QString(isModified ? "* " : "") +		(boardHandler->getGameData()->gameNumber != 0 ?		"(" + QString::number(boardHandler->getGameData()->gameNumber) + ") " : QString()) +		(boardHandler->getGameData()->gameName.isEmpty() ?		boardHandler->getGameData()->playerWhite +		(!boardHandler->getGameData()->rankWhite.isEmpty() ?		" " + boardHandler->getGameData()->rankWhite : QString())		+ " " + tr("vs.") + " "+		boardHandler->getGameData()->playerBlack +		(!boardHandler->getGameData()->rankBlack.isEmpty() ?		" " + boardHandler->getGameData()->rankBlack : QString()) :		boardHandler->getGameData()->gameName) +		"   " + QString(PACKAGE " " VERSION));	if (getInterfaceHandler())	{		bool simple = boardHandler->getGameData()->rankWhite.length() == 0 && boardHandler->getGameData()->rankBlack.length() == 0;		QGroupBox *gb = getInterfaceHandler()->normalTools->whiteFrame;		QString player = boardHandler->getGameData()->playerWhite;		if (simple && player == tr("White"))			gb->setTitle(tr("White"));			else		{			// truncate to 12 characters max			player.truncate(12);			if (boardHandler->getGameData()->rankWhite.length() != 0)				player = tr("W") + ": " + player + " " + boardHandler->getGameData()->rankWhite;			else				player = tr("W") + ": " + player;						gb->setTitle(player);		}		gb = getInterfaceHandler()->normalTools->blackFrame;		player = boardHandler->getGameData()->playerBlack;		if (simple && player == tr("Black"))			gb->setTitle(tr("Black"));			else		{			// truncate to 12 characters max			player.truncate(12);			if (boardHandler->getGameData()->rankBlack.length() != 0)				player = tr("B") + ": " + player + " " + boardHandler->getGameData()->rankBlack;			else				player = tr("B") + ": " + player;						gb->setTitle(player);		}	}}void Board::exportPicture(const QString &fileName, const QString &filter, bool toClipboard){    QPixmap pix = QPixmap::grabWidget(this,		offsetX - offset + 2,		offsetY - offset + 2 ,		board_pixel_size + offset*2,		board_pixel_size + offset*2);        if (toClipboard)    {		QApplication::clipboard()->setPixmap(pix);		return;    }        if (!pix.save(fileName, filter))		QMessageBox::warning(this, PACKAGE, tr("Failed to save image!"));}void Board::countScore(){    // Switch to score mode    boardHandler->setMode(modeScore);	#if 0    // Don't clean the board from existing territory marks and dead stones.    boardHandler->getStoneHandler()->removeDeadMarks();    boardHandler->getTree()->getCurrent()->getMatrix()->clearTerritoryMarks();	    boardHandler->countScore();#else    // Instead count the dead stones and add them to the captures. This way we keep    // existing scoring (Cgoban2) and don't need to mark the dead stones again.    int caps_black=0, caps_white=0;    boardHandler->getStoneHandler()->updateDeadMarks(caps_black, caps_white);	    boardHandler->enterScoreMode(caps_black, caps_white);    boardHandler->countScore();#endif	    setModified();}void Board::doCountDone(){     float komi = getGameData()->komi;    int capW = getInterfaceHandler()->scoreTools->capturesWhite->text().toInt(),		capB = getInterfaceHandler()->scoreTools->capturesBlack->text().toInt(),		terrW = getInterfaceHandler()->scoreTools->terrWhite->text().toInt(),		terrB = getInterfaceHandler()->scoreTools->terrBlack->text().toInt();	    float totalWhite = capW + terrW + komi;    int totalBlack = capB + terrB;    float result = 0;    QString rs;	    QString s;    s.sprintf(tr("White") + "\n%d + %d + %.1f = %.1f\n\n" + tr("Black") + "\n%d + %d = %d\n\n",		terrW, capW, komi, totalWhite,		terrB, capB, totalBlack);        if (totalBlack > totalWhite)    {		result = totalBlack - totalWhite;		s.append(tr("Black wins with %1").arg(result));		rs = "B+" + QString::number(result);    }    else if (totalWhite > totalBlack)    {		result = totalWhite - totalBlack;		s.append(tr("White wins with %1").arg(result));		rs = "W+" + QString::number(result);    }    else    {		rs = tr("Jigo");		s.append(rs);    }	    //if (QMessageBox::information(this, PACKAGE " - " + tr("Game Over"), s, tr("Ok"), tr("Update gameinfo")) == 1)		boardHandler->getGameData()->result = rs;      boardHandler->getTree()->getCurrent()->setTerritoryMarked(false);    boardHandler->getTree()->getCurrent()->setScore(totalBlack, totalWhite);    emit signal_done();        }int Board::getCurrentMoveNumber() const{    return boardHandler->getTree()->getCurrent()->getMoveNumber();}InterfaceHandler* Board::getInterfaceHandler(){    return ((MainWindow*)topLevelWidget())->getInterfaceHandler();}// button "Pass" clickedvoid Board::doPass(){	// wait for server message if online	if (isLocalGame)		// pass move is ok		boardHandler->doPass();  // emit in every case	emit signal_pass();}void Board::doResign(){	emit signal_resign();}void Board::set_isLocalGame(bool isLocal){	isLocalGame = isLocal;	getInterfaceHandler()->commentEdit2->setDisabled(isLocalGame);	if (isLocalGame)		((MainWindow*)topLevelWidget())->getListView_observers()->hide();	else		((MainWindow*)topLevelWidget())->getListView_observers()->show();}void Board::navIntersection()          {    /***** several unsuccessful tries with clean method //   unsetCursor(); //   this->topLevelWidget()->unsetCursor(); // this is debug code to check if we can catch the corrrect cursor    if (this->topLevelWidget()->ownCursor())      qDebug("cursor = top");          bool b;    int i= 0;    QWidget *w = this;    do {            if (w->ownCursor())          qDebug("cursor = %d",i);       i++  ;      }    while (w=w->parentWidget(true)) ;    qDebug("stack %d ",i-1);          setCursor(pointingHandCursor);  *** Therefore we apply thick method  :           */        QApplication::setOverrideCursor( QCursor(Qt::pointingHandCursor) );          navIntersectionStatus = true;} /**

⌨️ 快捷键说明

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