Commit 1535c053 authored by Frederik Schwarzer's avatar Frederik Schwarzer

Use range-based for loops.

parent d52e8e7b
......@@ -71,9 +71,9 @@ Game::Game(PlayerSettings* playerSettings)
init();
for (int i = 0; i < m_players.size(); i++)
for (auto & m_player : m_players)
{
connect(m_players[i], SIGNAL(bombDropped(Player*,qreal,qreal,bool,int)), this, SLOT(createBomb(Player*,qreal,qreal,bool,int)));
connect(m_player, SIGNAL(bombDropped(Player*,qreal,qreal,bool,int)), this, SLOT(createBomb(Player*,qreal,qreal,bool,int)));
}
m_gameOver = false;
......@@ -459,10 +459,10 @@ void Game::initCharactersPosition()
m_roundTimer->stop();
m_state = RUNNING;
// Initialize the Player coordinates
for(int i = 0; i < m_players.size(); ++i)
for(auto & m_player : m_players)
{
m_players[i]->initCoordinate();
m_players[i]->init();
m_player->initCoordinate();
m_player->init();
}
}
}
......@@ -505,9 +505,9 @@ void Game::keyPressEvent(QKeyEvent* p_event)
cleanUp();
init();
m_gameScene->init();
for(int i = 0; i < m_players.length(); ++i)
for(auto & m_player : m_players)
{
m_players[i]->resurrect();
m_player->resurrect();
}
}
}
......@@ -526,9 +526,9 @@ void Game::keyPressEvent(QKeyEvent* p_event)
}
//TODO: make signal
for(int i = 0; i < m_players.size(); ++i)
for(auto & m_player : m_players)
{
m_players[i]->keyPressed(p_event);
m_player->keyPressed(p_event);
}
}
......@@ -539,25 +539,25 @@ void Game::keyReleaseEvent(QKeyEvent* p_event)
return;
}
//TODO: make signal
for(int i = 0; i < m_players.size(); ++i)
for(auto & m_player : m_players)
{
m_players[i]->keyReleased(p_event);
m_player->keyReleased(p_event);
}
}
void Game::update()
{
//update Bombs
for (int i = 0; i < m_bombs.size(); ++i)
for (auto & m_bomb : m_bombs)
{
m_bombs[i]->updateMove();
m_bomb->updateMove();
}
//update Player
for(int i = 0; i < m_players.size(); ++i)
for(auto & m_player : m_players)
{
m_players[i]->updateMove();
m_players[i]->emitGameUpdated();
m_player->updateMove();
m_player->emitGameUpdated();
}
}
......@@ -626,9 +626,9 @@ void Game::playerDeath()
if(!m_setRoundFinishedTimer->isActive())
{
int nPlayerAlive = 0;
for(int i = 0; i < m_players.length(); ++i)
for(auto & m_player : m_players)
{
if(m_players[i]->isAlive())
if(m_player->isAlive())
{
nPlayerAlive++;
}
......@@ -643,11 +643,11 @@ void Game::playerDeath()
void Game::resurrectBonusTaken()
{
for(int i = 0; i < m_players.length(); ++i)
for(auto & m_player : m_players)
{
if(!(m_players[i]->isAlive()))
if(!(m_player->isAlive()))
{
m_players[i]->resurrect();
m_player->resurrect();
}
}
}
......@@ -681,13 +681,13 @@ void Game::setRoundFinished()
pause(true);
for(int i = 0; i < m_players.length(); ++i)
for(auto & m_player : m_players)
{
// check if a player reaches the win points
if (m_players[i]->points() >= m_winPoints)
if (m_player->points() >= m_winPoints)
{
m_gameOver = true;
m_strWinner = m_players[i]->getPlayerName();
m_strWinner = m_player->getPlayerName();
break;
}
}
......
......@@ -66,16 +66,16 @@ GameScene::GameScene(Game* p_game, KgThemeProvider* p_themeProvider) : m_game(p_
QList <Player*> players = p_game->getPlayers();
PlayerItem* playerItem;
for(int i = 0; i < players.size(); i++)
for(auto & player : players)
{
const QString desktopPath = players[i]->getDesktopFilePath();
const QString desktopPath = player->getDesktopFilePath();
KgTheme* theme = new KgTheme(desktopPath.toUtf8());
theme->readFromDesktopFile(desktopPath);
KGameRenderer* playerRenderer = new KGameRenderer(theme);
m_mapRendererPlayerItems.insert(players[i], playerRenderer);
playerItem = new PlayerItem(players[i], playerRenderer);
auto playerRenderer = new KGameRenderer(theme);
m_mapRendererPlayerItems.insert(player, playerRenderer);
playerItem = new PlayerItem(player, playerRenderer);
// Corrects the position of the player
playerItem->update(players[i]->getX(), players[i]->getY());
playerItem->update(player->getX(), player->getY());
// Stops the player animation
playerItem->stopAnim();
......@@ -208,13 +208,13 @@ void GameScene::init()
initItemsWithGraphicsFromTheme();
// Display each PlayerItem
for (int i = 0; i < m_playerItems.size(); i++)
for (auto & m_playerItem : m_playerItems)
{
if(!items().contains(m_playerItems[i]))
if(!items().contains(m_playerItem))
{
addItem(m_playerItems[i]);
addItem(m_playerItem);
}
m_playerItems[i]->resurrect();
m_playerItem->resurrect();
}
if (!items().contains(m_remainingTimeLabel))
......@@ -498,14 +498,14 @@ GameScene::~GameScene()
delete m_infoOverlay;
for (int i = 0; i < m_playerItems.size(); i++)
for (auto & m_playerItem : m_playerItems)
{
if(items().contains(m_playerItems[i]))
if(items().contains(m_playerItem))
{
removeItem(m_playerItems[i]);
removeItem(m_playerItem);
}
m_playerItems[i]->stopAnim();
delete m_playerItems[i];
m_playerItem->stopAnim();
delete m_playerItem;
}
QMap <Player*, KGameRenderer*>::iterator iteratorRendererPlayer = m_mapRendererPlayerItems.begin();
......@@ -735,9 +735,9 @@ void GameScene::setPaused(const bool p_pause, const bool p_fromUser)
}
// Stop player animation
for (int i = 0; i < m_playerItems.size(); i++)
for (auto & m_playerItem : m_playerItems)
{
m_playerItems[i]->pauseAnim();
m_playerItem->pauseAnim();
}
// Stop bomb animation
QHash<BombItem*, QList<BombExplosionItem*> >::iterator i = m_bombItems.begin();
......@@ -752,9 +752,9 @@ void GameScene::setPaused(const bool p_pause, const bool p_fromUser)
m_infoOverlay->hideItems();
// Resume player animation
for (int i = 0; i < m_playerItems.size(); i++)
for (auto & m_playerItem : m_playerItems)
{
m_playerItems[i]->resumeAnim();
m_playerItem->resumeAnim();
}
// Resume bomb animation
QHash<BombItem*, QList<BombExplosionItem*> >::iterator i = m_bombItems.begin();
......
......@@ -185,18 +185,18 @@ void InfoOverlay::showScore ()
m_gameScene->addItem(m_dimmOverlay);
}
for(int i = 0; i < players.length(); i++)
for(auto & player : players)
{
if (!m_gameScene->items().contains(m_mapPlayerNames.value(players[i])))
if (!m_gameScene->items().contains(m_mapPlayerNames.value(player)))
{
// display the player name
m_gameScene->addItem(m_mapPlayerNames.value(players[i]));
m_gameScene->addItem(m_mapPlayerNames.value(player));
}
for(int j = 0; j < nWinPoints; j++)
{
svgItem = m_mapScore.value(players[i]).at(j);
if (players[i]->points() > j)
svgItem = m_mapScore.value(player).at(j);
if (player->points() > j)
{
svgItem->setSpriteKey(QStringLiteral("score_star_enabled"));
}
......@@ -239,17 +239,17 @@ void InfoOverlay::hideItems ()
int nWinPoints = m_game->getWinPoints();
QList <Player*> players = m_game->getPlayers();
for(int i = 0; i < players.length(); i++)
for(auto & player : players)
{
if (m_gameScene->items().contains(m_mapPlayerNames.value(players[i])))
if (m_gameScene->items().contains(m_mapPlayerNames.value(player)))
{
// display the player name
m_gameScene->removeItem(m_mapPlayerNames.value(players[i]));
m_gameScene->removeItem(m_mapPlayerNames.value(player));
}
for(int j = 0; j < nWinPoints; j++)
{
KGameRenderedItem* svgItem = m_mapScore.value(players[i]).at(j);
KGameRenderedItem* svgItem = m_mapScore.value(player).at(j);
// if the score is displayed
if (m_gameScene->items().contains(svgItem))
{
......
......@@ -165,21 +165,21 @@ void PlayerItem::manageCollision()
// when the player only collides with the arena)
if (collidingList.size() > 1)
{
for (int i = 0; i < collidingList.size(); ++i)
for (auto & i : collidingList)
{
// The arena and the points labels have a negative zValue which allows to exclude them from the treatment of collisions
if (collidingList[i]->zValue() >= 300 && collidingList[i]->zValue() < 400)
if (i->zValue() >= 300 && i->zValue() < 400)
{
//((ElementItem*)collidingList[i])->getModel()->doActionOnCollision((Player*)getModel());
int nExplosionID;
if(collidingList[i]->zValue() == 315)
if(i->zValue() == 315)
{
BombItem* bombItem = dynamic_cast <BombItem*> (collidingList[i]);
BombItem* bombItem = dynamic_cast <BombItem*> (i);
nExplosionID = dynamic_cast <Bomb*> (bombItem->getModel())->explosionID();
}
else
{
nExplosionID = dynamic_cast <BombExplosionItem*> (collidingList[i])->explosionID();
nExplosionID = dynamic_cast <BombExplosionItem*> (i)->explosionID();
}
if(dynamic_cast <Player*> (m_model)->shield(nExplosionID) == false)
......@@ -188,9 +188,9 @@ void PlayerItem::manageCollision()
dynamic_cast <Player*> (m_model)->die();
}
}
else if (collidingList[i]->zValue() == 100)
else if (i->zValue() == 100)
{
bonusItem = dynamic_cast <BonusItem*> (collidingList[i]);
bonusItem = dynamic_cast <BonusItem*> (i);
if(dynamic_cast <Bonus*> (bonusItem->getModel())->isTaken() == false)
{
dynamic_cast <Bonus*> (bonusItem->getModel())->setTaken();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment