#include #include #include #include #include #include #include struct body { int x,y; body *next; }; int main() { int GraphDriver = DETECT; /* Request auto-detection */ int GraphMode; int ErrorCode; initgraph( &GraphDriver, &GraphMode, "" ); ErrorCode = graphresult(); /* Read result of initialization*/ if( ErrorCode != grOk ) /* Error occured during init */ { printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) ); exit( 1 ); } body *start; body *curr; curr = NULL; start = NULL; int dx = 10; int dy = 0; char znak = 0; start = new body; start -> x = 320; start -> y = 240; start -> next = NULL; do { if(kbhit()) { znak = getch(); switch(znak) { case 'w': dy = -10; dx = 0; break; case 's': dy = 10; dx = 0; break; case 'a': dy = 0; dx = -10; break; case 'd': dy = 0; dx = 10; break; case ' ': curr = start; while(curr -> next != NULL) { curr = curr -> next; } curr -> next = new body; //curr = curr -> next; curr -> next = NULL; break; } } start -> x += dx; start -> y += dy; delay(150); circle(start -> x,start -> y,5); do { curr = start; int tmpx, tmpy; tmpx = curr -> x; tmpy = curr -> y; }while(curr -> next != NULL); }while(znak!=27); while(!kbhit()); //czeka na naciśnięcie klawisza closegraph(); /* Return the system to text mode */ return(0); }