Sunday 3 February 2013
C++:Display &Move function
Hi, Everyone:
I wrote the display & move function in the blog.Please let me know any issues for these codes.We also discuss some better way to realize the requirement!:)
The display function:
void Console::display(const char* str, int row, int col, int fieldLen){
console.setPos(row,col);
if(fieldLen){
int i;
for(i=0;i<fieldLen && str[i];i++){
this->putChar(str[i]);
}
for(;i<fieldLen;i++){
this->putChar(' ');
}
}
else{
(*this)<<str;
}
}
The move function:( tow parts)
while(!done){
console.display(&str[*strOffset], row, col, fieldLength);
console.setPos(row, col + *curPosition);
console >> key;
switch(key) {
case LEFT:
if(*curPosition != 0){
(*curPosition)--;
}
else if(*strOffset != 0){
(*strOffset)--;
}
else{
console.alarm();
}
break;
case RIGHT:
if(*curPosition < fieldLength - 1){
if(str[*strOffset + *curPosition] != '\0'){
(*curPosition)++;
}
}
else if(*strOffset < maxStrLength){
if(str[*strOffset + *curPosition] != '\0'){
(*strOffset)++;
}
}
else{
console.alarm();
}
break;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment