/* robots.c * ein einfaches Spiel, mit Text-Graphik realisiert ("rogue-like") * * * B.Glavina, 9.12.2005 (nur Programm-Rahmen) */ #include #include #define bool int #define false 0 #define true 1 /* unsere Welt besteht aus einem Rechteck mit */ /* Breite XRANGE und Hoehe YRANGE; links unten ist Zelle (0;0) */ #define XRANGE 50 #define YRANGE 24 /* die Welt kann (nur) folgende Objekte enthalten: */ #define EMPTY '.' #define WALL '#' #define ME '@' #define ROBOT 'R' #define JUNK 'X' void init_world(char world[XRANGE][YRANGE], int level) /* fuelle Welt mit Waenden und Robotern */ { int x, y; for (x=0; x> "); gets(commandline); command = commandline[0]; ok = false; switch (command) { case '2': /* go south */ if (world[me_x][me_y+1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y++; world[me_x][me_y] = ME; ok = true; } break; case '4': /* go west */ if (world[me_x-1][me_y]==EMPTY) { world[me_x][me_y] = EMPTY; me_x--; world[me_x][me_y] = ME; ok = true; } break; case '6': /* go east */ if (world[me_x+1][me_y]==EMPTY) { world[me_x][me_y] = EMPTY; me_x++; world[me_x][me_y] = ME; ok = true; } break; case '8': /* go north */ if (world[me_x][me_y-1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y--; world[me_x][me_y] = ME; ok = true; } break; case '7': /* go northwest */ if (world[me_x-1][me_y-1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y--; me_x--; world[me_x][me_y] = ME; ok = true; } break; case '9': /* go northeast */ if (world[me_x+1][me_y-1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y--; me_x++; world[me_x][me_y] = ME; ok = true; } break; case '1': /* go southwest */ if (world[me_x-1][me_y+1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y++; me_x--; world[me_x][me_y] = ME; ok = true; } break; case '3': /* go southeast */ if (world[me_x+1][me_y+1]==EMPTY) { world[me_x][me_y] = EMPTY; me_y++; me_x++; world[me_x][me_y] = ME; ok = true; } break; case '5': /* dont move */ world[me_x][me_y] = ME; ok = true; break; case '0': /* dont move */ //compute_random_free_cell(world[XRANGE][YRANGE], *x, *y); world[me_x][me_y] = EMPTY; ok = true; break; break; case 'h': /* Hilfe: Erklaerung moeglicher Eingaben */ printf("\n"); printf("Moegliche Eingaben sind\n"); printf("x = Spiel abbrechen\n"); printf("[12345679h ebenfalls erklaeren]\n"); printf("... usw.\n"); printf("\n"); printf("(RET druecken zum Weiterspielen)"); gets(commandline); break; case 'x': /* Abbruch */ alive = false; strcpy(msg, "Hey, is there really anything better than ROBOTS???"); break; default: break; } /* end switch */ if (ok) { move_robots(world, me_x, me_y, &number_of_robots); if (world[me_x][me_y]!=ME) { alive = false; /* player is dead */ strcpy(msg, "Sorry, loser! Have more luck next time."); } else if (number_of_robots==0) { alive = false; /* player has won */ strcpy(msg, "Wow! You are a genuine robot buster."); } } else beep(); /* invalid command */ } while (alive); show_world(world); printf("\n"); printf("%s\n", msg); printf("... exiting this exciting game ...\n"); printf("\n"); return 0; } /* end of file robots.c */