void MainWindow::mode_switch() { ui->graphicsView->fitInView(QRectF(0, 0, BOARD_WIDTH * BOARD_TILE_SIZE, BOARD_HEIGHT * BOARD_TILE_SIZE), Qt::KeepAspectRatio); ui->nextView->fitInView(QRectF(0, 0, 4*BOARD_TILE_SIZE, 4*BOARD_TILE_SIZE), Qt::KeepAspectRatio); switch (state) { case STATE_INIT: game->Reset(); game->Start(); drawNext(game->next); state = STATE_RUNNING; score = 0; refreshScore(); ui->pushButton->setText("Pause"); ui->actionStart_Game->setText("Pause"); goto start_timer; case STATE_RUNNING: game->Pause(); timer->stop(); ui->pushButton->setText("Resume"); ui->actionStart_Game->setText("Resume"); state = STATE_PAUSE; return; case STATE_PAUSE: game->Resume(); ui->pushButton->setText("Pause"); ui->actionStart_Game->setText("Pause"); state = STATE_RUNNING; goto start_timer; } start_timer: restartTimer (); redraw(); }
void StarMatrix::deleteSelectedList() { if(selectedList.size() <= 1) { m_layer->hideLinkNum(); selectedList.at(0)->setSelected(false); return; } for(auto it = selectedList.begin();it != selectedList.end();it++) { Star* star = *it; showStarParticleEffect(star->getColor(),star->getPosition(),this); stars[star->getIndexI()][star->getIndexJ()] = nullptr; star->removeFromParentAndCleanup(true); Audio::getInstance()->playPop(); } showComboEffect(selectedList.size(),this); Audio::getInstance()->playCombo(selectedList.size()); refreshScore(); m_layer->showLinkNum(selectedList.size()); adjustMatrix(); if(isEnded()) { m_layer->floatLeftStarMsg(getLeftStarNum()); CCLOG("ENDED"); } }
void MainWindow::keyReleaseEvent(QKeyEvent *event) { int erases = 0; if (event->key() == Qt::Key_P) { mode_switch(); return; } switch (state) { case STATE_RUNNING: switch (event->key()) { case Qt::Key_Space: game->DropToBottom(); finishJudge(); drawNext(game->next); erases = game->EraseRows(); for(int i = 0; i<erases; i++) { score += (i+1) * 100; } refreshScore(); goto redraw; case Qt::Key_Left: game->MoveLeft(); goto redraw; case Qt::Key_Right: game->MoveRight(); goto redraw; case Qt::Key_Up: game->Rotate(); goto redraw; case Qt::Key_Down: timer_timeout (); goto redraw; case Qt::Key_C: if (interval % 10 == 3) game->next = block(util::point(0, 0), block_shape::GetRandomBlockShape()); drawNext(game->next); goto redraw; default: QMainWindow::keyReleaseEvent(event); return; } redraw: redraw (); return; case STATE_INIT: if (event->key() == Qt::Key_Space) mode_switch(); else { QMainWindow::keyReleaseEvent(event); return; } return; case STATE_PAUSE: return; } }
void MainWindow::timer_timeout() { if (state != STATE_RUNNING) return; if (game->Drop()) { finishJudge(); drawNext(game->next); int erases = game->EraseRows(); for(int i = 0; i<erases; i++) { score += (i+1) * 100; } refreshScore(); } qDebug() << game->now.start_point.x << " " << game->now.start_point.y; redraw(); }
MainWindow::MainWindow() { quitdlg=0; editdlg=0; helpdlg=0; windlg=0; losedlg=0; //QSound::play("C:/Users/Altair/Documents/Qt/Inversion/sound.wav"); QGridLayout* layout1 = new QGridLayout(); QHBoxLayout* layout4 = new QHBoxLayout(); QVBoxLayout *layout3 = new QVBoxLayout; for (int i=0; i < 5; i++) { for (int j=0; j < 5; j++) { b[i][j] = new QPushButton(this); grid[i][j]=1; b[i][j]->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/on.png) 1 1 1 1 ;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); b[i][j]->setMinimumSize(100, 100); layout1->addWidget(b[i][j], i, j); } } combo= new QComboBox(); QLabel *label = new QLabel("Choose the puzzle :"); label->setFixedSize(40,40); combo->addItem("--"); for (int i=1;i<=10;i++){ combo->addItem("Puzzle "+QString::number(i)); } connect(combo,SIGNAL(currentIndexChanged(int)),this,SLOT(opencombo(int))); combo->setFixedSize(40,40); combo->setStyleSheet("QWidget { background-color: gray;border-style: outset;}"); layout3->addWidget(label); layout3->addWidget(combo); layout4->addLayout(layout3); layout4->addLayout(layout1); QVBoxLayout *layout6= new QVBoxLayout(); gameTurns=0;gameTimes=0; gameScore=0;gamemin=0;gamesec=0; lblTurn = new QLabel(this); lblTurn->setFixedSize(30, 30); layout6->addWidget(lblTurn); lblTimes = new QLabel(this); lblTimes->setFixedSize(30, 30); layout6->addWidget(lblTimes); lblScore = new QLabel(this); lblScore->setFixedSize(30, 30); layout6->addWidget(lblScore); QSound* sound=new QSound("C:/Users/Altair/Documents/Qt/Inversion/sound.wav"); sound->setLoops(-1); soundplay = new QPushButton(this); soundplay->setMaximumSize(100, 100); soundplay->setStyleSheet("QPushButton{border-image: url(C:/Users/Altair/Documents/Qt/Inversion/sound.png)3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); QObject::connect(soundplay,SIGNAL(clicked()),sound,SLOT(play())); layout6->addWidget(soundplay); soundstop = new QPushButton(this); soundstop->setMaximumSize(100, 100); soundstop->setStyleSheet("QPushButton{border-image: url(C:/Users/Altair/Documents/Qt/Inversion/mute.png)3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); QObject::connect(soundstop,SIGNAL(clicked()),sound,SLOT(stop())); layout6->addWidget(soundstop); layout4->addLayout(layout6); this->setWindowFlags(Qt::FramelessWindowHint); this->setStyleSheet("QWidget {background: url('C:/Users/Altair/Documents/Qt/Inversion/back.png')no-repeat ; border-style: outset; border-width: 2px;border-radius: 10px;border-color: beige;font: bold 14px;min-width: 10em;padding: 6px; }"); QVBoxLayout *layoutPrincipal=new QVBoxLayout(this); QHBoxLayout *layout2=new QHBoxLayout(); quitdlg= new quitdial(this); helpdlg= new helpdial(this); editdlg= new editdial(this); windlg= new windial(this); losedlg= new losedial(this); player= new QPushButton("Play"); player->setCheckable(true); player->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); connect(player, SIGNAL(clicked()), this, SLOT(openplay())); connect(player, SIGNAL(clicked()), this, SLOT(clik2())); player->setMinimumSize(50,50); layout2->addWidget(player); solve = new QPushButton("Solve"); solve->setCheckable(true); solve->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); solve->setMinimumSize(50,50); solve->setEnabled(false); connect(solve, SIGNAL(clicked()), this, SLOT(opensolve())); layout2->addWidget(solve); mix= new QPushButton("Mix"); mix->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); mix->setMinimumSize(50,50); connect(mix, SIGNAL(clicked()), this, SLOT(openmix())); layout2->addWidget(mix); resett = new QPushButton("Reset"); resett->setMinimumSize(50,50); resett->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); connect(resett, SIGNAL(clicked()), this, SLOT(openreset())); layout2->addWidget(resett); edit = new QPushButton("Edit"); edit->setMinimumSize(50,50); edit->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); edit->setCheckable(true); connect(edit, SIGNAL(clicked()), this, SLOT(openedit())); connect(edit, SIGNAL(clicked()), this, SLOT(clik1())); layout2->addWidget(edit); hel = new QPushButton("Help"); hel->setMinimumSize(50,50); hel->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); connect(hel, SIGNAL(clicked()), this, SLOT(openhelp())); layout2->addWidget(hel); boutonQuitter = new QPushButton("Quit"); boutonQuitter->setMinimumSize(50,50); boutonQuitter->setStyleSheet(" QPushButton { border-image: url(C:/Users/Altair/Documents/Qt/Inversion/bouton.png) 3 10 3 10;color: grey;border-top: 3px transparent; border-bottom: 3px transparent;border-right: 10px transparent;border-left: 10px transparent;}"); QWidget::connect(boutonQuitter, SIGNAL(clicked()), this, SLOT(openquit())); layout2->addWidget(boutonQuitter); layoutPrincipal->addLayout(layout2); layoutPrincipal->addLayout(layout4); this->resize(1370,600); setLayout(layoutPrincipal); gameTimer = new QTimer(); gameTimer->setInterval(1000); gameTimer->start(); connect(gameTimer,SIGNAL(timeout()),this,SLOT(gameTimer_timeout())); refreshScore(); }
void MainWindow::gameTimer_timeout(){ if (isGameRun==1) gameTimes++; refreshScore(); }
void MainWindow::gameUpdate() { //update jugador updateShip(this->player); //update bullets for(int i = 0; i < playerBullets->size(); i++) { bool remove = UpdatePlayerBeam(playerBullets->at(i)); if(remove) { delete playerBullets->at(i)->myLabel; playerBullets->removeAt(i); i--; } } for(int i= 0; i < enemies->size(); i++) { enemyUpdate(enemies->at(i)); } QRect Rectplayer = player->myLabel->geometry(); //Checkeo Colisiones for(int i = 0; i < playerBullets->size(); i++) { PlayerBeam* bullet = playerBullets->at(i); QRect Rectbullet = bullet->myLabel->geometry(); if(Rectbullet.intersects(Rectplayer)) { player->lives--; delete bullet->myLabel; playerBullets->removeAt(i); i--; } for(int j = 0; j < enemies->size(); j++) { enemy_T* actEnemy = enemies->at(j); QRect RectActEnemy = actEnemy->image->geometry(); if(Rectbullet.intersects(RectActEnemy)) { hit(actEnemy); delete bullet->myLabel; playerBullets->removeAt(i); i--; break; } } } //Colisiones con el jugador for(int i = 0; i < enemies->size(); i++) { QRect RectActEnemy = enemies->at(i)->image->geometry(); if(Rectplayer.intersects(RectActEnemy)) { playerHitted = true; player->lives--; qDebug() << player->lives; hit(enemies->at(i)); } } //check gmae over if(player->lives <= 0) { emit gameEnd(); } //Checkeo Muerte de Enemigos for(int i = 0; i < enemies->size(); i++) { if(enemies->at(i)->dead) { delete enemies->at(i)->image; player->score += checkEnemyValue(enemies->at(i)->type); enemies->removeAt(i); i--; this->enemyKilled = true; } } if(enemies->size() == 0) { this->level++; generateNextLevel(); } refreshScore(); refreshLives(); }
void playGame(void) { bool gameLoaded = false; uint8_t ch; gScoreBar = 0; gShouldSave = false; printf("\n\nChecking for a saved game..."); if (loadGame()) { bool gotAnswer = false; printf("\n\nYou have a saved game!\n Would you like to continue it (Y/N)"); while (!gotAnswer) { ch = cgetc(); switch (ch) { case 'y': case 'Y': printf("\n\nLoading your saved puzzle"); gotAnswer = true; gShouldSave = true; gameLoaded = true; break; case 'n': case 'N': gotAnswer = true; break; default: badThingHappened(); break; } } } showAndClearDblLoRes(); if (!gameLoaded) { startNewGame(); } drawBoard(); speakGo(); while (true) { resetStarAnim(); while (true) { doStarAnim(); if (pollKeyboard()) { break; } if ((gGameOptions.enableJoystick) && (pollJoystick())) { break; } if ((gGameOptions.enableMouse) && (pollMouse())) { break; } } if (gameIsOver()) { endGame(); showAndClearDblLoRes(); refreshScore(0); startNewGame(); gShouldSave = false; } } }
static bool pollKeyboard(void) { bool result = false; uint8_t ch; if (!kbhit()) return result; ch = cgetc(); switch (ch) { case 'i': case 'I': case CH_CURS_UP: if (!isAppleButtonPressed()) { moveDir(DIR_UP); break; } // Fallthrough... case 139: result = swapDir(DIR_UP); break; case 'j': case 'J': case CH_CURS_LEFT: if (!isAppleButtonPressed()) { moveDir(DIR_LEFT); break; } // Fallthrough... case 136: result = swapDir(DIR_LEFT); break; case 'k': case 'K': case CH_CURS_RIGHT: if (!isAppleButtonPressed()) { moveDir(DIR_RIGHT); break; } // Fallthrough... case 149: result = swapDir(DIR_RIGHT); break; case 'm': case 'M': case CH_CURS_DOWN: if (!isAppleButtonPressed()) { moveDir(DIR_DOWN); break; } // Fallthrough... case 138: result = swapDir(DIR_DOWN); break; case CH_ESC: case 'q': case 'Q': if (gShouldSave) { videomode(VIDEOMODE_80x24); mixedTextMode(); gotoxy(0, 0); cprintf("Saving your game so you can continue\r\n later..."); saveGame(); } quitGame(); break; case 'r': case 'R': refreshScore(0); startNewGame(); gShouldSave = false; return true; case 'o': case 'O': selectOptions(); showAndClearDblLoRes(); drawBoard(); break; case 'h': case 'H': getHint(); break; case '?': printInstructions(); showAndClearDblLoRes(); drawBoard(); break; default: badThingHappened(); break; } return result; }