Guest User

Untitled

a guest
Feb 12th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5.  
  6. int main(void)
  7. {
  8.     int i, j;
  9.  
  10.     struct { char *name; int num, min, max; } invs[2][4] =
  11.     {{{ "",                                 -1, -1, -1 },
  12.          { "HANDFUL OF PARENTHESES",           10,  5,  5 },
  13.          { "HARDCOVER COPY OF SICP",            5, 15, 15 },
  14.          { "SICP VIDEO LECTURES ON YOUR IPOD", 20,  5, 25 }},
  15.     {{ "UNINDENTED JAVASCRIPT",            30,  5,  5 },
  16.         { "EARNEST DEFENSE OF SEPPLES",        5, 10,  5 },
  17.         { "EXPERT WEB DEVELOPMENT SOLUTION",   3,  8, 40 }}};
  18.  
  19.     int hps[2] = { 100, 100 };
  20.     char *faces[2][4][10] =
  21.     {{{ "_                  ___.....___         ",
  22.           " `.__           ,-'        ,-.`-,      ",
  23.           "     `''-------'          ( p )  `._   ",
  24.           "                           `-'      (  ",
  25.           "                                     \\ ",
  26.           "                           .         \\ ",
  27.           "                            \\---..,--' ",
  28.           "................._           --...--,  ",
  29.           "                  `-.._         _.-'   ",
  30.           "                       `'-----''       " },
  31.     { "_                  ___.....___         ",
  32.         " `.__           ,-'        ,-.`-,      ",
  33.         "     `''-------'          ( p )  `._   ",
  34.         "                           `-'      (  ",
  35.         "                                     \\ ",
  36.         "                                     \\ ",
  37.         "                            .---..,--' ",
  38.         "................._          |--...--,  ",
  39.         "                  `-.._         _.-'   ",
  40.         "                       `'-----''       " },
  41.     { "_                  ___.....___         ",
  42.         " `.__           ,-'        .-'  \\      ",
  43.         "     `''-------'          / o )  `._   ",
  44.         "                           `-'      (  ",
  45.         "                                     \\ ",
  46.         "                                      \\",
  47.         "                                ______)",
  48.         "................._          .-''    /  ",
  49.         "                  `-.._         _.-'   ",
  50.         "                       `'-----''       " },
  51.     { "_                  ___.....___         ",
  52.         " `.__           ,-'        ,-.`-,      ",
  53.         "     `''-------'          ( x )  `._   ",
  54.         "                           `-'      (  ",
  55.         "                                     \\ ",
  56.         "                                     \\ ",
  57.         "                             ---..,--' ",
  58.         "................._          /--...--,  ",
  59.         "                  `-.._    `    _.-'   ",
  60.         "                       `'-----''       " }},
  61.     {{ "                                 ",
  62.          "        /-------._               ",
  63.          "      .´          ''-.           ",
  64.          "    .´   .-.          +----------",
  65.          "  .´    ( o )                    ",
  66.          " /       '-´    /                ",
  67.          ":       .------´                 ",
  68.          "+------´                .--------",
  69.          " '---------------------´         ",
  70.          "                                 " },
  71.     { "                                 ",
  72.         "        /-------._               ",
  73.         "      .´          ''-.           ",
  74.         "    .´   .-.          +----------",
  75.         "  .´    ( o )                    ",
  76.         " /       '-´                     ",
  77.         ":       .------                  ",
  78.         "+------´                .--------",
  79.         " '---------------------´         ",
  80.         "                                 " },
  81.     { "                                 ",
  82.         "        /-------._               ",
  83.         "      .´          ''-.           ",
  84.         "    .´   .-.          +----------",
  85.         "  .´    ( o )                    ",
  86.         " /       '-´                     ",
  87.         ":                                ",
  88.         "+------                 .--------",
  89.         " '---------------------´         ",
  90.         "                                 " },
  91.     { "                                 ",
  92.         "        /-------._               ",
  93.         "      .´          ''-.           ",
  94.         "    .´   .-.          +----------",
  95.         "  .´    ( X )                    ",
  96.         " /       '-´                     ",
  97.         ":                                ",
  98.         "+------                 .--------",
  99.         " '---------------------´         ",
  100.         "                                 " }}};
  101.  
  102.     srand((unsigned int)time(NULL));
  103.  
  104.     for (;;) {
  105.         int acted = 0;
  106.         char action;
  107.  
  108.         printf("\033[2J\033[0;0H\n"
  109.                 "                                 "
  110.                 "PROGSNAKE FITE\n\n");
  111.  
  112.         for (i = 0; i < 10; ++i)
  113.             printf("%s        %s\n", faces[0][3 - (hps[0] + 32) * 3 / 100][i],
  114.                     faces[1][3 - (hps[1] + 32) * 3 / 100][i]);
  115.         printf("\n");
  116.  
  117.         switch (rand() % 2) {
  118.             case 0:
  119.                 if (rand() % 100 > 40) {
  120.                     j = rand() % 16 + 8;
  121.  
  122.                     printf("Opponent attacks, and hits you for %d HP!\n", j);
  123.                     hps[0] -= j;
  124.  
  125.                 } else
  126.                     printf("Opponent attacks, but misses!\n");
  127.  
  128.                 break;
  129.  
  130.             case 1:
  131.                 i = rand() % 3;
  132.  
  133.                 if (invs[1][i].num == 0) {
  134.                     printf("Opponent wanted to use %s, but doesn't have any!\n",
  135.                             invs[1][i].name);
  136.  
  137.                 } else {
  138.                     j = rand() % invs[1][i].max + invs[1][i].min;
  139.  
  140.                     printf("Opponent uses %s! You lose %d HP!\n",
  141.                             invs[1][i].name, j);
  142.                     hps[0] -= j;
  143.                     --invs[1][i].num;
  144.  
  145.                 }
  146.  
  147.                 break;
  148.         }
  149.  
  150.         sleep(1);
  151.         if (hps[0] <= 0) break;
  152.  
  153.         printf("\nYou have %d HP. Your opponent has %d HP.\n", hps[0], hps[1]);
  154.  
  155.         do {
  156.             printf("\nWhat do? [F]ight, [I]tem, [A]bility, [R]un: ");
  157.  
  158.             action = (char)getchar();
  159.             action &= 0xdf;
  160.  
  161.             while (getchar() != 10);
  162.  
  163.             printf("\n");
  164.  
  165.             switch (action) {
  166.                 case 'F':
  167.                     if (rand() % 100 > 40) {
  168.                         j = rand() % 16 + 10;
  169.                         printf("You attack, dealing %d damage!\n", j);
  170.                         hps[1] -= j;
  171.  
  172.                     } else
  173.                         printf("You try to attack, but miss!\n");
  174.  
  175.                     acted = 1;
  176.                     break;
  177.  
  178.                 case 'I':
  179.                     printf("Inventory:\n");
  180.  
  181.                     for (i = 1; i < 4; ++i) {
  182.                         printf("\t%d. %35s (%d)\n", i, invs[0][i].name,
  183.                                 invs[0][i].num);
  184.                     }
  185.  
  186.                     printf("\nWhich will you use? [1-3] ");
  187.  
  188.                     do {
  189.                         action = (char)getchar();
  190.                     } while (action < 48 || action > 57);
  191.  
  192.                     while (getchar() != 10);
  193.  
  194.                     i = action - 48;
  195.  
  196.                     switch (i) {
  197.                         case 1:
  198.                         case 2:
  199.                         case 3:
  200.                             if (invs[0][i].num > 0) {
  201.                                 j = rand() % invs[0][i].max + invs[0][i].min;
  202.  
  203.                                 printf("\nYou use %s! ", invs[0][i].name);
  204.  
  205.                                 if (i == 3) {
  206.                                     printf("You gain %d HP!\n", j);
  207.                                     hps[0] += j;
  208.                                 } else {
  209.                                     printf("Opponent loses %d HP!\n", j);
  210.                                     hps[1] -= j;
  211.                                 }
  212.  
  213.                                 --invs[0][i].num;
  214.  
  215.                             } else
  216.                                 printf("\nYou try to use %s, but don't have any!\n",
  217.                                         invs[0][i].name);
  218.  
  219.                             acted = 1;
  220.                             break;
  221.  
  222.                         default:
  223.                             break;
  224.                     }
  225.                     break;
  226.  
  227.                 case 'A':
  228.                     printf("You have not yet reached Satori, so you do not "
  229.                             "have any special abilities!\n");
  230.                     break;
  231.  
  232.                 case 'R':
  233.                     printf("Real men don't back down!\n");
  234.                     break;
  235.  
  236.                 default:
  237.                     printf("I don't understand that.\n");
  238.             }
  239.  
  240.         } while (!acted);
  241.  
  242.         sleep(2);
  243.         if (hps[1] <= 0) break;
  244.  
  245.     }
  246.  
  247.     printf("\033[2J\033[0;0H\n\t\t\t\tGAME OVER\n\n");
  248.  
  249.     for (i = 0; i < 10; ++i)
  250.         printf("\t\t\t%s\n", faces[hps[0] > 0 ? 1 : 0][3][i]);
  251.  
  252.     printf(hps[0] > 0 ? "\n\t\t\tYou have defeated your opponent!\n\n"
  253.             : "\n\t\t\tYou have been defeated.\n\n");
  254.  
  255.     return 0;
  256. }
Advertisement
Add Comment
Please, Sign In to add comment