コード例 #1
0
ファイル: board.cpp プロジェクト: estan/tetris
void Board::removeLines()
{
	int score = 14 * m_level;

	// Loop through full lines
	for (int i = 0; i < 4; ++i) {
		int row = m_full_lines[i];
		if (row == -1)
			break;

		// Remove line
		for (int col = 0; col < 10; ++col) {
			removeCell(col, row);
		}
		++m_removed_lines;
		++m_topCellY;
		score *= 3;

		// Shift board down
		for (; row > 0; --row) {
			for (int col = 0; col < 10; ++col) {
				m_cells[col][row] = m_cells[col][row - 1];
			}
		}
	}

	// Remove top line
	if (m_full_lines[0] != -1) {
		for (int col = 0; col < 10; ++col) {
			removeCell(col, 0);
		}
	}

	m_level = (m_removed_lines / 10) + 1;
	//m_shift_timer->setInterval(10000 / (m_removed_lines + 20));
	m_score += score;
	emit levelUpdated(m_level);
	emit linesRemovedUpdated(m_removed_lines);
	emit scoreUpdated(m_score);

	// Empty list of full lines
	for (int i = 0; i < 4; ++i)
		m_full_lines[i] = -1;

	// Add new piece
	createPiece();
}
コード例 #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Create an instance of a ScoreKeeper that will keep track of correct/incorrect answers and provide statistics on them
    score_keeper = new ScoreKeeper(this);

    // Upon retrieving the two sound file URLs, send a request to Playback to open them and assign them to the Players
    connect(this, SIGNAL(loadSoundsRequest(QUrl,QUrl)), ui->playbackWidget, SLOT(loadSounds(QUrl,QUrl)));
    // When a guess is made by the user, send whether it was correct or incorrect to ScoreKeeper
    connect(this, SIGNAL(guessMade(ScoreKeeper::Guesses)), score_keeper, SLOT(guessMade(ScoreKeeper::Guesses)));
    // When the user makes a guess, Playback starts a new trial
    connect(this, SIGNAL(startNewTrialRequest()), ui->playbackWidget, SLOT(startNewTrial()));
    // When ScoreKeeper has updated its scores, it notifies this window to update their display
    connect(score_keeper, SIGNAL(scoreUpdated(ScoreKeeper::Score,ScoreKeeper::Score)), this, SLOT(updateLabels(ScoreKeeper::Score,ScoreKeeper::Score)));
}
コード例 #3
0
ファイル: board.cpp プロジェクト: estan/tetris
void Board::newGame()
{
	if (!endGame()) {
		return;
	}

	m_flash_timer->stop();
	m_shift_timer->stop();
	delete m_piece;
	m_piece = 0;

	emit hideMessage();
	m_started = true;
	m_done = false;
	m_paused = false;
	m_removed_lines = 0;
	m_level = 1;
	m_score = 0;
	m_shift_timer->setInterval(m_shiftTime);
	m_next_piece = (rand() % 7) + 1;
	m_topCellY = 19;
	m_difficultyLevel = FirstLevel;
	m_shiftTime = m_firstLevelShiftTime;

	for (int i = 0; i < 4; ++i)
		m_full_lines[i] = -1;

	for (int col = 0; col < 10; ++col) {
		for (int row = 0; row < 20; ++row) {
			m_cells[col][row] = 0;
		}
	}

	emit pauseAvailable(true);
	emit levelUpdated(m_level);
	emit linesRemovedUpdated(m_removed_lines);
	emit scoreUpdated(m_score);
	emit gameStarted();

	setCursor(Qt::BlankCursor);
	createPiece();
}