SAI ||
Sommersemester 1997 ||
Systemnahe Software II ||
Übungen
<- Alle Module
Lösung zu Blatt 3 (Aufgabe 3): gbuser.h + gbuser.c
Einlesen von Benutzerkommandos.
/*
* gbuser.h - Headerfile for Gobang keyboard interface.
*/
typedef enum {
GBU_QUIT, /* quit game */
GBU_LEFT, GBU_DOWN, GBU_UP, GBU_RIGHT, /* cursor motion */
GBU_REDRAW, /* redraw screen */
GBU_MOVE, /* make a move */
GBU_PASS, /* make a pass */
GBU_ERASE } Command; /* erase a stone */
/*
* Read a command from stdin.
*/
Command gb_getcommand(void);
/*
* gbuser.c - Gobang keyboard interface.
*/
#include <curses.h>
#include "gbuser.h"
/*
* Read a command from stdin.
*/
Command gb_getcommand(void)
{
int ch;
for (;;) {
switch ( (ch = getch()) ) {
case 'q':
case ERR:
return GBU_QUIT;
case 'h':
case KEY_LEFT:
return GBU_LEFT;
case 'j':
case KEY_DOWN:
return GBU_DOWN;
case 'k':
case KEY_UP:
return GBU_UP;
case 'l':
case KEY_RIGHT:
return GBU_RIGHT;
case 'r':
case '\f':
return GBU_REDRAW;
case 's':
case '\n':
case KEY_ENTER:
return GBU_MOVE;
case 'p':
case ' ':
return GBU_PASS;
case 'x':
case KEY_BACKSPACE:
return GBU_ERASE;
default:
(void) flash();
}
}
/* NOTREACHED */
}
<- Alle Module
SAI ||
Sommersemester 1997 ||
Systemnahe Software II ||
Übungen
Martin Hasch, Mai 1997