I tried a lot to make it in another way. But it is only done by this way..
X-mover: 
    case RIGHT:
        if(col == console.getCols()-2 && row == console.getRows()-1){
        console.alarm();
      }
        else if(col < console.getCols()-1){
        col++;
      }
      break;
      
    case DOWN:
      if(row == console.getRows()-2 && col == console.getCols()-1) {
        console.alarm();
      }
      else if(row < console.getRows()-1){
        row++;
      }
      break;
    
Removing if else statement from console.display() function.. It is done by condition operator
    void Console::display(const char* str, int row, int col, int fieldLen){
      setPos(row, col);
      int i;
      int lenght;
      lenght = strlen(str);
        
        for(i=0,fieldLen==0?fieldLen=lenght:i=0;i<fieldLen;str[i]!=0?putChar(str[i]):putChar(' '),i++);
    }
No comments:
Post a Comment