Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <conio.h>
- #define SIZEA 40
- #define SIZEB 108
- char c;
- void cursorposition(int x, int y)
- {
- ::HANDLE hConsoleOut =::GetStdHandle( STDOUTPUTHANDLE );
- ::CONSOLECURSORINFO hCCI;
- ::GetConsoleCursorInfo( hConsoleOut, & hCCI );
- hCCI.bVisible = FALSE;
- ::SetConsoleCursorInfo( hConsoleOut, & hCCI );
- HANDLE h = GetStdHandle(STDOUTPUTHANDLE);
- WORD wOldColorAttrs;
- SetConsoleTextAttribute(h, BACKGROUNDBLUE | FOREGROUNDINTENSITY);
- int i = 0;
- int j = 0;
- for (j = 8; j<SIZE_A-8; j++)
- {
- for (i = 8; i<SIZE_B-8; i++)
- {
- COORD pos;
- pos.X = i;
- pos.Y = j;
- SetConsoleCursorPosition(h, pos);
- printf(" ");
- }
- }
- CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
- SetConsoleTextAttribute(h, wOldColorAttrs);
- SetConsoleTextAttribute(h, BACKGROUND_GREEN | FOREGROUND_BLUE);
- COORD pos;
- pos.X = x;
- pos.Y = y;
- SetConsoleCursorPosition(h, pos);
- printf(" ");
- }
- void direction (char c)
- {
- int x=SIZEB/2, y=SIZEA/2;
- cursorposition(x, y);
- while (1)
- {
- if (_kbhit())
- c = getch();
- switch (c)
- {
- case 'w': y--;
- break;
- case 's': y++;
- break;
- case 'a': x--;
- break;
- case 'd': x++;
- break;
- case ' ': x=SIZE_B/2, y=SIZE_A/2;
- break;
- }
- int xold=x,yold=y;
- if (xold>=SIZE_B-8) x = 8;
- else if (xold<=8) x=SIZE_B-9;
- if (yold>=SIZE_A-8) y = 8;
- else if (yold<=8) y=SIZE_A-9;
- cursorposition(x, y);
- }
- }
- int main()
- {
- printf("\n\n\n\n\nW: UP S: DOWN A: LEFT D: RIGHT");
- char c;
- if (_kbhit())
- c = getch();
- direction(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement