Advertisement
Manhydra

Asterisk Man

Jun 11th, 2013
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | None | 0 0
  1. /*
  2.  *      asteriskman.c
  3.  *
  4.  *      Copyright 2013 Marc Sylvestre <marc.sylvestre@manhydra.com>
  5.  *
  6.  *      This program is free software; you can redistribute it and/or modify
  7.  *      it under the terms of the GNU General Public License as published by
  8.  *      the Free Software Foundation; either version 3 of the License, or
  9.  *      (at your option) any later version.
  10.  *
  11.  *      This program is distributed in the hope that it will be useful,
  12.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *      GNU General Public License for more details.
  15.  *
  16.  *      You should have received a copy of the GNU General Public License
  17.  *      along with this program; if not, see <http://www.gnu.org/licenses/>,
  18.  *      or if prefer good old fashion postal mail, write to the Free Software
  19.  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20.  *      MA 02110-1301, USA.
  21.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <curses.h>
  27.  
  28. #define KEYUP    0x03
  29. #define KEYDOWN  0x02
  30. #define KEYLEFT  0x04
  31. #define KEYRIGHT 0x05
  32.  
  33. int main(void) {
  34.     char key_pressed;
  35.     int x = 10, y = 10;
  36.  
  37.     initscr();
  38.     intrflush(stdscr, FALSE);
  39.     keypad(stdscr, TRUE);
  40.     curs_set(0);
  41.     nonl();
  42.     noecho();
  43.     cbreak();
  44.     nodelay(stdscr, TRUE);
  45.  
  46.     mvprintw(1, 1, "!! Adventures of Asterisk Man !!");
  47.     mvprintw(2, 1, "Your mission is to move Asterisk Man as much as you can. Danger could be lurking in the dark! :O");
  48.     mvprintw(3, 1, "=======================================================================================================================");
  49.  
  50.     while (1) {
  51.         mvprintw(x, y, "*");
  52.         key_pressed = getch();
  53.         if (key_pressed != ERR && tolower(key_pressed) == 'q') break;
  54.         if (key_pressed != ERR) {
  55.             if (tolower(key_pressed) == 'q') break;
  56.             switch (tolower(key_pressed)) {
  57.                 case KEYLEFT:
  58.                 case 'h':
  59.                     mvprintw(x, y, " ");
  60.                     if (y) y--;
  61.                     mvprintw(x, y, "*");
  62.                 break;
  63.                 case KEYRIGHT:
  64.                 case 'l':
  65.                     mvprintw(x, y, " ");
  66.                     mvprintw(x, ++y, "*");
  67.                 break;
  68.                 case KEYUP:
  69.                 case 'k':
  70.                     mvprintw(x, y, " ");
  71.                     if (x > 4) x--;
  72.                     mvprintw(x, y, "*");
  73.                 break;
  74.                 case KEYDOWN:
  75.                 case 'j':
  76.                     mvprintw(x, y, " ");
  77.                     mvprintw(++x, y, "*");
  78.                 break;
  79.             }
  80.         }
  81.         refresh();
  82.         usleep(1000L);
  83.     }
  84.  
  85.     endwin();
  86.     curs_set(1);
  87.     exit(EXIT_SUCCESS);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement