X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=curses.c;h=dc708bd4b4ce5f03d1c6dc0cb8a389c78e348cc5;hb=refs%2Ftags%2Fdebian%2F0.52-6;hp=047efa4bc496de98ca707516db7cc60d53fb8c07;hpb=89d91b6cfd98e514b3e418526ba854d00beb876c;p=pkg%2Fnetris.git diff --git a/curses.c b/curses.c index 047efa4..dc708bd 100644 --- a/curses.c +++ b/curses.c @@ -1,6 +1,6 @@ /* * Netris -- A free networked version of T*tris - * Copyright (C) 1994,1995,1996 Mark H. Weaver + * Copyright (C) 1994-1996,1999 Mark H. Weaver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,16 +16,40 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: curses.c,v 1.32 1996/02/09 08:47:25 mhw Exp $ + * $Id: curses.c,v 1.33 1999/05/16 06:56:25 mhw Exp $ */ #include "netris.h" +#include #include #include +#include #include #include #include +#ifdef NCURSES_VERSION +# define HAVE_NCURSES +#endif + +#ifdef HAVE_NCURSES +static struct +{ + BlockType type; + short color; +} myColorTable[] = +{ + { BT_white, COLOR_WHITE }, + { BT_blue, COLOR_BLUE }, + { BT_magenta, COLOR_MAGENTA }, + { BT_cyan, COLOR_CYAN }, + { BT_yellow, COLOR_YELLOW }, + { BT_green, COLOR_GREEN }, + { BT_red, COLOR_RED }, + { BT_none, 0 } +}; +#endif + static void PlotBlock1(int scr, int y, int x, BlockType type); static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event); @@ -34,6 +58,8 @@ static EventGenRec keyGen = static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS]; static int statusYPos, statusXPos; +static int haveColor; +static int screens_dirty = 0; static char *term_vi; /* String to make cursor invisible */ static char *term_ve; /* String to make cursor visible */ @@ -45,12 +71,37 @@ ExtFunc void InitScreens(void) GetTermcapInfo(); /* - * Do this atomically. Otherwise a badly timed Ctrl-C during - * initialization will leave your terminal in a bad state. + * Block signals while initializing curses. Otherwise a badly timed + * Ctrl-C during initialization might leave the terminal in a bad state. */ BlockSignals(&oldMask, SIGINT, 0); initscr(); + +#ifdef CURSES_HACK + { + extern char *CS; + + CS = 0; + } +#endif + +#ifdef HAVE_NCURSES + haveColor = colorEnable && has_colors(); + if (haveColor) + { + int i = 0; + + start_color(); + for (i = 0; myColorTable[i].type != BT_none; ++i) + init_pair(myColorTable[i].type, COLOR_BLACK, + myColorTable[i].color); + } +#else + haveColor = 0; +#endif + AtExit(CleanupScreens); + screens_dirty = 1; RestoreSignals(NULL, &oldMask); cbreak(); @@ -61,7 +112,7 @@ ExtFunc void InitScreens(void) move(0, 0); addstr("Netris "); addstr(version_string); - addstr(" (C) 1994,1995,1996 Mark H. Weaver " + addstr(" (C) 1994-1996,1999 Mark H. Weaver " "\"netris -h\" for more info"); statusYPos = 22; statusXPos = 0; @@ -69,9 +120,12 @@ ExtFunc void InitScreens(void) ExtFunc void CleanupScreens(void) { - RemoveEventGen(&keyGen); - endwin(); - OutputTermStr(term_ve, 1); + if (screens_dirty) { + RemoveEventGen(&keyGen); + endwin(); + OutputTermStr(term_ve, 1); + screens_dirty = 0; + } } ExtFunc void GetTermcapInfo(void) @@ -154,6 +208,8 @@ ExtFunc void InitScreen(int scr) for (y = boardVisible[scr] - 1; y >= 0; --y) { move(boardYPos[scr] - y, boardXPos[scr] - 1); addch('|'); + for (x = boardWidth[scr] - 1; x >= 0; --x) + addstr(" "); move(boardYPos[scr] - y, boardXPos[scr] + 2 * boardWidth[scr]); addch('|'); } @@ -172,27 +228,26 @@ ExtFunc void CleanupScreen(int scr) static void PlotBlock1(int scr, int y, int x, BlockType type) { + int colorIndex = abs(type); + move(boardYPos[scr] - y, boardXPos[scr] + 2 * x); - switch (type) { - case BT_none: - addstr(" "); - break; - case -BT_piece1: - if (standoutEnable) - standout(); - addstr("$$"); - if (standoutEnable) - standend(); - break; - case BT_piece1: - if (standoutEnable) + + if (type == BT_none) + addstr(" "); + else + { + if (standoutEnable) + { +#ifdef HAVE_NCURSES + if (haveColor) + attrset(COLOR_PAIR(colorIndex)); + else +#endif standout(); - addstr("[]"); - if (standoutEnable) - standend(); - break; - default: - assert(0); + } + + addstr(type > 0 ? "[]" : "$$"); + standend(); } } @@ -210,6 +265,29 @@ ExtFunc void PlotUnderline(int scr, int x, int flag) ExtFunc void ShowDisplayInfo(void) { + if (game == GT_classicTwo) { + move(statusYPos - 5, statusXPos); + printw("Enemy lines: %3d/%4d", enemyLinesCleared, enemyTotalLinesCleared); + } + move(statusYPos - 4, statusXPos); + printw("My lines: %3d/%4d", myLinesCleared, myTotalLinesCleared); + move(statusYPos - 3, statusXPos); + printw("Won: %3d", won); + move(statusYPos - 2, statusXPos); + printw("Lost: %3d", lost); + + move(statusYPos - 1, statusXPos); + switch(gameState) { + case STATE_WAIT_CONNECTION: + addstr("Waiting for opponent... "); + break; + case STATE_WAIT_KEYPRESS: + addstr("Press the key for a new game."); + break; + default: + addstr(" "); + } + move(statusYPos - 9, statusXPos); printw("Seed: %d", initSeed); clrtoeol(); @@ -217,7 +295,7 @@ ExtFunc void ShowDisplayInfo(void) printw("Speed: %dms", speed / 1000); clrtoeol(); if (robotEnable) { - move(statusYPos - 6, statusXPos); + move(statusYPos - 7, statusXPos); if (fairRobot) addstr("Controlled by a fair robot"); else @@ -225,7 +303,7 @@ ExtFunc void ShowDisplayInfo(void) clrtoeol(); } if (opponentFlags & SCF_usingRobot) { - move(statusYPos - 5, statusXPos); + move(statusYPos - 6, statusXPos); if (opponentFlags & SCF_fairRobot) addstr("The opponent is a fair robot"); else