Changeset 11071 for code/trunk/src/modules/tetris
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/tetris/Tetris.cc
r10624 r11071 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 -
code/trunk/src/modules/tetris/Tetris.h
r10624 r11071 58 58 virtual ~Tetris(); //!< Destructor. Cleans up, if initialized. 59 59 60 virtual void start(void) ; //!< Starts the Tetris minigame.61 virtual void end(void) ; ///!< Ends the Tetris minigame.60 virtual void start(void) override; //!< Starts the Tetris minigame. 61 virtual void end(void) override; ///!< Ends the Tetris minigame. 62 62 63 virtual void tick(float dt) ;63 virtual void tick(float dt) override; 64 64 65 virtual void spawnPlayer(PlayerInfo* player) ; //!< Spawns the input player.66 virtual bool playerLeft(PlayerInfo* player) ;65 virtual void spawnPlayer(PlayerInfo* player) override; //!< Spawns the input player. 66 virtual bool playerLeft(PlayerInfo* player) override; 67 67 68 68 void setCenterpoint(TetrisCenterpoint* center); … … 77 77 78 78 protected: 79 virtual void spawnPlayersIfRequested() ; //!< Spawns player.79 virtual void spawnPlayersIfRequested() override; //!< Spawns player. 80 80 81 81 … … 93 93 94 94 WeakPtr<TetrisCenterpoint> center_; //!< The playing field. 95 std::list<StrongPtr<TetrisStone> 95 std::list<StrongPtr<TetrisStone>> stones_; //!< A list of all stones in play. 96 96 WeakPtr<TetrisBrick> activeBrick_; 97 97 WeakPtr<TetrisBrick> futureBrick_; -
code/trunk/src/modules/tetris/TetrisBrick.cc
r10624 r11071 81 81 this->attach(stone); 82 82 this->formBrick(stone, i); 83 if(this->tetris_ != NULL)83 if(this->tetris_ != nullptr) 84 84 { 85 85 stone->setGame(this->tetris_); 86 if(this->tetris_->getCenterpoint() != NULL)86 if(this->tetris_->getCenterpoint() != nullptr) 87 87 stone->addTemplate(this->tetris_->getCenterpoint()->getStoneTemplate()); 88 88 else 89 orxout()<< "tetris_->getCenterpoint == NULLin TetrisBrick.cc"<< endl;89 orxout()<< "tetris_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; 90 90 } 91 91 else 92 orxout()<< "tetris_ == NULLin TetrisBrick.cc"<< endl;92 orxout()<< "tetris_ == nullptr in TetrisBrick.cc"<< endl; 93 93 } 94 94 } … … 161 161 if(i < this->brickStones_.size()) 162 162 return this->brickStones_[i]; 163 else return NULL;163 else return nullptr; 164 164 } 165 165 … … 167 167 Tetris* TetrisBrick::getTetris() 168 168 { 169 if (this->getGametype() != NULL&& this->getGametype()->isA(Class(Tetris)))169 if (this->getGametype() != nullptr && this->getGametype()->isA(Class(Tetris))) 170 170 { 171 171 Tetris* tetrisGametype = orxonox_cast<Tetris*>(this->getGametype()); 172 172 return tetrisGametype; 173 173 } 174 return NULL;174 return nullptr; 175 175 } 176 176 … … 239 239 { 240 240 assert(this->tetris_); 241 for( unsigned int i = 0; i < this->brickStones_.size(); i++)242 { 243 this->brickStones_[i]->detachFromParent();244 this->brickStones_[i]->attachToParent(center);245 this->brickStones_[i]->setPosition(this->getPosition()+this->tetris_->rotateVector(this->brickStones_[i]->getPosition(),this->rotationCount_ ));241 for(TetrisStone* stone : this->brickStones_) 242 { 243 stone->detachFromParent(); 244 stone->attachToParent(center); 245 stone->setPosition(this->getPosition()+this->tetris_->rotateVector(stone->getPosition(),this->rotationCount_ )); 246 246 } 247 247 this->brickStones_.clear(); -
code/trunk/src/modules/tetris/TetrisBrick.h
r10262 r11071 57 57 virtual ~TetrisBrick() {} 58 58 59 virtual void moveFrontBack(const Vector2& value) ; //!< Overloaded the function to steer the bat up and down.60 virtual void moveRightLeft(const Vector2& value) ; //!< Overloaded the function to steer the bat up and down.61 virtual void changedPlayer() ; //!< Is called when the player changed.59 virtual void moveFrontBack(const Vector2& value) override; //!< Overloaded the function to steer the bat up and down. 60 virtual void moveRightLeft(const Vector2& value) override; //!< Overloaded the function to steer the bat up and down. 61 virtual void changedPlayer() override; //!< Is called when the player changed. 62 62 63 63 bool isValidMove(const Vector3& position, bool isRotation); -
code/trunk/src/modules/tetris/TetrisCenterpoint.cc
r10624 r11071 84 84 void TetrisCenterpoint::checkGametype() 85 85 { 86 if (this->getGametype() != NULL&& this->getGametype()->isA(Class(Tetris)))86 if (this->getGametype() != nullptr && this->getGametype()->isA(Class(Tetris))) 87 87 { 88 88 Tetris* tetrisGametype = orxonox_cast<Tetris*>(this->getGametype()); -
code/trunk/src/modules/tetris/TetrisCenterpoint.h
r10624 r11071 62 62 virtual ~TetrisCenterpoint() {} 63 63 64 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ; //!< Method to create a TetrisCenterpoint through XML.64 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method to create a TetrisCenterpoint through XML. 65 65 66 66 /** -
code/trunk/src/modules/tetris/TetrisScore.cc
r10624 r11071 36 36 37 37 #include "core/CoreIncludes.h" 38 #include "core/XMLPort.h"39 38 #include "util/Convert.h" 40 39 … … 56 55 RegisterObject(TetrisScore); 57 56 58 this->owner_ = 0;59 this->player_ = NULL;57 this->owner_ = nullptr; 58 this->player_ = nullptr; 60 59 } 61 60 … … 66 65 TetrisScore::~TetrisScore() 67 66 { 68 }69 70 /**71 @brief72 Method to create a TetrisScore through XML.73 */74 void TetrisScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)75 {76 SUPER(TetrisScore, XMLPort, xmlelement, mode);77 67 } 78 68 … … 89 79 90 80 // If the owner is set. The owner being a Tetris game. 91 if (this->owner_ != NULL)81 if (this->owner_ != nullptr) 92 82 { 93 83 std::string score("0"); … … 101 91 { 102 92 // Save the name and score of each player as a string. 103 if (player_ != NULL)93 if (player_ != nullptr) 104 94 score = multi_cast<std::string>(this->owner_->getScore(player_)); 105 95 } … … 111 101 @brief 112 102 Is called when the owner changes. 113 Sets the owner to NULL, if it is not a pointer to a Tetris game.103 Sets the owner to nullptr, if it is not a pointer to a Tetris game. 114 104 */ 115 105 void TetrisScore::changedOwner() … … 117 107 SUPER(TetrisScore, changedOwner); 118 108 119 if (this->getOwner() != NULL&& this->getOwner()->getGametype())109 if (this->getOwner() != nullptr && this->getOwner()->getGametype()) 120 110 this->owner_ = orxonox_cast<Tetris*>(this->getOwner()->getGametype()); 121 111 else 122 this->owner_ = 0;112 this->owner_ = nullptr; 123 113 } 124 114 } -
code/trunk/src/modules/tetris/TetrisScore.h
r10262 r11071 60 60 virtual ~TetrisScore(); 61 61 62 virtual void tick(float dt); //!< Creates and sets the caption to be displayed by the TetrisScore. 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 64 virtual void changedOwner(); //!< Is called when the owner changes. 62 virtual void tick(float dt) override; //!< Creates and sets the caption to be displayed by the TetrisScore. 63 virtual void changedOwner() override; //!< Is called when the owner changes. 65 64 66 65 private:
Note: See TracChangeset
for help on using the changeset viewer.