void Game::keyPressEvent(QKeyEvent *event){ int key = event->key(); if (key == Qt::Key_Space){ rotate(); } else if (key == Qt::Key_A || key == Qt::Key_B || key == Qt::Key_C || key == Qt::Key_D || key == Qt::Key_E || key == Qt::Key_I || key == Qt::Key_J || key == Qt::Key_K || key == Qt::Key_L || key == Qt::Key_M || key == Qt::Key_O || key == Qt::Key_P || key == Qt::Key_Q || key == Qt::Key_R || key == Qt::Key_S || key == Qt::Key_U || key == Qt::Key_V || key == Qt::Key_W || key == Qt::Key_X || key == Qt::Key_Y) { insertStone(event->text().toUpper().toStdString().c_str()); } else if (key == Qt::Key_Left){ movePlayer("l"); } else if (key == Qt::Key_Right){ movePlayer("p"); } else if (key == Qt::Key_Up){ movePlayer("n"); } else if (key == Qt::Key_Down){ movePlayer("d"); } else if (hrac_posunul == true && (key == Qt::Key_Enter || key == Qt::Key_Return)) { hracNaTahu++; if(hracNaTahu == pocetHracu) { hracNaTahu = 0; } hrac_posunul = false; posunuto = false; updateGame(); } else if (key == Qt::Key_Control) { predmet = new Predmet(); predmet->vykresliPredmet(hrac[hracNaTahu].hledany_predmet()); predmet->setPos(125+(velikost*52),170); scene->addItem(predmet); } else if (key == Qt::Key_Escape) { if(running && !menu) showInGameMenu(); else if(menu) updateGame(); } }
void Tree::addMove(StoneColor c, int x, int y) { Move * lastValidMoveChecked = new Move(c, x, y, current->getMoveNumber() + 1, phaseOngoing, *(current->getMatrix()), true); //clearMarks = true koStoneX = 0; koStoneY = 0; /* special case: pass */ if(x == 20 && y == 20) { if (hasSon(lastValidMoveChecked)) delete lastValidMoveChecked; else addSon(lastValidMoveChecked); return; } if (insertStoneFlag) { insertStone(lastValidMoveChecked); return; } if (c == stoneErase) { /* FIXME I don't think this is right. First of all, it needs to be fixed in deleteNode() as well which is called as an undo * as well as as a tree edit. But here, I don't think we want a new move added as a son to erase a move, I think we just * want to erase it... or maybe not because it makes sense to add it as a tree when its an undo in a game. * another point is that its not like a move in order, its like a separate tree, so addMove(stoneErase seems singularly * useless since we have to do something special with the tree anyway, i.e., no addSon, but maybe we go backwards and * delete some marker */ lastValidMoveChecked->getMatrix()->insertStone(x, y, stoneErase); } if (hasSon(lastValidMoveChecked)) { /* This happens a lot if we add a move that's already there * when really we're just playing along with the tree. * This would be the place to add any kind of tesuji testing * code */ delete lastValidMoveChecked; return; } int lastCaptures = lastValidMoveChecked->getMatrix()->makeMove(x, y, c); addSon(lastValidMoveChecked); if (lastCaptures == 1) checkAddKoMark(current->getColor(), current->getX(), current->getY(), current); int capturesBlack, capturesWhite; if (current->parent != NULL) { capturesBlack = current->parent->getCapturesBlack(); capturesWhite = current->parent->getCapturesWhite(); } else capturesBlack = capturesWhite = 0; if (c == stoneBlack) capturesBlack += lastCaptures; else if (c == stoneWhite) capturesWhite += lastCaptures; current->setCaptures(capturesBlack, capturesWhite); }