For the Xmover program, the solution I wrote is a total kludge. If I come up with something a little more elegant I'll post that code later.
case DOWN:
if(row < console.getRows()-1){
if(row == console.getRows()-2 && col == console.getCols()-1){
console.alarm();
}
else{
row++;
}
}
else{
console.alarm();
}
break;
case RIGHT:
if(col < console.getCols()-1){
if(col == console.getCols()-2 && row == console.getRows()-1){
console.alarm();
}
else{
col++;
}
}
else{
console.alarm();
}
break;
For removing the 'if' from the ::display() function and reducing it to one line I once again wrote a total kludge, it is completely confusing to look at and it's ugly but dang it it works.
void Console::display(const char* str, int row, int col, int fieldLen){
setPos(row, col);
int i;
for(i=0,fieldLen==0?fieldLen=strlen(str):i=0;i<fieldLen;str[i]!=0?putChar(str[i]):putChar(' '),i++);
}
This code also makes it possible to display any characters that you may insert past the first NULL char in the array when you are scrolling through str.