2 * Netris -- A free networked version of Tetris
3 * Copyright (C) 1994,1995 Mark Weaver <Mark_Weaver@brown.edu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * $Id: curses.c,v 1.29 1995/07/11 08:53:21 mhw Exp $
23 #include <sys/types.h>
29 static void PlotBlock1(int scr, int y, int x, BlockType type);
30 static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event);
32 static EventGenRec keyGen =
33 { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key };
35 static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS];
36 static int statusYPos, statusXPos;
38 ExtFunc void InitScreens(void)
42 BlockSignals(&oldMask, SIGINT, 0);
44 AtExit(CleanupScreens);
45 RestoreSignals(NULL, &oldMask);
51 addstr(version_string);
52 addstr(" (C) 1994,1995 Mark Weaver "
53 "\"netris -h\" for more info");
58 ExtFunc void CleanupScreens(void)
60 RemoveEventGen(&keyGen);
64 ExtFunc void InitScreen(int scr)
71 boardXPos[scr] = boardXPos[scr - 1] +
72 2 * boardWidth[scr - 1] + 3;
74 if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3)
75 statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3;
76 for (y = boardVisible[scr] - 1; y >= 0; --y) {
77 move(boardYPos[scr] - y, boardXPos[scr] - 1);
79 move(boardYPos[scr] - y, boardXPos[scr] + 2 * boardWidth[scr]);
82 for (y = boardVisible[scr]; y >= -1; y -= boardVisible[scr] + 1) {
83 move(boardYPos[scr] - y, boardXPos[scr] - 1);
85 for (x = boardWidth[scr] - 1; x >= 0; --x)
91 ExtFunc void CleanupScreen(int scr)
95 static void PlotBlock1(int scr, int y, int x, BlockType type)
97 move(boardYPos[scr] - y, boardXPos[scr] + 2 * x);
121 ExtFunc void PlotBlock(int scr, int y, int x, BlockType type)
123 if (y >= 0 && y < boardVisible[scr] && x >= 0 && x < boardWidth[scr])
124 PlotBlock1(scr, y, x, type);
127 ExtFunc void PlotUnderline(int scr, int x, int flag)
129 move(boardYPos[scr] + 1, boardXPos[scr] + 2 * x);
130 addstr(flag ? "==" : "--");
133 ExtFunc void ShowDisplayInfo(void)
135 move(statusYPos - 9, statusXPos);
136 printw("Seed = %d", initSeed);
138 move(statusYPos - 8, statusXPos);
139 printw("Speed = %dms", speed / 1000);
142 move(statusYPos - 6, statusXPos);
144 addstr("Controlled by a fair robot");
146 addstr("Controlled by a robot");
149 if (opponentFlags & SCF_usingRobot) {
150 move(statusYPos - 5, statusXPos);
151 if (opponentFlags & SCF_fairRobot)
152 addstr("The opponent is a fair robot");
154 addstr("The opponent is a robot");
159 ExtFunc void UpdateOpponentDisplay(void)
162 printw("Playing %s@%s", opponentName, opponentHost);
166 ExtFunc void ShowPause(int pausedByMe, int pausedByThem)
168 move(statusYPos - 3, statusXPos);
170 addstr("Game paused by opponent");
173 move(statusYPos - 2, statusXPos);
175 addstr("Game paused by you");
180 ExtFunc void Message(char *s)
184 move(statusYPos - 20 + line, statusXPos);
185 addstr(s); /* XXX Should truncate long lines */
187 line = (line + 1) % 10;
188 move(statusYPos - 20 + line, statusXPos);
192 ExtFunc void RefreshScreen(void)
194 static char timeStr[2][32];
198 strftime(timeStr[0], 30, "%I:%M %p", localtime(&theTime));
199 /* Just in case the local curses library sucks */
200 if (strcmp(timeStr[0], timeStr[1]))
202 move(statusYPos, statusXPos);
204 strcpy(timeStr[1], timeStr[0]);
206 move(boardYPos[0] + 1, boardXPos[0] + 2 * boardWidth[0] + 1);
210 static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
212 if (MyRead(gen->fd, &event->u.key, 1))