#endif
#ifdef HAVE_NCURSES
-static struct
-{
+static struct {
BlockType type;
short color;
-} myColorTable[] =
-{
+} myColorTable[] = {
{ BT_white, COLOR_WHITE },
{ BT_blue, COLOR_BLUE },
{ BT_magenta, COLOR_MAGENTA },
{ BT_yellow, COLOR_YELLOW },
{ BT_green, COLOR_GREEN },
{ BT_red, COLOR_RED },
- { BT_none, 0 }
+ { BT_none, 0 }
};
#endif
}
statusYPos = 22;
statusXPos = 0;
-}
+} //InitScreens
ExtFunc void CleanupScreens(void)
{
RemoveEventGen(&keyGen);
endwin();
OutputTermStr(term_ve, 1);
-}
+} //CleanupScreens
ExtFunc void GetTermcapInfo(void)
{
}
if (!term_vi || !term_ve)
term_vi = term_ve = NULL;
-}
+} //GetTermcapInfo
ExtFunc void OutputTermStr(char *str, int flush)
{
if (str) {
fputs(str, stdout);
- if (flush)
- fflush(stdout);
+ if (flush) fflush(stdout);
}
-}
+} //OutputTermStr
ExtFunc void DrawField(int scr)
-{
+{ //drow field for player scr
{
int y, x;
+ getmaxyx(stdscr, y, x);
+ if (x < boardXPos[scr] + 2 * Players[scr].boardWidth + 1) {
+ Players[scr].spy = 0;
+ return;
+ }
+
for (y = Players[scr].boardVisible - 1; y >= 0; --y) {
mvaddch(boardYPos[scr] - y, boardXPos[scr] - 1,
Game.ascii ? '|' : ACS_VLINE); //left
{
char userstr[300];
- sprintf(userstr, "%s <%s>", Players[scr].name, Players[scr].host);
+ if (Players[scr].host && Players[scr].host[0])
+ sprintf(userstr, "%s <%s>", Players[scr].name, Players[scr].host);
+ else sprintf(userstr, "%s", Players[scr].name);
userstr[20 - 7*((Players[scr].flags & SCF_usingRobot) != 0)
- 5*((Players[scr].flags & SCF_fairRobot) != 0)] = 0;
mvaddstr(1, boardXPos[scr], userstr);
? "(fair robot)" : "(robot)");
}
} //display playername/host
+
+ ShowPause(scr);
} //DrawScreen
ExtFunc void InitFields()
-{
+{ //place fields for all players
int scr, prevscr;
+ statusXPos = 2 * Players[me].boardWidth + 3;
boardXPos[me] = 1;
boardYPos[me] = 22;
prevscr = me;
boardYPos[scr] = 22;
prevscr = scr;
}
- statusXPos = 2 * Players[me].boardWidth + 3;
} //InitScreen
ExtFunc void CleanupScreen(int scr)
addstr(type ? "[]" : "$$");
standend();
}
-}
+} //PlotBlock1
ExtFunc void PlotBlock(int scr, int y, int x, BlockType type)
{
if (y >= 0 && y < Players[scr].boardVisible &&
x >= 0 && x < Players[scr].boardWidth)
PlotBlock1(scr, boardYPos[scr] - y, boardXPos[scr] + 2 * x, type);
-}
+} //PlotBlock
ExtFunc void PlotUnderline(int scr, int x, int flag)
{
addch(flag ? ACS_BTEE : ACS_HLINE);
addch(flag ? ACS_BTEE : ACS_HLINE);
}
-}
-
-ExtFunc void ShowDisplayInfo(void)
-{
- move(statusYPos - 9, statusXPos);
- printw("Seed: %010d", Game.seed);
- // move(statusYPos - 8, statusXPos);
- // printw("Speed: %dms ", speed / 1000);
- if (robotEnable) {
- move(statusYPos - 6, statusXPos);
- if (fairRobot)
- addstr("Controlled by a fair robot");
- else
- addstr("Controlled by a robot");
- // clrtoeol();
- }
- if (Players[1].flags & SCF_usingRobot) {
- move(statusYPos - 5, statusXPos);
- if (Players[1].flags & SCF_fairRobot)
- addstr("The opponent is a fair robot");
- else
- addstr("The opponent is a robot");
- // clrtoeol();
- }
-}
+} //PlotUnderline
ExtFunc void ShowScore(int scr, struct _Score score)
-{
+{ //show score stuff
float timer;
move(6, statusXPos); addstr("Next: ");
else addstr(" ");
printw(" apm:%5.1f", score.adds * 60 / timer);
}
-}
+} //ShowScore
+
+ExtFunc void FieldMessage(int playa, char *message)
+{ //put a message over playa's field
+ if (!Players[playa].spy) return;
+ if (message) {
+ char s[MAX_BOARD_WIDTH+1];
+ memset(s, ' ', MAX_BOARD_WIDTH);
+ memcpy(&s[Players[playa].boardWidth - strlen(message) / 2],
+ message, strlen(message));
+ s[Players[playa].boardWidth * 2] = 0;
+ if (Game.standout) standout();
+ mvprintw(boardYPos[playa] - Players[playa].boardVisible / 2,
+ boardXPos[playa], "%s", s);
+ standend();
+ } //display
+ else {
+ int x, y;
+ y = Players[playa].boardVisible / 2;
+ for (x = 0; x <= Players[playa].boardWidth; x++)
+ PlotBlock(playa, y, x, GetBlock(playa, y, x));
+ } //restore field
+} //FieldMessage
+
+ExtFunc void ShowPause(int playa)
+{ //put paused over player's field
+ if (Players[playa].flags & SCF_paused)
+ FieldMessage(playa, "P A U S E D");
+ else FieldMessage(playa, NULL);
+} //ShowPause
-ExtFunc void ShowPause(int pausedByMe, int pausedByThem)
-{
- move(statusYPos - 3, statusXPos);
- if (pausedByThem)
- addstr("Game paused by opponent");
- else
- addstr(" ");
- move(statusYPos - 2, statusXPos);
- if (pausedByMe)
- addstr("Game paused by you");
- else
- addstr(" ");
-}
ExtFunc void Message(char *s)
{
// move(statusYPos - 20 + line, statusXPos);
move(statusYPos + 2 + line, 1);
clrtoeol();
-}
+} //Message
ExtFunc void ShowTime(void)
-{
+{ //display timer
move(statusYPos, statusXPos);
printw("Timer: %.0f ", CurTimeval() / 1e6);
move(boardYPos[0] + 1, boardXPos[0] + 2 * Players[0].boardWidth + 1);
// refresh();
-}
+} //ShowTime
ExtFunc void ScheduleFullRedraw(void)
{
touchwin(stdscr);
-}
+} //ScheduleFullRedraw
static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
-{
+{ //read keypresses
if (MyRead(gen->fd, &event->u.key, 1))
return E_key;
else
return E_none;
-}
+} //KeyGenFunc
/*
* vi: ts=4 ai