void Board::inicio(){ this->setFocus(); QSound botaoSound("Media/Windows Navigation Start.wav"); botaoSound.play(); //Inicia o jogo if((pause == false) && (vida == 0) && (run == false)||(vencedor == true)){ qDebug() << "inicio()"; level = 1; score = 0; cont = 0; ctrlFim = false; pause = false; tamSnake = 1; start(); emit nivelDificuldade(level); emit pontosGanho(score); //Inicia o jogo se estiver e pausa }else if(pause == true){ tempo.start(timeoutTime(), this); pause = false; //Inicia o jogo se o jogador perdeu uma vida }else if(vida > 0 && vida < 3){ start(); //Inicia o jogo apos chegar ao fim }else if(end == 'f' && ctrlFim == true ){ reset(); } }
//消行计分 void game_area_frame::deLine(int y) { int line = y/30; bool flag[4]; int lineCnt = 4; //俄罗斯方块一次最多消去4行,得到四行的状态,即利用flag标志该行是否应该被消除 for(int i = 0; i < 4; i++) { //如果越界 flag[i] = true; if(line+i > 19){ lineCnt--; continue; } for(int j = 0; j < 10; j++) { //有一个位置点为空则将flag置为false并退出判断 if(state[line+i][j] == false){ flag[i] = false; lineCnt--; break; } } } //进行消行处理--有问题(疑似已经解决) for(int i = 0; i < 4; i++) { //越界直接退出循环 if(line+i > 19) break; //标志为真则消行--状态标识下移 if(flag[i] == true) { for(int j = line+i; j >= 0; j--) { if(j==0) { for(int k = 0; k < 10; k++) state[0][k] = 0; timer.start(timeoutTime(), this); } else { for(int k = 0; k < 10; k++) { state[j][k] = state[j-1][k]; } } } } } //返回计分 if(lineCnt > 0) { this->scoreAll += lineCnt*15-5; emit add_score(scoreAll); } }
//incrementa o display Level void Board::incrementaLevel(){ if(score == (level * 5)){ QSound som("Media/Windows Notify.wav"); som.play(); level++; tempo.start(timeoutTime(), this); emit nivelDificuldade(level); } }
void game_area_frame::pause_game() { if(!isStart) return; isPause = !isPause; if(isPause) timer.stop(); else timer.start(timeoutTime(), this); update(); }
//! [5] void TetrixBoard::pause() { if (!isStarted) return; isPaused = !isPaused; if (isPaused) { timer.stop(); } else { timer.start(timeoutTime(), this); } update(); //! [5] //! [6] }
//Auxiliar de início do jogo void Board::start() { if(run == false){ qDebug() << "start()"; vetorSnakeX.clear(); vetorSnakeY.clear(); run = true; pos_x = 64; pos_y = 64; direcao = 4; vencedor = false; posicaoMaca(); tempo.start(timeoutTime(), this); } }
void game_area_frame::timerEvent(QTimerEvent *event) { if (event->timerId() == timer.timerId()) { if (isWaiting == true) { isWaiting = false; this->set_NowTe(); //表示将落下一个新的方块 timer.start(timeoutTime(), this); } else { this->down(); } } else { QFrame::timerEvent(event); } }
//! [15] void TetrixBoard::timerEvent(QTimerEvent *event) { if (event->timerId() == timer.timerId()) { if (isWaitingAfterLine) { isWaitingAfterLine = false; newPiece(); timer.start(timeoutTime(), this); } else { oneLineDown(); } } else { QFrame::timerEvent(event); //! [15] //! [16] } //! [16] //! [17] }
//游戏开始、暂停、结束信号函数 void game_area_frame::start_game() { if(this->isStart == true) { for(int i = 0; i < 20; i++) for(int j = 0; j < 10; j++) state[i][j] = 0; } this->isStart = true; this->next_area->setStart(); this->isWaiting = false; this->set_NowTe(); this->scoreAll = 0; emit add_score(scoreAll); timer.start(timeoutTime(), this); this->update(); this->next_area->update(); }
void game_area_frame::change_level(int level) { //测试 QString levelName = levelBox->itemText(level); if(levelName == "Easy"){ this->level = 800; } else if(levelName == "Normal"){ this->level = 500; } else if(levelName == "Hard"){ this->level = 200; } timer.stop(); if(this->isStart == true) timer.start(timeoutTime(), this); this->setFocus(); }
//! [4] void TetrixBoard::start() { if (isPaused) return; isStarted = true; isWaitingAfterLine = false; numLinesRemoved = 0; numPiecesDropped = 0; score = 0; level = 1; clearBoard(); emit linesRemovedChanged(numLinesRemoved); emit scoreChanged(score); emit levelChanged(level); newPiece(); timer.start(timeoutTime(), this); }
//! [22] void TetrixBoard::pieceDropped(int dropHeight) { for (int i = 0; i < 4; ++i) { int x = curX + curPiece.x(i); int y = curY - curPiece.y(i); shapeAt(x, y) = curPiece.shape(); } ++numPiecesDropped; if (numPiecesDropped % 25 == 0) { ++level; timer.start(timeoutTime(), this); emit levelChanged(level); } score += dropHeight + 7; emit scoreChanged(score); removeFullLines(); if (!isWaitingAfterLine) newPiece(); //! [22] //! [23] }