Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Robot finds kitten. Because every robot wants love.
- #include <ncurses.h>
- #include <time.h>
- //Percentage of objects
- #define DENSITY 4
- int total = 24;
- char* messages[] =
- {
- " ",
- "This is duct tape, not kitten.",
- "A dirty old cum rag. Eww.",
- "It looks like kitten, sounds like kitten, tastes like kitten. It's not kitten.",
- "A Jedi Knight tells you \"This is not the kitten you are looking for\"",
- "It's Steve Ballmer. He\'s yelling \"DEVELOPERS DEVELOPERS DEVELOPERS\"",
- "Linus Torvalds, eating a BLT.",
- "Richard Stallman, coding in a housecoat.",
- "Bill Gates with a collander on his head and a razor in his hands.",
- "Steve Jobs debating putting kittens in the cloud. You feel scared.",
- "A kitten-like robot, but sadly not kitten.",
- "A stoned teen coding at a Model M. You feel like you can see your soul in his face.",
- "A wonderfully brewed cup of coffee, sadly you don't have tastebuds",
- "A bare PCB sits here beckoning to you with blinking LEDs.",
- "Shrodingers Box. You have found, and not found kitten. Huh.",
- "KITTE- Nope it's a box of shrimp",
- "The filming of 4men1mule.",
- "The shopkeep loudly proclaims \"You never go ass to mouth!\". Crazy humans.",
- "A MacBook Pro running a FOSS system. You now know what communism feels like",
- "A hacked to shit Android device. You feel strangely affectionate.",
- "A chocolate moose. Odd, it doesn't have antlers.",
- "The Lost city of atlantis.",
- "A wild Pikachu appeared!, Pika!",
- "A sticky wicket. Blimey!",
- "A blanket fort with a dog in it. Woof!",
- };
- int main() {
- //Actor positions
- int robot_x = -1,
- robot_y = -1,
- kitten_x = -1,
- kitten_y = -1;
- //Ncurses Jazz
- initscr();
- noecho();
- cbreak();
- start_color();
- keypad(stdscr, TRUE);
- //ncurses colors
- init_pair(1, COLOR_RED, COLOR_BLACK);
- init_pair(2, COLOR_BLUE, COLOR_BLACK);
- init_pair(3, COLOR_WHITE, COLOR_BLACK);
- init_pair(4, COLOR_GREEN, COLOR_BLACK);
- init_pair(5, COLOR_CYAN, COLOR_BLACK);
- //Init world
- srand(time(NULL));
- int world[COLS][LINES];
- int i, j;
- for (i = 0; i < COLS; i++) {
- for (j = 0; j < LINES; j++) {
- if (rand() % (100-DENSITY) == 0)
- world[i][j] = rand() % total;
- else
- world[i][j] = 0;
- }
- }
- //Add in our faithful heroes
- robot_x = rand() % COLS;
- robot_y = rand() % LINES;
- kitten_y = rand() % LINES;
- kitten_x = rand() % LINES;
- //Activity loop
- while (1) {
- //Parse you a input
- int key = getch();
- switch (key) {
- case KEY_UP:
- robot_y--;
- break;
- case KEY_DOWN:
- robot_y++;
- break;
- case KEY_LEFT:
- robot_x--;
- break;
- case KEY_RIGHT:
- robot_x++;
- break;
- }
- //Check for game over
- if ((robot_x == kitten_x) &&
- (robot_y == kitten_y)) break;
- //Draw the world
- for (i = 0; i < COLS; i++) {
- for (j = 0; j < LINES; j++) {
- //Unique color
- attron(COLOR_PAIR(((i+j) % 5) +1));
- mvaddch(j, i, world[i][j]+32);
- }
- }
- //Kittens!
- mvaddch(kitten_y, kitten_x, '@');
- //Robot Overlords!
- attron(A_BOLD);
- mvaddch(robot_y, robot_x, '#');
- attroff(A_BOLD);
- //Text overlays!
- mvprintw(LINES-1, 0, "%s", messages[world[robot_x][robot_y]]);
- move(LINES-1, 0);
- refresh();
- }
- //Clean the screen
- clear();
- refresh();
- endwin();
- //Victory messages
- printf("\nYou Found kitten! Congrats!\n");
- //Done!
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment