From kde-commits Thu Mar 31 21:31:03 2011 From: Frederik Schwarzer Date: Thu, 31 Mar 2011 21:31:03 +0000 To: kde-commits Subject: KDE/kdegames/kbreakout/src (silent) Message-Id: <20110331213103.7461EAC8CD () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=130160710802161 SVN commit 1226667 by schwarzer: SVN_SILENT: Some coding style unification. M +13 -5 brick.cpp M +6 -2 canvasitems.cpp M +5 -2 canvaswidget.cpp M +2 -1 fontutils.cpp M +63 -32 gameengine.cpp --- trunk/KDE/kdegames/kbreakout/src/brick.cpp #1226666:1226667 @@ -32,14 +32,16 @@ { m_gift = 0; - if(typeString != "UnbreakableBrick" && typeString != "HiddenBrick") + if (typeString != "UnbreakableBrick" && typeString != "HiddenBrick") { ++m_game->m_remainingBricks; + } moveTo((x-1)*BRICK_WIDTH, (y-1)*BRICK_HEIGHT); repaint(); - if(typeString == "HiddenBrick") + if (typeString == "HiddenBrick") { hide(); } +} Brick::~Brick() { @@ -90,7 +92,9 @@ void Brick::explode() { - if (m_deleted) return; + if (m_deleted) { + return; + } burn(); QTimer::singleShot(BURNING_SPEED, this, SLOT(burnNearbyBricks())); @@ -106,7 +110,9 @@ void Brick::burn() { - if (m_deleted) return; + if (m_deleted) { + return; + } if (type() == "ExplodingBrick") { // makes sure it doesn't explode twice @@ -173,7 +179,9 @@ nearbyPoints.append(QPoint(x, y + BRICK_HEIGHT)); foreach (Brick *b, m_game->m_bricks) { - if (b->isDeleted()) continue; + if (b->isDeleted()) { + continue; + } foreach (const QPoint& p, nearbyPoints) { if (b->getRect().contains(p)) { result.append(b); --- trunk/KDE/kdegames/kbreakout/src/canvasitems.cpp #1226666:1226667 @@ -42,7 +42,9 @@ { int oldWidth = width; width = qRound(width*RESIZE_BAR_RATIO); - if (width > MAX_BAR_WIDTH) width = MAX_BAR_WIDTH; + if (width > MAX_BAR_WIDTH) { + width = MAX_BAR_WIDTH; + } loadSprite(); // move the bar to retain it's center @@ -55,7 +57,9 @@ { int oldWidth = width; width = qRound(width/RESIZE_BAR_RATIO); - if (width < MIN_BAR_WIDTH) width = MIN_BAR_WIDTH; + if (width < MIN_BAR_WIDTH) { + width = MIN_BAR_WIDTH; + } loadSprite(); // move the bar to retain it's center --- trunk/KDE/kdegames/kbreakout/src/canvaswidget.cpp #1226666:1226667 @@ -130,7 +130,9 @@ void CanvasWidget::updateBar() { QPoint p = mapFromGlobal(cursor().pos()); - if (lastMousePosition == p) return; + if (lastMousePosition == p) { + return; + } lastMousePosition = p; // don't move the mouse if the user was using the keys to play @@ -176,9 +178,10 @@ KGameCanvasWidget::keyPressEvent(event); } - if ((rightPressed || leftPressed) && !moveBarTimer.isActive()) + if ((rightPressed || leftPressed) && !moveBarTimer.isActive()) { moveBarTimer.start(); } +} void CanvasWidget::keyReleaseEvent(QKeyEvent *event) { --- trunk/KDE/kdegames/kbreakout/src/fontutils.cpp #1226666:1226667 @@ -42,8 +42,9 @@ return -1; } else if (rect.width() > w || rect.height() > h) { size = qMin(w * size / rect.width(), h * size / rect.height()); + } else { + done = true; } - else done = true; } return size; --- trunk/KDE/kdegames/kbreakout/src/gameengine.cpp #1226666:1226667 @@ -96,9 +96,12 @@ void GameEngine::pause() { - if (gameIsPaused()) return; - if (m_gameWon || m_gameOver) return; - + if (gameIsPaused()) { + return; + } + if (m_gameWon || m_gameOver) { + return; + } m_elapsedTimeTimer.stop(); m_gameTimer.stop(); emit gamePaused(); @@ -107,8 +110,9 @@ void GameEngine::resume() { - if (!gameIsPaused()) return; - + if (!gameIsPaused()) { + return; + } m_elapsedTimeTimer.start(); m_gameTimer.start(); @@ -127,8 +131,9 @@ void GameEngine::moveBar(int newPos) { - if (gameIsPaused()) return; - + if (gameIsPaused()) { + return; + } // width of the game int width = BRICK_WIDTH * WIDTH; // width of the bar @@ -139,8 +144,7 @@ if (x < 0) { x = 0; emit resetMousePosition(); - } - else if (x > width - w) { + } else if (x > width - w) { x = width - w; emit resetMousePosition(); } @@ -167,7 +171,9 @@ } foreach (Ball *ball, m_balls) { - if (!ball->toBeFired) continue; + if (!ball->toBeFired) { + continue; + } // else ball->toBeFired = false; @@ -232,7 +238,9 @@ m_speed = 1.8; m_repaintInterval = 1; m_levelInfo.setLevel(m_level); - if (gameIsPaused()) resume(); + if (gameIsPaused()) { + resume(); + } showMessage(i18n("Level %1", m_level)); QTimer::singleShot(2000, this, SLOT(hideMessage())); @@ -271,7 +279,9 @@ } if (m_speed < 1.0) { if (m_gameTimer.interval() >= REPAINT_INTERVAL) { - if (m_speed < MINIMUM_SPEED) m_speed = MINIMUM_SPEED; + if (m_speed < MINIMUM_SPEED) { + m_speed = MINIMUM_SPEED; + } return; } // else @@ -294,29 +304,36 @@ m_dScore *= SCORE_AUTO_DECREASE; foreach (Ball *ball, m_balls) { - if (ball->toBeFired) continue; + if (ball->toBeFired) { + continue; + } // TODO: add function ball->move(speed) ball->moveBy(ball->directionX * m_speed, ball->directionY * m_speed); // collision detection detectBallCollisions(ball); - if (m_itemsGotDeleted) return; + if (m_itemsGotDeleted) { + return; } + } QMutableListIterator i(m_gifts); while (i.hasNext()) { Gift *gift = i.next(); - if (!gift->isVisible()) continue; // do nothing + if (!gift->isVisible()) { + continue; // do nothing + } qreal giftSpeed = std::sqrt(m_speed / m_gameTimer.interval()); gift->move(giftSpeed, m_gameTimer.interval()); if (gift->getRect().bottom() > BRICK_HEIGHT * HEIGHT) { i.remove(); delete gift; + } else if (m_bar.getRect().intersects(gift->getRect())) { + gift->execute(this); + if (m_itemsGotDeleted) { + return; } - else if (m_bar.getRect().intersects(gift->getRect())) { - gift->execute(this); - if (m_itemsGotDeleted) return; i.remove(); delete gift; } @@ -332,8 +349,9 @@ } foreach (Gift *gift, m_gifts) { - if (!gift->isVisible()) continue; - + if (!gift->isVisible()) { + continue; + } gift->repaint(); } @@ -432,9 +450,7 @@ ball->directionY = -sin(angle) * speed; } } - } - // bounce against the bricks (and optionally break them) - else { + } else { // bounce against the bricks (and optionally break them) handleBrickCollisions(ball); } @@ -478,12 +494,16 @@ void GameEngine::handleBrickCollisions(Ball *ball) { - if (m_itemsGotDeleted) return; + if (m_itemsGotDeleted) { + return; + } QRect rect = ball->getRect(); QList bricksIntersecting; foreach (Brick *brick, m_bricks) { - if (brick->isDeleted()) continue; + if (brick->isDeleted()) { + continue; + } QRect brickRect = brick->getRect(); if (brickRect.intersects(rect)) { @@ -514,7 +534,9 @@ void GameEngine::showFireBallMessage() { - if (Settings::fireOnClick()) return; // don't show message + if (Settings::fireOnClick()) { + return; // don't show message + } QAction *fireAction = m_mainWindow->actionCollection()->action("fire"); QString shortcut = fireAction->shortcut().toString(QKeySequence::NativeText); showInfoMessage(i18n("Press %1 to fire the ball", shortcut)); @@ -522,8 +544,12 @@ void GameEngine::hideMessage() { - if (gameIsPaused()) return; - if (m_gameWon && m_gameOver) return; + if (gameIsPaused()) { + return; + } + if (m_gameWon && m_gameOver) { + return; + } // else m_messageBox.hide(); @@ -534,9 +560,12 @@ // assign points for each remaining brick foreach (Brick *brick, m_bricks) { // don't assign points for Unbreakable Bricks - if (brick->type() == "UnbreakableBrick") continue; - if (brick->isDeleted()) continue; - + if (brick->type() == "UnbreakableBrick") { + continue; + } + if (brick->isDeleted()) { + continue; + } addScore(AUTOBRICK_SCORE); // add extra points for Multiple Bricks @@ -568,7 +597,9 @@ void GameEngine::updateAttachedBalls() { foreach (Ball *ball, m_balls) { - if (!ball->toBeFired) continue; + if (!ball->toBeFired) { + continue; + } // else int ballX = m_bar.getRect().left() + qRound(ball->barPosition * m_bar.getRect().width());