/** * @brief 생성자 * @param parent 부모 위젯 */ Puzzle::Puzzle(QWidget *parent) : QMainWindow(parent) , _emptyPiece(0) , _shuffle(false) , _tryCount(0) { initMenus(); // 메뉴 초기화 initWidgets(); // 위젯 초기화 initConnections(); // 시그널과 슬롯 연결 newPuzzle(); // 새 퍼즐 }
/** * @brief 메뉴를 초기화한다 */ void Puzzle::initMenus() { // "파일" 메뉴 새성 QMenu *fileMenu = new QMenu(tr("파일(&F)")); // "새 퍼즐" 항목 추가 fileMenu->addAction(tr("새 퍼즐(&N)"), this, SLOT(newPuzzle()), QKeySequence(QKeySequence::New)); // 구분줄 추가 fileMenu->addSeparator(); // "끝내기" 항목 추가 fileMenu->addAction(tr("끝내기(&x)"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q"))); // 메뉴바에 "파일" 메뉴 추가 menuBar()->addMenu(fileMenu); }
GameLogic::GameLogic(Rage *rage, Input *input) : rage(rage), input(input), win(false), resultTimer(0), wins(0), fails(0) { field = new Field(rage); field->randomize(); largeMarker = 0; penDown = false; solutionProvided = false; ticks = 0; newPuzzle(); }
void MainWindow::createActions() { newPuzzleAction = new QAction(QStringLiteral("出题"), this); newPuzzleAction->setIcon(QIcon(":/images/newPuzzle.png")); connect(newPuzzleAction, SIGNAL(triggered()), sudokuTable, SLOT(newPuzzle())); previousAction = new QAction(QStringLiteral("上一个答案"), this); previousAction->setIcon(QIcon(":/images/previous.png")); connect(previousAction, SIGNAL(triggered()), sudokuTable, SLOT(previous())); nextAciton = new QAction(QStringLiteral("下一个答案"), this); nextAciton->setIcon(QIcon(":/images/next.png")); connect(nextAciton, SIGNAL(triggered()), sudokuTable, SLOT(next())); eraseAction = new QAction(QStringLiteral("清除答案"), this); eraseAction->setIcon(QIcon(":/images/erase.png")); connect(eraseAction, SIGNAL(triggered()), sudokuTable, SLOT(erase())); clearAction = new QAction(QStringLiteral("清空"), this); clearAction->setIcon(QIcon(":/images/clear.png")); connect(clearAction, SIGNAL(triggered()), sudokuTable, SLOT(clear())); eyeModeAction = new QAction(QStringLiteral("天眼模式"), this); eyeModeAction->setIcon(QIcon(":/images/eyeOn.png")); connect(eyeModeAction, SIGNAL(triggered()), this, SLOT(setEyeMode())); settingsAction = new QAction(QStringLiteral("设置"), this); settingsAction->setIcon(QIcon(":/images/settings.png")); connect(settingsAction, SIGNAL(triggered()), this, SLOT(settings())); helpAction = new QAction(QStringLiteral("帮助"), this); helpAction->setIcon(QIcon(":/images/help.png")); connect(helpAction, SIGNAL(triggered()), this, SLOT(help())); aboutAction = new QAction(QStringLiteral("关于"), this); aboutAction->setIcon(QIcon(":/images/about.png")); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); xiakeAction = new QAction(QStringLiteral("侠客风云传"), this); xiakeAction->setIcon(QIcon(":/images/xiake.png")); connect(xiakeAction, SIGNAL(triggered()), this, SLOT(xiake())); }
void GameLogic::update() { if(largeMarker == 0) { largeMarker = rage->createSpriteInstance(Rage::MAIN, LARGE_MARKER); rage->showSprite(Rage::MAIN, largeMarker, false); } ticks++; if(resultTimer > 0) { if(--resultTimer == 0) { rage->showSprite(Rage::MAIN, largeMarker, false); newPuzzle(); } return; } if(input->keyPressed(KEY_TOUCH)) { int x, y; if(getPenTouch(&x, &y)) { startX = endX = x; startY = endY = y; rage->selectAnimation(Rage::MAIN, largeMarker, MARKER_1); rage->showSprite(Rage::MAIN, largeMarker, true); rage->moveSpriteAbs(Rage::MAIN, largeMarker, offsetX + x*24 + 4, offsetY + y*24 + 4); penDown = true; } } else if(input->keyReleased(KEY_TOUCH)) { penDown = false; if(solutionProvided) { // check solution win = field->checkSolution(puzzle, startX, startY, (startX + endX)/2, (startY + endY) / 2, endX, endY); if(win) { wins++; } else { printf("Fail!\n"); fails++; } printf("Wins: %d, Fails: %d, Rank: %d\n", wins, fails, wins?ticks/wins/60:0); resultTimer = 60; solutionProvided = false; } else { rage->showSprite(Rage::MAIN, largeMarker, false); } } if(penDown) { // User moving pen around int x, y; if(getPenTouch(&x, &y)) { if(x != endX || y != endY) { endX = x; endY = y; // Is this a correct line? int xdel[17] = {0, 1, 2, 1, 2, 0, 0, -1, -2, -1, -2, -1, -2, 0, 0, 1, 2}; int ydel[17] = {0, 0, 0, -1, -2, -1, -2, -1, -2, 0, 0, 1, 2, 1, 2, 1, 2}; int anim[17] = {MARKER_1, MARKER_2_HORIZONTAL, MARKER_3_HORIZONTAL, MARKER_2_DOWNLEFT, MARKER_3_DOWNLEFT, MARKER_2_VERTICAL, MARKER_3_VERTICAL, MARKER_2_DOWNRIGHT, MARKER_3_DOWNRIGHT, MARKER_2_HORIZONTAL, MARKER_3_HORIZONTAL, MARKER_2_DOWNLEFT, MARKER_3_DOWNLEFT, MARKER_2_VERTICAL, MARKER_3_VERTICAL, MARKER_2_DOWNRIGHT, MARKER_3_DOWNRIGHT}; for(int i = 0;i < 17;i++) { if(startX == endX + xdel[i] && startY == endY + ydel[i]) { rage->selectAnimation(Rage::MAIN, largeMarker, anim[i]); rage->moveSpriteAbs(Rage::MAIN, largeMarker, (startX < endX ? startX : endX) * 24 + offsetX + 4, (startY < endY ? startY : endY) * 24 + offsetY + 4); if(i > 0 && i%2 == 0) solutionProvided = true; else solutionProvided = false; } } } } } if(input->keyPressed(KEY_A)) { field->randomize(); newPuzzle(); } }