#include #include #include #include #include #include static struct videoconfig video_config; void main (int argc, char *argv[]) { if (argc == 1) { printf("Usage: turtle \n" "\n = { R | L | M | T }*\n"); return; } if (!_setvideomode(_MAXRESMODE)) { printf("No videomode\n"); return; } _getvideoconfig(&video_config); #define MAX_X video_config.numxpixels #define MAX_Y video_config.numypixels { int x = MAX_X / 2, y = MAX_Y / 2, d = 0; int len; len = strlen(argv[1]); if (video_config.numcolors < len) { len = video_config.numcolors; argv[1][len] = '\0'; } if (argc > 2) printf("%s", argv[1]); while (!kbhit()) { int p = _getpixel(x,y); switch(argv[1][p]) { case 'R' : case 'r' : d = (d + 3) % 4; break; case 'L' : case 'l' : d = (d + 1) % 4; break; case 'T' : case 't' : d = (d + 2) % 4; break; } _setcolor((p + 1) % len); _setpixel(x,y); switch (d) { case 0: x++; if (x >= MAX_X) x -= MAX_X; break; case 1: y++; if (y >= MAX_Y) y -= MAX_X; break; case 2: x--; if (x < 0) x += MAX_X; break; case 3: y--; if (y < 0) y += MAX_X; break; } } } }