Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * asteriskman.c
- *
- * Copyright 2013 Marc Sylvestre <marc.sylvestre@manhydra.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>,
- * or if prefer good old fashion postal mail, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <curses.h>
- #define KEYUP 0x03
- #define KEYDOWN 0x02
- #define KEYLEFT 0x04
- #define KEYRIGHT 0x05
- int main(void) {
- char key_pressed;
- int x = 10, y = 10;
- initscr();
- intrflush(stdscr, FALSE);
- keypad(stdscr, TRUE);
- curs_set(0);
- nonl();
- noecho();
- cbreak();
- nodelay(stdscr, TRUE);
- mvprintw(1, 1, "!! Adventures of Asterisk Man !!");
- mvprintw(2, 1, "Your mission is to move Asterisk Man as much as you can. Danger could be lurking in the dark! :O");
- mvprintw(3, 1, "=======================================================================================================================");
- while (1) {
- mvprintw(x, y, "*");
- key_pressed = getch();
- if (key_pressed != ERR && tolower(key_pressed) == 'q') break;
- if (key_pressed != ERR) {
- if (tolower(key_pressed) == 'q') break;
- switch (tolower(key_pressed)) {
- case KEYLEFT:
- case 'h':
- mvprintw(x, y, " ");
- if (y) y--;
- mvprintw(x, y, "*");
- break;
- case KEYRIGHT:
- case 'l':
- mvprintw(x, y, " ");
- mvprintw(x, ++y, "*");
- break;
- case KEYUP:
- case 'k':
- mvprintw(x, y, " ");
- if (x > 4) x--;
- mvprintw(x, y, "*");
- break;
- case KEYDOWN:
- case 'j':
- mvprintw(x, y, " ");
- mvprintw(++x, y, "*");
- break;
- }
- }
- refresh();
- usleep(1000L);
- }
- endwin();
- curs_set(1);
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement