void IScene::restoreCursor() { lastCursor = QApplication::overrideCursor() ? (* QApplication::overrideCursor()) : QCursor(); while (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); setDefaultGameCursor(); }
GameScene::GameScene(QWidget *parent) : QGraphicsScene(parent), myLock(false) { inputDisabled = true; dconfirm = new ConfirmDialog(); addWidget(dconfirm, Qt::FramelessWindowHint); dconfirm->hide(); menu = new MenuWidget(); addWidget(menu); menu->activate(); connect(menu, SIGNAL(menuNew()), this, SLOT(on_menuNew())); connect(menu, SIGNAL(menuContinue()), this, SLOT(on_menuContinue())); connect(menu, SIGNAL(menuExit()), this, SLOT(on_menuExit())); connect(menu, SIGNAL(menuPauseBack()), this, SLOT(on_menuPauseBack())); connect(menu, SIGNAL(menuRestartLevel()), this, SLOT(on_menuRestartLevel())); connect(menu, SIGNAL(menuAbandonGame()), this, SLOT(on_menuAbandonGame())); connect(menu, SIGNAL(menuThemeChanged()), this, SLOT(on_menuThemeChanged())); connect(menu, SIGNAL(menuGameStart()), this, SLOT(on_menuGameStart())); connect(menu, SIGNAL(menuLevelPack()), this, SLOT(on_menuLevelPack())); stat = new StatInfo(); connect(gameProfile, SIGNAL(profileChanged()), this, SLOT(initProfile())); rows = cols = 0; xoff = 20; yoff = 10; advanceTimer = new QTimer(this); advanceTimer->setInterval(30); connect(advanceTimer, SIGNAL(timeout()), this, SLOT(nextCycle())); timeTimer = new QTimer(this); timeTimer->setInterval(1000); connect(timeTimer, SIGNAL(timeout()), this, SLOT(countTime())); bonusTimer = new QTimer(this); bonusTimer->setInterval(500); connect(bonusTimer, SIGNAL(timeout()), this, SLOT(countBonusTime())); hintTimer = new QTimer(this); hintTimer->setInterval(10000); connect(hintTimer, SIGNAL(timeout()), this, SLOT(hintAvailableMoves())); // init components GameStock::init(); toolset = new ToolSet(); gameBonus = new GameBonus(); setSceneRect(0,0, WIDTH, HEIGHT); // set background gameBackground = new GameBackground(); setBackgroundBrush(Qt::black); setDefaultGameCursor(); // update max level for current pack max_level = gameProfile->levelPackCount(gameProfile->currentLevelPack()); // very first initialization initGame(); }
bool GameScene::initLevel(int level) { qsrand(QTime::currentTime().msec()); // if level pack not found if (max_level == 0) return false; // init field const int max = MAX_COLS*MAX_ROWS; for (int i = 0; i < max; i++) { PlaceInfo &pi = field[i]; if (pi.item) delete pi.item; field[i] = PlaceInfo(); } qDeleteAll(tempItems); tempItems.clear(); rows = cols = 0; currentItem = 0; currentCol = currentRow = -1; targetCol = targetRow = -1; lastClickPos = QPoint(); moveState = MS_IDLE; availFrom = QPoint(); availTo = QPoint(); hintMove = false; hintText = ""; inputDisabled = true; paintState = false; stat_active = false; // set level this->level = level; bonus = 1; bonus_time = 0; time = 10*60; targets = 0; frameCount = 1; // check if all levels were finished if (level > max_level) { showStatictics(STAT_GAME_WON); return true; } // load level from pack if (!loadLevel(level)) return false; // set local info from profile // PlayerInfo *pl = gameProfile->currentPlayer(); LevelPackInfo *lpi = gameProfile->currentPlayer()->currentLevelPackInfo(); score = lpi->score; // more time for hard difficulty if (lpi->diff == DIFF_HARD) time = int(time*1.5); toolset->readProfile(lpi); gameBonus->readProfile(lpi, this); gameBackground->readProfile(gameProfile->currentPlayer()); // add bonus to the timer time += toolset->bonusClock(); stat->level_time = time; gameProfile->setGameStarted(true); gameProfile->setGamePaused(false); // set background loadRandomBackground(); // pre-draw lower layer drawHUDonBackground(); // set cursor setDefaultGameCursor(); // start level createStaticPopup(QRect(0,0,DX(910),DY(700)), tr("Level %1").arg(level), Qt::AlignCenter, gameStock->Font60, Qt::white, 1, 0, 50, 0, -2); sndEngine->playSound(GameSound::sndLevelStart); advanceTimer->start(); // init animation ls_x = ls_y = 0; level_start = true; return true; }