Guest User

Untitled

a guest
Sep 26th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.54 KB | None | 0 0
  1. //Robot finds kitten. Because every robot wants love.
  2.  
  3. #include <ncurses.h>
  4. #include <time.h>
  5.  
  6. //Percentage of objects
  7. #define DENSITY 4
  8.  
  9. int total = 24;
  10. char* messages[] =
  11. {
  12.   " ",
  13.   "This is duct tape, not kitten.",
  14.   "A dirty old cum rag. Eww.",
  15.   "It looks like kitten, sounds like kitten, tastes like kitten. It's not kitten.",
  16.   "A Jedi Knight tells you \"This is not the kitten you are looking for\"",
  17.   "It's Steve Ballmer. He\'s yelling \"DEVELOPERS DEVELOPERS DEVELOPERS\"",
  18.   "Linus Torvalds, eating a BLT.",
  19.   "Richard Stallman, coding in a housecoat.",
  20.   "Bill Gates with a collander on his head and a razor in his hands.",
  21.   "Steve Jobs debating putting kittens in the cloud. You feel scared.",
  22.   "A kitten-like robot, but sadly not kitten.",
  23.   "A stoned teen coding at a Model M. You feel like you can see your soul in his face.",
  24.   "A wonderfully brewed cup of coffee, sadly you don't have tastebuds",
  25.   "A bare PCB sits here beckoning to you with blinking LEDs.",
  26.   "Shrodingers Box. You have found, and not found kitten. Huh.",
  27.   "KITTE- Nope it's a box of shrimp",
  28.   "The filming of 4men1mule.",
  29.   "The shopkeep loudly proclaims \"You never go ass to mouth!\". Crazy humans.",
  30.   "A MacBook Pro running a FOSS system. You now know what communism feels like",
  31.   "A hacked to shit Android device. You feel strangely affectionate.",
  32.   "A chocolate moose. Odd, it doesn't have antlers.",
  33.   "The Lost city of atlantis.",
  34.   "A wild Pikachu appeared!, Pika!",
  35.   "A sticky wicket. Blimey!",
  36.   "A blanket fort with a dog in it. Woof!",
  37. };
  38.  
  39. int main() {
  40.   //Actor positions
  41.   int robot_x  = -1,
  42.       robot_y  = -1,
  43.       kitten_x = -1,
  44.       kitten_y = -1;
  45.  
  46.   //Ncurses Jazz
  47.   initscr();
  48.   noecho();
  49.   cbreak();
  50.   start_color();
  51.   keypad(stdscr, TRUE);
  52.  
  53.   //ncurses colors
  54.   init_pair(1, COLOR_RED,   COLOR_BLACK);
  55.   init_pair(2, COLOR_BLUE,  COLOR_BLACK);
  56.   init_pair(3, COLOR_WHITE, COLOR_BLACK);
  57.   init_pair(4, COLOR_GREEN, COLOR_BLACK);
  58.   init_pair(5, COLOR_CYAN,  COLOR_BLACK);
  59.  
  60.   //Init world
  61.   srand(time(NULL));
  62.   int world[COLS][LINES];
  63.  
  64.   int i, j;
  65.   for (i = 0; i < COLS; i++) {
  66.     for (j = 0; j < LINES; j++) {
  67.       if (rand() % (100-DENSITY)  == 0)
  68.         world[i][j] = rand() % total;
  69.       else
  70.         world[i][j] = 0;
  71.     }
  72.   }
  73.  
  74.   //Add in our faithful heroes
  75.   robot_x  = rand() % COLS;
  76.   robot_y  = rand() % LINES;
  77.   kitten_y = rand() % LINES;
  78.   kitten_x = rand() % LINES;
  79.  
  80.   //Activity loop
  81.   while (1) {
  82.     //Parse you a input
  83.     int key = getch();
  84.     switch (key) {
  85.       case KEY_UP:
  86.         robot_y--;
  87.         break;
  88.       case KEY_DOWN:
  89.         robot_y++;
  90.         break;
  91.       case KEY_LEFT:
  92.         robot_x--;
  93.         break;
  94.       case KEY_RIGHT:
  95.         robot_x++;
  96.         break;
  97.     }
  98.    
  99.     //Check for game over
  100.     if ((robot_x == kitten_x) &&
  101.         (robot_y == kitten_y)) break;
  102.    
  103.     //Draw the world
  104.     for (i = 0; i < COLS; i++) {
  105.       for (j = 0; j < LINES; j++) {
  106.         //Unique color
  107.         attron(COLOR_PAIR(((i+j) % 5) +1));
  108.           mvaddch(j, i, world[i][j]+32);
  109.       }
  110.     }
  111.    
  112.     //Kittens!
  113.     mvaddch(kitten_y, kitten_x, '@');
  114.  
  115.     //Robot Overlords!
  116.     attron(A_BOLD);
  117.     mvaddch(robot_y, robot_x, '#');
  118.     attroff(A_BOLD);
  119.  
  120.     //Text overlays!
  121.     mvprintw(LINES-1, 0, "%s", messages[world[robot_x][robot_y]]);
  122.     move(LINES-1, 0);
  123.  
  124.     refresh();
  125.   }
  126.  
  127.   //Clean the screen
  128.   clear();
  129.   refresh();
  130.   endwin();
  131.  
  132.   //Victory messages
  133.   printf("\nYou Found kitten! Congrats!\n");
  134.  
  135.   //Done!
  136.   return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment