Changeset 9328 for code/branches/presentation2012merge/src/modules/tetris
- Timestamp:
- Jul 22, 2012, 5:57:54 PM (12 years ago)
- Location:
- code/branches/presentation2012merge/src/modules/tetris
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/tetris/Tetris.cc
r9326 r9328 67 67 RegisterObject(Tetris); 68 68 69 this->activeBrick_ = NULL;69 this->activeBrick_ = 0; 70 70 71 71 // Pre-set the timer, but don't start it yet. … … 76 76 this->endGameCriteria_ = 0.0f; 77 77 this->setHUDTemplate("TetrisHUD"); 78 this->futureBrick_ = NULL;78 this->futureBrick_ = 0; 79 79 } 80 80 … … 95 95 void Tetris::cleanup() 96 96 { 97 if (this->isInitialized()) 98 { 99 if (this->activeBrick_) 100 { 101 this->activeBrick_->destroy(); 102 this->activeBrick_ = NULL; 103 } 104 if (this->futureBrick_) 105 { 106 this->futureBrick_->destroy(); 107 this->futureBrick_ = NULL; 108 } 109 110 for (std::list<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 111 (*it)->destroy(); 112 this->stones_.clear(); 113 } 97 if (this->activeBrick_) 98 { 99 this->activeBrick_->destroy(); 100 this->activeBrick_ = 0; 101 } 102 if (this->futureBrick_) 103 { 104 this->futureBrick_->destroy(); 105 this->futureBrick_ = 0; 106 } 107 108 for (std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 109 (*it)->destroy(); 110 this->stones_.clear(); 114 111 } 115 112 … … 129 126 this->findFullRows(); 130 127 if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval. 131 {132 128 this->end(); 133 return; 134 } 135 this->startBrick(); 129 else 130 this->startBrick(); 136 131 this->endGameCriteria_ = 0.0f; 137 132 } … … 148 143 return false; 149 144 150 for(std::list< TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)145 for(std::list<SmartPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 151 146 { 152 147 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone … … 201 196 202 197 // we use a reverse iterator because we have to check for collisions with the topmost stones first 203 for(std::list< TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)198 for(std::list<SmartPtr<TetrisStone> >::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it) 204 199 { 205 200 //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount()); … … 364 359 // Make the last brick to be created the active brick. 365 360 this->activeBrick_ = this->futureBrick_; 366 this->futureBrick_ = NULL;361 this->futureBrick_ = 0; 367 362 368 363 // set its position … … 432 427 { 433 428 stonesPerRow = 0; 434 for(std::list< TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); )435 { 436 std::list< TetrisStone*>::iterator it_temp = it++;429 for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ) 430 { 431 std::list<SmartPtr<TetrisStone> >::iterator it_temp = it++; 437 432 correctPosition = static_cast<unsigned int>(((*it_temp)->getPosition().y - 5)/this->center_->getStoneSize()); 438 433 if(correctPosition == row) … … 454 449 void Tetris::clearRow(unsigned int row) 455 450 {// clear the full row 456 for(std::list< TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); )451 for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ) 457 452 { 458 453 if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row) … … 465 460 } 466 461 // adjust height of stones above the deleted row //TODO: check if this could be a source of a bug. 467 for(std::list< TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)462 for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 468 463 { 469 464 if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) > row) -
code/branches/presentation2012merge/src/modules/tetris/Tetris.h
r9326 r9328 92 92 93 93 WeakPtr<TetrisCenterpoint> center_; //!< The playing field. 94 std::list< TetrisStone*> stones_; //!< A list of all stones in play.95 TetrisBrick*activeBrick_;96 TetrisBrick*futureBrick_;94 std::list<SmartPtr<TetrisStone> > stones_; //!< A list of all stones in play. 95 WeakPtr<TetrisBrick> activeBrick_; 96 WeakPtr<TetrisBrick> futureBrick_; 97 97 98 98 Timer starttimer_; //!< A timer to delay the start of the game. -
code/branches/presentation2012merge/src/modules/tetris/TetrisBrick.cc
r9327 r9328 236 236 { 237 237 assert(this->tetris_); 238 for(unsigned int i = 0; i < brickStones_.size(); i++)238 for(unsigned int i = 0; i < this->brickStones_.size(); i++) 239 239 { 240 240 this->brickStones_[i]->detachFromParent(); … … 242 242 this->brickStones_[i]->setPosition(this->getPosition()+this->tetris_->rotateVector(this->brickStones_[i]->getPosition(),this->rotationCount_ )); 243 243 } 244 244 this->brickStones_.clear(); 245 245 } 246 246
Note: See TracChangeset
for help on using the changeset viewer.