Probleme mit mein "Test-Spiel"
-
Hallo - ich versuche mal auf C++ basis nen Spiel zu schreiben ,
leider habe ich gerade folgendes problem:ich will das mein Smily eine position nach X geht
#include <cstdlib> #include <iostream> #include <windows.h> using namespace std; void gotoxy(int x, int y) { COORD pos={x,y}; HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOuput,pos); } void Player(); int main() { Player(); return 0; } void Player() { int x ; int y ; x = 20; y = 8; gotoxy(x,y); cout<<"O"; Sleep(1000); x++; gotoxy(x,y); Player(); }
Wie bekomme ich das hin , das der Player nicht immer wieder bei der selben position anfängt ????
-
Egal - Problem gelöst ^^
#include <cstdlib> #include <iostream> #include <windows.h> using namespace std; void Player(); void gotoxy(int x,int y); int main() { gotoxy(20,8); Player(); return 0; } void Player() { int x; int y; gotoxy(x,y); cout<<"x"; Sleep(1000); x++; gotoxy(x,y); Player(); } void gotoxy(int x, int y) { COORD pos={x,y}; HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOuput,pos); }
-
egal. z.b. so:
const char player = 'O'; const char blank = ' '; const int wait = 1000; HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE); void gotoxy (int x, int y) { COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(hOuput,pos); } void set_player( int x, int y ) { gotoxy(x,y); cout << player; } void clear_player ( int x, int y ) { gotoxy (x, y); cout << blank; } void ShowConsoleCursor( bool show ) { CONSOLE_CURSOR_INFO ci = {0}; GetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &ci ); ci.bVisible = show; SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &ci ); } int main() { int x = 10, y = 20, stepx = 1, stepy = -1; ShowConsoleCursor (false); while (1) { set_player ( x, y ); Sleep(100); clear_player ( x, y ); x += stepx; y += stepy; if ( y < 0 ) y = 24; if ( x > 79 ) x = 0; } return 0; }