Changeset 9087 for code/branches/pCuts/src/modules/tetris
- Timestamp:
- Apr 14, 2012, 5:45:44 PM (13 years ago)
- Location:
- code/branches/pCuts/src/modules/tetris
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/src/modules/tetris/Tetris.cc
r9086 r9087 23 23 * ... 24 24 * Co-authors: 25 * ... 26 * 25 * Johannes Ritz 26 * 27 *BUG a) double stone model (@ brick's location the stone's model is duplicated. Why does the brick have a model attached to it.) 28 *BUG b) the brick is set the wrong way after a (brick-brick) collision, if the brick was turned 29 *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ? 30 *BUG 31 * 32 *TASK a) give points for winning 33 *TASK b) write a hud (show points gained; new brick) 34 *TASK c) end the game in a nicer way 35 *TASK d) save the highscore 36 *TASK e) eye candy 27 37 */ 28 38 … … 65 75 66 76 this->player_ = NULL; 77 this->endGameCriteria_ = 0.0f; 67 78 } 68 79 … … 94 105 SUPER(Tetris, tick, dt); 95 106 96 if(this->activeBrick_ != NULL) 97 { 107 if((this->activeBrick_ != NULL)&&(!this->hasEnded())) 108 { 109 this->endGameCriteria_ += dt; 98 110 if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition())) 99 111 { … … 101 113 this->activeBrick_->releaseStones(this->center_); 102 114 //delete this->activeBrick_; //releasing the memory 115 this->findFullRows(); 116 if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval. 117 this->end(); 103 118 this->createBrick(); 104 119 this->startBrick(); 120 this->endGameCriteria_ = 0.0f; 105 121 } 106 122 } … … 257 273 void Tetris::end() 258 274 { 275 this->activeBrick_->setVelocity(Vector3::ZERO); 259 276 this->cleanup(); 260 277 … … 366 383 @brief Manage score. 367 384 */ 368 void Tetris::clearFullRow() 369 { 385 void Tetris::findFullRows() 386 { 387 unsigned int correctPosition = 0; 388 orxout()<< "clear full rows ************ " <<endl; 370 389 unsigned int stonesPerRow = 0; 371 for (unsigned int row = 0; row < this->center_->getHeight() /this->center_->getStoneSize(); row++)390 for (unsigned int row = 0; row < this->center_->getHeight(); row++) 372 391 { 373 392 stonesPerRow = 0; 374 393 for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it) 375 394 { 376 if((*it)->getPosition().y == row) 395 correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()); 396 if(correctPosition == row) 377 397 stonesPerRow++; 378 if(stonesPerRow == this->center_->getWidth() /this->center_->getStoneSize())379 orxout()<< "CANDIDATE FOUND in row " << row <<endl;398 if(stonesPerRow == this->center_->getWidth()) 399 {orxout()<< "CANDIDATE FOUND in row " << row <<endl; clearRow(row);} 380 400 } 381 401 … … 383 403 } 384 404 405 void Tetris::clearRow(unsigned int row) 406 {//std::vector<int>::iterator it = v.begin() 407 for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 408 { 409 if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row) 410 (*it)->setPosition(Vector3(-10,-10,0)); 411 //{(*it)->destroy(); this->stones_.erase(it); orxout()<< "destroy row "<<endl;}//experimental 412 } 413 for(std::vector<TetrisStone*>::const_reverse_iterator it2 = this->stones_.rbegin(); it2 != this->stones_.rend(); ++it2) 414 { 415 /*if(static_cast<unsigned int>(((*it2)->getPosition().y - 5)/this->center_->getStoneSize()) > row) 416 (*it2)->setPosition((*it2)->getPosition()-Vector3(0,1,0));//*/ 417 } 418 419 } 420 421 385 422 } -
code/branches/pCuts/src/modules/tetris/Tetris.h
r9086 r9087 85 85 bool isValidStonePosition(TetrisStone* stone, const Vector3& position); 86 86 bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position); 87 void clearFullRow(void); 87 void findFullRows(void); 88 void clearRow(unsigned int row); 88 89 89 90 … … 97 98 98 99 Timer starttimer_; //!< A timer to delay the start of the game. 100 float endGameCriteria_; //<! Works as a timer which is resetted, whenever a brick is created. 99 101 }; 100 102 } -
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
r9086 r9087 40 40 #include "TetrisStone.h" 41 41 #include "Tetris.h" 42 #include "util/Math.h" 42 43 43 44 namespace orxonox … … 52 53 { 53 54 RegisterObject(TetrisBrick); 54 55 this->shapeIndex_ = 4; //<! TODO: random number between 0 and 7 55 this->shapeIndex_ = static_cast<unsigned int>(rnd(7.0f)); //<! random number between 0 and 7 56 56 this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones 57 57 this->delay_ = false; … … 105 105 void TetrisBrick::formBrick(TetrisStone* stone, unsigned int i) 106 106 { 107 if(i != 0 && this->shapeIndex_ == 0)108 orxout() << "So it has come to this in TetrisBrick.cc"<< endl;109 107 if(i == 0) //setting the first stone as 110 108 {
Note: See TracChangeset
for help on using the changeset viewer.