X-Git-Url: http://git.shiar.nl/netris.git/blobdiff_plain/d970b02f5c5800066fd484af40852b79bbf5cfc2..1e155d969ded8f4aa11411be7f60299b45a56f04:/game.c diff --git a/game.c b/game.c index 5e3f689..a5a72ad 100644 --- a/game.c +++ b/game.c @@ -52,12 +52,12 @@ static struct option options[] = { enum { KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down, - KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys + KT_faster, KT_pause, KT_redraw, KT_say, KT_quit, KT_numKeys }; static char *keyNames[KT_numKeys+1] = { "Left", "Right", "RotRight", "RotLeft", "Drop", "Down", - "Faster", "Pause", "Redraw", "Quit", NULL + "Faster", "Pause", "Redraw", "Say", "Quit", NULL }; _Sets Sets = {7, 0, 1, 1, 1}; @@ -319,8 +319,10 @@ void OneGame(void) { char *p; - if (key == 13) { - if (!(chatMode = !chatMode)) { + if (chatMode) { + if (key == 13) { + // enter text + chatMode = 0; if (chatText[0]) { Message("<\\%d%s\\7> %s", Players[me].team > 7 ? 7 : Players[me].team, @@ -331,15 +333,12 @@ void OneGame(void) } //say it else Messagetype(27, -1, NULL); //escape return; - } //leave chat mode - } //enter pressed (start/stop chat mode) - - if (chatMode) { - if (key == 27) //escape + } + else if (key == 27) //escape chatMode = 0; else if (key == 127 && chatText) //backspace chatText[strlen(chatText) - 1] = 0; - else if (key != 13 && strlen(chatText) < MSG_WIDTH-1) //text + else if (strlen(chatText) < MSG_WIDTH-1) //text chatText[strlen(chatText)] = key; Messagetype(key, strlen(chatText) - 1, chatText); return; @@ -347,8 +346,47 @@ void OneGame(void) if (!(p = strchr(keyTable, tolower(key)))) return; key = p - keyTable; - if (Players[me].alive <= 0 && key != KT_quit) return; - if (paused && key < KT_pause) return; + + // global actions (always possible, even if not playing) + switch (key) { + case KT_redraw: + clear(); + InitFields(); +// ScheduleFullRedraw(); + refresh(); + return; + case KT_say: + chatMode = 1; + Messagetype(key, strlen(chatText) - 1, chatText); + return; + case KT_quit: + ShowPause(me); + refresh(); + gameStatus = 0; + return; + } + + if (Players[me].alive <= 0) return; + // actions available while in game + switch (key) { + case KT_pause: + Players[me].flags ^= SCF_paused; + if (Game.started > 1) + Message(Players[me].flags & SCF_paused + ? "You paused the game" : "You unpaused the game"); + else + Message(Players[me].flags & SCF_paused + ? "You are not ready" : "You are ready"); + checkPaused(); + if (game == GT_classicTwo) + SendPacket(me, NP_pause, 0, NULL); + ShowPause(me); + changed = 1; + return; + } + + if (paused) return; + // actions only available while actually playing switch (key) { case KT_left: if (MovePiece(me, 0, -1) && spied) SendPacket(me, NP_left, 0, NULL); @@ -388,32 +426,8 @@ void OneGame(void) ShowScore(me, Players[me].score); changed = 1; break; - case KT_pause: - Players[me].flags ^= SCF_paused; - if (Game.started > 1) - Message(Players[me].flags & SCF_paused - ? "You paused the game" : "You unpaused the game"); - else - Message(Players[me].flags & SCF_paused - ? "You are not ready" : "You are ready"); - checkPaused(); - if (game == GT_classicTwo) - SendPacket(me, NP_pause, 0, NULL); - ShowPause(me); - changed = 1; - break; - case KT_redraw: - clear(); - InitFields(); -// ScheduleFullRedraw(); - refresh(); - break; - case KT_quit: - ShowPause(me); - refresh(); - gameStatus = 0; - break; - } //E_key + } + if (dropMode && DropPiece(me) > 0) { SetITimer(Game.speed, Game.speed); if (spied) SendPacket(me, NP_drop, 0, NULL);