Changeset 11054 for code/branches/cpp11_v3/src/modules/tetris/Tetris.cc
- Timestamp:
- Jan 10, 2016, 1:54:11 PM (9 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/modules/tetris/Tetris.cc
r10624 r11054 66 66 RegisterObject(Tetris); 67 67 68 this->activeBrick_ = 0;68 this->activeBrick_ = nullptr; 69 69 70 70 // Pre-set the timer, but don't start it yet. … … 72 72 this->starttimer_.stopTimer(); 73 73 74 this->player_ = NULL;74 this->player_ = nullptr; 75 75 this->setHUDTemplate("TetrisHUD"); 76 this->futureBrick_ = 0;76 this->futureBrick_ = nullptr; 77 77 } 78 78 … … 96 96 { 97 97 this->activeBrick_->destroy(); 98 this->activeBrick_ = 0;98 this->activeBrick_ = nullptr; 99 99 } 100 100 if (this->futureBrick_) 101 101 { 102 102 this->futureBrick_->destroy(); 103 this->futureBrick_ = 0;104 } 105 106 for ( std::list<StrongPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)107 (*it)->destroy();103 this->futureBrick_ = nullptr; 104 } 105 106 for (TetrisStone* stone : this->stones_) 107 stone->destroy(); 108 108 this->stones_.clear(); 109 109 } … … 113 113 SUPER(Tetris, tick, dt); 114 114 115 if((this->activeBrick_ != NULL)&&(!this->hasEnded()))115 if((this->activeBrick_ != nullptr)&&(!this->hasEnded())) 116 116 { 117 117 if(!this->isValidBrickPosition(this->activeBrick_)) … … 136 136 return false; 137 137 138 for( std::list<StrongPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)139 { 140 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone138 for(TetrisStone* someStone : this->stones_) 139 { 140 const Vector3& currentStonePosition = someStone->getPosition(); //!< Saves the position of the currentStone 141 141 142 142 if((position.x == currentStonePosition.x) && abs(position.y-currentStonePosition.y) < this->center_->getStoneSize()) … … 192 192 193 193 // check for collisions with all stones 194 for( std::list<StrongPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)194 for(TetrisStone* someStone : this->stones_) 195 195 { 196 196 //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount()); 197 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone197 const Vector3& currentStonePosition = someStone->getPosition(); //!< Saves the position of the currentStone 198 198 199 199 //filter out cases where the falling stone is already below a steady stone … … 290 290 void Tetris::start() 291 291 { 292 if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.292 if (this->center_ != nullptr) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place. 293 293 { 294 294 // Create the first brick. … … 323 323 { 324 324 this->activeBrick_->setVelocity(Vector3::ZERO); 325 if(this->activeBrick_ != NULL)325 if(this->activeBrick_ != nullptr) 326 326 { 327 327 this->player_->stopControl(); … … 341 341 { 342 342 // Spawn a human player. 343 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)344 if ( it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))345 this->spawnPlayer( it->first);343 for (const auto& mapEntry : this->players_) 344 if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_)) 345 this->spawnPlayer(mapEntry.first); 346 346 } 347 347 … … 351 351 if(player && player->isHumanPlayer()) 352 352 { 353 if(this->activeBrick_ != NULL)353 if(this->activeBrick_ != nullptr) 354 354 { 355 355 this->player_->stopControl(); … … 370 370 assert(player); 371 371 372 if(this->player_ == NULL)372 if(this->player_ == nullptr) 373 373 { 374 374 this->player_ = player; … … 381 381 void Tetris::startBrick(void) 382 382 { 383 if(this->player_ == NULL)383 if(this->player_ == nullptr) 384 384 return; 385 385 386 386 unsigned int cameraIndex = 0; 387 if(this->activeBrick_ != NULL)387 if(this->activeBrick_ != nullptr) 388 388 { 389 389 // Get camera settings … … 396 396 // Make the last brick to be created the active brick. 397 397 this->activeBrick_ = this->futureBrick_; 398 this->futureBrick_ = 0;398 this->futureBrick_ = nullptr; 399 399 400 400 // set its position … … 437 437 Get the player. 438 438 @return 439 Returns a pointer to the player. If there is no player, NULLis returned.439 Returns a pointer to the player. If there is no player, nullptr is returned. 440 440 */ 441 441 PlayerInfo* Tetris::getPlayer(void) const … … 469 469 { 470 470 stonesPerRow = 0; 471 for(std::list<StrongPtr<TetrisStone> 472 { 473 std::list<StrongPtr<TetrisStone> 471 for(std::list<StrongPtr<TetrisStone>>::iterator it = this->stones_.begin(); it != this->stones_.end(); ) 472 { 473 std::list<StrongPtr<TetrisStone>>::iterator it_temp = it++; 474 474 correctPosition = static_cast<unsigned int>(((*it_temp)->getPosition().y - 5)/this->center_->getStoneSize()); 475 475 if(correctPosition == row) … … 491 491 void Tetris::clearRow(unsigned int row) 492 492 {// clear the full row 493 for(std::list<StrongPtr<TetrisStone> 493 for(std::list<StrongPtr<TetrisStone>>::iterator it = this->stones_.begin(); it != this->stones_.end(); ) 494 494 { 495 495 if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row) … … 502 502 } 503 503 // adjust height of stones above the deleted row //TODO: check if this could be a source of a bug. 504 for( std::list<StrongPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)505 { 506 if(static_cast<unsigned int>(( (*it)->getPosition().y - 5)/this->center_->getStoneSize()) > row)507 (*it)->setPosition((*it)->getPosition()-Vector3(0,10,0));504 for(TetrisStone* stone : this->stones_) 505 { 506 if(static_cast<unsigned int>((stone->getPosition().y - 5)/this->center_->getStoneSize()) > row) 507 stone->setPosition(stone->getPosition()-Vector3(0,10,0)); 508 508 } 509 509
Note: See TracChangeset
for help on using the changeset viewer.