/* To stop the box from moving into the corner where it causes the weird scroll, I used a bool and flipped it on and off as appropriate. Otherwise I simply checked for the borders on a 25x80 console window and prevented the rows/cols from advancing if the box was at the consoles edge. I also included <stdio.h> for debugging purposes with printf, and would have removed all references to it, but I left it in as a reminder to myself.
*/
#include "console.h"
#include <stdio.h>
using namespace cui;
void prnbox(int row, int col){
console.dspstr("*****************", row , col);
console.dspstr("*****************", row + 1, col);
console.dspstr("*****************", row + 2, col);
}
int main(){
bool done = false;
int row = 0;
int col = 0;
bool dead=false;
int key;
while(!done){
if(row+3==console.getRows()&&col+18==console.getCols()||row+4==console.getRows()&&col+17==console.getCols())dead=true;
else dead=false;
//console.setPos(row,40);
//printf("Row: %d Col: %d Dead=%d",row,col,dead); DEBUG LINE
//console.setPos(10,55);
//printf("TotRow: %d TotCol: %d",console.getRows(),console.getCols()); BASED ON 25x80 console
prnbox(row, col);
key = console.getKey();
switch(key){
case DOWN:
if(row+3<console.getRows()&&!dead){
row++;
}
console.clear();
break;
case UP:
if(row>0){
row--;
}
console.clear();
break;
case RIGHT:
if(col+17<console.getCols()&&!dead){
col++;
}
console.clear();
break;
case LEFT:
if(col>0){
col--;
}
console.clear();
break;
case ESCAPE:
done = true;
break;
}
}
return 0;
}
No comments:
Post a Comment