/[eliot]/eliot/game/game.cpp
ViewVC logotype

Diff of /eliot/game/game.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by ipkiss, Sat Nov 5 11:01:58 2005 UTC revision 1.19 by ipkiss, Sat Nov 5 13:56:59 2005 UTC
# Line 209  Game * Game::load(FILE *fin, const Dicti Line 209  Game * Game::load(FILE *fin, const Dicti
209    
210              // Build a round              // Build a round
211              Round round;              Round round;
212                round.accessCoord().setFromString(ref);
213                if (!round.getCoord().isValid())
214                    continue;
215    
216              round.setPoints(pts);              round.setPoints(pts);
217              if (bonus == '*')              if (bonus == '*')
218                  round.setBonus(1);                  round.setBonus(1);
219    
220              if (isalpha(ref[0]))              for (unsigned int i = 0; i < strlen(word); i++)
221              {              {
222                  // Horizontal word                  tile = Tile(word[i]);
                 round.setDir(Coord::HORIZONTAL);  
                 round.setRow(ref[0] - 'A' + 1);  
                 round.setCol(atoi(ref + 1));  
223    
224                  for (unsigned int i = 0; i < strlen(word); i++)                  if (round.getCoord().getDir() == Coord::HORIZONTAL)
225                  {                  {
226                      tile = Tile(word[i]);                      if (!pGame->m_board.getTile(round.getCoord().getRow(),
227                                                    round.getCoord().getCol() + i).isEmpty())
                     if (!pGame->m_board.getTile(round.getRow(), round.getCol() + i).isEmpty())  
228                      {                      {
229                          round.addRightFromBoard(tile);                          round.addRightFromBoard(tile);
230                      }                      }
# Line 234  Game * Game::load(FILE *fin, const Dicti Line 234  Game * Game::load(FILE *fin, const Dicti
234                          pGame->m_bag.takeTile((islower(word[i])) ? Tile::Joker() : tile);                          pGame->m_bag.takeTile((islower(word[i])) ? Tile::Joker() : tile);
235                      }                      }
236                  }                  }
237              }                  else
             else  
             {  
                 // Vertical word  
                 round.setDir(Coord::VERTICAL);  
                 round.setRow(ref[strlen(ref) - 1] - 'A' + 1);  
                 round.setCol(atoi(ref));  
   
                 for (unsigned int i = 0; i < strlen(word); i++)  
238                  {                  {
239                      tile = Tile(word[i]);                      if (!pGame->m_board.getTile(round.getCoord().getRow() + i,
240                                                    round.getCoord().getCol()).isEmpty())
                     if (!pGame->m_board.getTile(round.getRow() + i, round.getCol()).isEmpty())  
241                      {                      {
242                          round.addRightFromBoard(tile);                          round.addRightFromBoard(tile);
243                      }                      }
# Line 717  int Game::helperSetRackManual(int p, boo Line 708  int Game::helperSetRackManual(int p, boo
708    
709  string Game::formatCoords(const Round &iRound) const  string Game::formatCoords(const Round &iRound) const
710  {  {
711      if (iRound.getDir() == Coord::HORIZONTAL)      ASSERT(iRound.getCoord().isValid(), "Invalid coordinates");
712      {      return iRound.getCoord().toString();
         char s[5];  
         sprintf(s, "%d", iRound.getCol());  
         return string(1, iRound.getRow() + 'A' - 1) + s;  
     }  
     else  
     {  
         char s[5];  
         sprintf(s, "%d", iRound.getCol());  
         return s + string(1, iRound.getRow() + 'A' - 1);  
     }  
713  }  }
714    
715    
# Line 888  int Game::checkPlayedWord(const string & Line 869  int Game::checkPlayedWord(const string &
869  {  {
870      ASSERT(getNPlayers() != 0, "Expected at least one player");      ASSERT(getNPlayers() != 0, "Expected at least one player");
871    
     char l[4];  
     int col, row;  
872      int res;      int res;
873      vector<Tile> tiles;      vector<Tile> tiles;
874      Tile t;      Tile t;
875    
876      /* Init the round with the given coordinates */      /* Init the round with the given coordinates */
877      oRound.init();      oRound.init();
878      if (sscanf(iCoord.c_str(), "%1[a-oA-O]%2d", l, &col) == 2)      oRound.accessCoord().setFromString(iCoord);
879          oRound.setDir(Coord::HORIZONTAL);      if (!oRound.getCoord().isValid())
     else if (sscanf(iCoord.c_str(), "%2d%1[a-oA-O]", &col, l) == 2)  
         oRound.setDir(Coord::VERTICAL);  
     else  
         return 2;  
     row = toupper(*l) - 'A' + 1;  
     if (col < BOARD_MIN || col > BOARD_MAX ||  
         row < BOARD_MIN || row > BOARD_MAX)  
     {  
880          return 2;          return 2;
     }  
     oRound.setCol(col);  
     oRound.setRow(row);  
881    
882      /* Check the existence of the word */      /* Check the existence of the word */
883      if (Dic_search_word(*m_dic, iWord.c_str()) == 0)      if (Dic_search_word(*m_dic, iWord.c_str()) == 0)

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26