Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2011, 9:59:01 PM (13 years ago)
Author:
dafrick
Message:

Fixing bug in tetris.

Location:
code/branches/presentation/src/modules/tetris
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/modules/tetris/Tetris.cc

    r8564 r8565  
    9191        if(this->activeStone_ != NULL)
    9292        {
    93             std::pair<bool, TetrisStone*> valid = this->isValidMove(this->activeStone_, this->activeStone_->getPosition());
     93            std::pair<bool, TetrisStone*> valid = this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition());
    9494            if(!valid.first)
    9595            {
     
    116116        else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize()) //!< If the stone touches the right edge of the level
    117117            valid.first = false;
    118         else if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
    119         {
    120             valid.first = false;
    121             stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0, stone->getPosition().z));
    122         }
    123118
    124119        for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     
    137132                return valid;
    138133            }// This case applies if the stones overlap completely
    139             else if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
     134        }
     135
     136        return valid;
     137    }
     138
     139    std::pair<bool, TetrisStone*> Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
     140    {
     141        assert(stone);
     142
     143        std::pair<bool, TetrisStone*> valid = std::pair<bool, TetrisStone*>(true, NULL);
     144
     145        if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
     146        {
     147            valid.first = false;
     148            stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0, stone->getPosition().z));
     149        }
     150
     151        for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     152        {
     153            if(stone == *it)
     154                continue;
     155
     156            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
     157
     158            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    140159            {
    141160                valid.first = false;
  • code/branches/presentation/src/modules/tetris/Tetris.h

    r8564 r8565  
    7878            void createStone(void);
    7979            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
     80            std::pair<bool, TetrisStone*> isValidStonePosition(TetrisStone* stone, const Vector3& position);
    8081           
    8182            PlayerInfo* player_;
Note: See TracChangeset for help on using the changeset viewer.