(WinXP, Borland C++ Free Command Line Compiler)
Ok, I made a short console game, you can move a dot around the screen. But, my barriers only work for up & down, left and right dont work for some odd reason. I have looked all around my code, and I tried swapping their values, but I dont understand why the barriers dont work, its just a simple if() function...
Well heres my code, its actualy pritty short:
Code:#include <windows.h> #include <iostream> #include <conio.h> using namespace std; enum { ESC_KEY = 27, UP_ARROW = 256+72, DOWN_ARROW = 256+80, LEFT_ARROW = 256+75, RIGHT_ARROW = 256+77 }; int get_arrow(); HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ); WORD Color; CONSOLE_SCREEN_BUFFER_INFO inf; CONSOLE_CURSOR_INFO Cur; int main() { COORD Pos; COORD Pos2; int Counter; int c2; int buffer; int grid_x; int grid_y; clrscr(); GetConsoleScreenBufferInfo(h, &inf); Color = inf.wAttributes; Cur.bVisible = FALSE; Cur.dwSize = 1; SetConsoleTextAttribute(h, BACKGROUND_RED | BACKGROUND_INTENSITY); SetConsoleCursorInfo(h, &Cur); SetConsoleTitle("Hi"); for(Counter=0; Counter < 80; Counter++) for(c2=0; c2 < 25; c2++) { Pos.X = Counter; Pos.Y = c2; SetConsoleCursorPosition(h, Pos); if(Counter == 10 && c2 == 13) cout << "*" << endl; else cout << " " << endl; } Pos2.X = 0; Pos2.Y = 0; SetConsoleCursorPosition(h, Pos2); grid_x = 10; grid_y = 13; for(;;) { buffer = get_arrow(); if(buffer == ESC_KEY) { clrscr(); SetConsoleTextAttribute(h, Color); exit(0); } if(buffer == DOWN_ARROW) if(grid_y == 23) cout << ""; else grid_y++; if(buffer == UP_ARROW) if(grid_y == 1) cout << ""; else grid_y--; if(buffer == LEFT_ARROW) if(grid_y == 80) cout << ""; else grid_x--; if(buffer == RIGHT_ARROW) if(grid_y == 1) cout << ""; else grid_x++; for(Counter=0; Counter < 80; Counter++) for(c2=0; c2 < 25; c2++) { Pos.X = Counter; Pos.Y = c2; SetConsoleCursorPosition(h, Pos); if(Counter == grid_x && c2 == grid_y) cout << "*" << endl; else cout << " " << endl; SetConsoleCursorPosition(h, Pos2); } } } int get_arrow() { int ch = getch(); if(ch == 0 || ch == 224) ch = 256 + getch(); return ch; }
I'm guessing I messed up somewhere simple, but I just cant find my problem.... I have looked at this four three hours, but I'm not getting anywhere, no matter what value I give it, it just lets me bring it off the screen... Any ideas?
Thank you very much in advanced!



LinkBack URL
About LinkBacks


