enum DRAW{
CMD_SHOW,
CMD_FIX,
CMD_CLEAR
};
DRAW _draw;
_draw = CMD_FIX;
switch (_draw)
{
case CMD_SHOW:
printf("CMD_SHOW\n"); break;
case CMD_FIX:
printf("CMD_FIX\n"); break;
case CMD_CLEAR:
printf("CMD_CLEAR\n"); break;
default:
break;
}
enum CMD{
CMD_UP, CMD_LEFT, CMD_RIGHT, CMD_DOWN,
CMD_SINK,
CMD_QUIT
};
CMD GetCmd()
{
if (_kbhit)
{
switch (_getch())
{
case 'w':
case 'W': return CMD_UP;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch (_getch())
{
case 72: return CMD_UP;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}
}
void DispatchCmd(CMD _cmd)
{
switch (_cmd)
{
case CMD_UP: OnUp(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_Quit: OnQuit(); break;
}
}
int main()
{
......
CMD c;
c = GetCmd();
Dispatch(c);
......
return 0;
}