Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <time.h>
- int main(void)
- {
- int i, j;
- struct { char *name; int num, min, max; } invs[2][4] =
- {{{ "", -1, -1, -1 },
- { "HANDFUL OF PARENTHESES", 10, 5, 5 },
- { "HARDCOVER COPY OF SICP", 5, 15, 15 },
- { "SICP VIDEO LECTURES ON YOUR IPOD", 20, 5, 25 }},
- {{ "UNINDENTED JAVASCRIPT", 30, 5, 5 },
- { "EARNEST DEFENSE OF SEPPLES", 5, 10, 5 },
- { "EXPERT WEB DEVELOPMENT SOLUTION", 3, 8, 40 }}};
- int hps[2] = { 100, 100 };
- char *faces[2][4][10] =
- {{{ "_ ___.....___ ",
- " `.__ ,-' ,-.`-, ",
- " `''-------' ( p ) `._ ",
- " `-' ( ",
- " \\ ",
- " . \\ ",
- " \\---..,--' ",
- "................._ --...--, ",
- " `-.._ _.-' ",
- " `'-----'' " },
- { "_ ___.....___ ",
- " `.__ ,-' ,-.`-, ",
- " `''-------' ( p ) `._ ",
- " `-' ( ",
- " \\ ",
- " \\ ",
- " .---..,--' ",
- "................._ |--...--, ",
- " `-.._ _.-' ",
- " `'-----'' " },
- { "_ ___.....___ ",
- " `.__ ,-' .-' \\ ",
- " `''-------' / o ) `._ ",
- " `-' ( ",
- " \\ ",
- " \\",
- " ______)",
- "................._ .-'' / ",
- " `-.._ _.-' ",
- " `'-----'' " },
- { "_ ___.....___ ",
- " `.__ ,-' ,-.`-, ",
- " `''-------' ( x ) `._ ",
- " `-' ( ",
- " \\ ",
- " \\ ",
- " ---..,--' ",
- "................._ /--...--, ",
- " `-.._ ` _.-' ",
- " `'-----'' " }},
- {{ " ",
- " /-------._ ",
- " .´ ''-. ",
- " .´ .-. +----------",
- " .´ ( o ) ",
- " / '-´ / ",
- ": .------´ ",
- "+------´ .--------",
- " '---------------------´ ",
- " " },
- { " ",
- " /-------._ ",
- " .´ ''-. ",
- " .´ .-. +----------",
- " .´ ( o ) ",
- " / '-´ ",
- ": .------ ",
- "+------´ .--------",
- " '---------------------´ ",
- " " },
- { " ",
- " /-------._ ",
- " .´ ''-. ",
- " .´ .-. +----------",
- " .´ ( o ) ",
- " / '-´ ",
- ": ",
- "+------ .--------",
- " '---------------------´ ",
- " " },
- { " ",
- " /-------._ ",
- " .´ ''-. ",
- " .´ .-. +----------",
- " .´ ( X ) ",
- " / '-´ ",
- ": ",
- "+------ .--------",
- " '---------------------´ ",
- " " }}};
- srand((unsigned int)time(NULL));
- for (;;) {
- int acted = 0;
- char action;
- printf("\033[2J\033[0;0H\n"
- " "
- "PROGSNAKE FITE\n\n");
- for (i = 0; i < 10; ++i)
- printf("%s %s\n", faces[0][3 - (hps[0] + 32) * 3 / 100][i],
- faces[1][3 - (hps[1] + 32) * 3 / 100][i]);
- printf("\n");
- switch (rand() % 2) {
- case 0:
- if (rand() % 100 > 40) {
- j = rand() % 16 + 8;
- printf("Opponent attacks, and hits you for %d HP!\n", j);
- hps[0] -= j;
- } else
- printf("Opponent attacks, but misses!\n");
- break;
- case 1:
- i = rand() % 3;
- if (invs[1][i].num == 0) {
- printf("Opponent wanted to use %s, but doesn't have any!\n",
- invs[1][i].name);
- } else {
- j = rand() % invs[1][i].max + invs[1][i].min;
- printf("Opponent uses %s! You lose %d HP!\n",
- invs[1][i].name, j);
- hps[0] -= j;
- --invs[1][i].num;
- }
- break;
- }
- sleep(1);
- if (hps[0] <= 0) break;
- printf("\nYou have %d HP. Your opponent has %d HP.\n", hps[0], hps[1]);
- do {
- printf("\nWhat do? [F]ight, [I]tem, [A]bility, [R]un: ");
- action = (char)getchar();
- action &= 0xdf;
- while (getchar() != 10);
- printf("\n");
- switch (action) {
- case 'F':
- if (rand() % 100 > 40) {
- j = rand() % 16 + 10;
- printf("You attack, dealing %d damage!\n", j);
- hps[1] -= j;
- } else
- printf("You try to attack, but miss!\n");
- acted = 1;
- break;
- case 'I':
- printf("Inventory:\n");
- for (i = 1; i < 4; ++i) {
- printf("\t%d. %35s (%d)\n", i, invs[0][i].name,
- invs[0][i].num);
- }
- printf("\nWhich will you use? [1-3] ");
- do {
- action = (char)getchar();
- } while (action < 48 || action > 57);
- while (getchar() != 10);
- i = action - 48;
- switch (i) {
- case 1:
- case 2:
- case 3:
- if (invs[0][i].num > 0) {
- j = rand() % invs[0][i].max + invs[0][i].min;
- printf("\nYou use %s! ", invs[0][i].name);
- if (i == 3) {
- printf("You gain %d HP!\n", j);
- hps[0] += j;
- } else {
- printf("Opponent loses %d HP!\n", j);
- hps[1] -= j;
- }
- --invs[0][i].num;
- } else
- printf("\nYou try to use %s, but don't have any!\n",
- invs[0][i].name);
- acted = 1;
- break;
- default:
- break;
- }
- break;
- case 'A':
- printf("You have not yet reached Satori, so you do not "
- "have any special abilities!\n");
- break;
- case 'R':
- printf("Real men don't back down!\n");
- break;
- default:
- printf("I don't understand that.\n");
- }
- } while (!acted);
- sleep(2);
- if (hps[1] <= 0) break;
- }
- printf("\033[2J\033[0;0H\n\t\t\t\tGAME OVER\n\n");
- for (i = 0; i < 10; ++i)
- printf("\t\t\t%s\n", faces[hps[0] > 0 ? 1 : 0][3][i]);
- printf(hps[0] > 0 ? "\n\t\t\tYou have defeated your opponent!\n\n"
- : "\n\t\t\tYou have been defeated.\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment