Package: netris Severity: wishlist Tags: patch Version: 0.52-2 I just can't get into the swing of a tetris game without knowing what my next piece is going to be, so I've patched up netris to display it. Hopefully I can regain the netris crown from my wife now. <grin>
Unfortunately, despite much fart-arsing around, I can't work out how to make the piece display in ASCII art, so I settled for printing a letter representing the piece. Works OK for me. If you've got more experience with the codebase and can work out how to make the actual piece display, I'd be thrilled. - Matt
diff -urN netris-0.52.orig/curses.c netris-0.52/curses.c --- netris-0.52.orig/curses.c 2005-04-14 18:02:38.000000000 +1000 +++ netris-0.52/curses.c 2005-04-14 19:20:09.305547672 +1000 @@ -55,7 +55,8 @@ { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key }; static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS]; -static int statusYPos, statusXPos; +int statusYPos, statusXPos; +static int statusWidth = 30; static int haveColor; static int screens_dirty = 0; @@ -199,10 +200,13 @@ boardXPos[scr] = 1; else boardXPos[scr] = boardXPos[scr - 1] + - 2 * boardWidth[scr - 1] + 3; + 2 * boardWidth[scr - 1] + statusWidth + 4; boardYPos[scr] = 22; - if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3) - statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3; + + /* Status bar has a fixed position of 2 characters to the right of the + * local player's screen + */ + statusXPos = boardXPos[0] + 2 * boardWidth[0] + 3; for (y = boardVisible[scr] - 1; y >= 0; --y) { move(boardYPos[scr] - y, boardXPos[scr] - 1); addch('|'); @@ -281,11 +285,13 @@ } move(statusYPos - 9, statusXPos); + addstr(" "); + move(statusYPos - 9, statusXPos); printw("Seed: %d", initSeed); - clrtoeol(); + move(statusYPos - 8, statusXPos); + addstr(" "); move(statusYPos - 8, statusXPos); printw("Speed: %dms", speed / 1000); - clrtoeol(); if (robotEnable) { move(statusYPos - 6, statusXPos); if (fairRobot) @@ -317,12 +323,12 @@ if (pausedByThem) addstr("Game paused by opponent"); else - clrtoeol(); + addstr(" "); move(statusYPos - 2, statusXPos); if (pausedByMe) addstr("Game paused by you"); else - clrtoeol(); + addstr(" "); } ExtFunc void Message(char *s) diff -urN netris-0.52.orig/game.c netris-0.52/game.c --- netris-0.52.orig/game.c 2005-04-14 18:02:38.000000000 +1000 +++ netris-0.52/game.c 2005-04-14 19:58:32.851355480 +1000 @@ -79,16 +79,26 @@ exit(1); } +extern int statusXPos, statusYPos; + ExtFunc int StartNewPiece(int scr, Shape *shape) { - curShape[scr] = shape; + curShape[scr] = nextShape[scr]; + nextShape[scr] = shape; curY[scr] = boardVisible[scr] + 4; curX[scr] = boardWidth[scr] / 2; - while (!ShapeVisible(shape, scr, curY[scr], curX[scr])) + while (!ShapeVisible(curShape[scr], scr, curY[scr], curX[scr])) --curY[scr]; - if (!ShapeFits(shape, scr, curY[scr], curX[scr])) + if (!ShapeFits(curShape[scr], scr, curY[scr], curX[scr])) return 0; - PlotShape(shape, scr, curY[scr], curX[scr], 1); + PlotShape(curShape[scr], scr, curY[scr], curX[scr], 1); + + /* Tell the user the next piece coming up */ + if (scr == 0) + { + move(statusYPos - 18, statusXPos); + printw("%c", nextShape[scr]->shorthand); + } return 1; } @@ -131,6 +141,9 @@ RobotCmd(0, "BeginGame\n"); RobotTimeStamp(); } + + // Put an initial piece on the stack + nextShape[scr] = nextShape[scr2] = ChooseOption(stdOptions); while (StartNewPiece(scr, ChooseOption(stdOptions))) { if (robotEnable && !fairRobot) RobotCmd(1, "NewPiece %d\n", ++pieceCount); diff -urN netris-0.52.orig/netris.h netris-0.52/netris.h --- netris-0.52.orig/netris.h 2005-04-14 18:02:38.000000000 +1000 +++ netris-0.52/netris.h 2005-04-14 19:39:40.817450792 +1000 @@ -142,6 +142,7 @@ Dir initDir; BlockType type; Cmd *cmds; + char shorthand; } Shape; typedef struct _ShapeOption { @@ -162,6 +163,7 @@ EXT GameType game; EXT int boardHeight[MAX_SCREENS]; EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS]; +EXT Shape *nextShape[MAX_SCREENS]; EXT Shape *curShape[MAX_SCREENS]; EXT int curY[MAX_SCREENS], curX[MAX_SCREENS]; EXT char opponentName[16], opponentHost[256]; diff -urN netris-0.52.orig/shapes.c netris-0.52/shapes.c --- netris-0.52.orig/shapes.c 2003-08-13 11:33:02.000000000 +1000 +++ netris-0.52/shapes.c 2005-04-14 19:42:31.775461224 +1000 @@ -28,44 +28,44 @@ #define PreDecl(name, dir) \ static Shape ShapeName(name, dir) -#define StdShape(name, cmdName, mirror, type, realDir, dir, nextDir) \ +#define StdShape(name, cmdName, mirror, type, realDir, dir, nextDir, character) \ static Shape ShapeName(name, dir) = { &ShapeName(name, nextDir), \ - 0, 0, mirror, D_ ## realDir, type, cmds_ ## cmdName } + 0, 0, mirror, D_ ## realDir, type, cmds_ ## cmdName, character} -#define FourWayDecl(name, cmdName, mirror, type) \ +#define FourWayDecl(name, cmdName, mirror, type, character) \ PreDecl(name, down); \ - StdShape(name, cmdName, mirror, type, left, left, down); \ - StdShape(name, cmdName, mirror, type, up, up, left); \ - StdShape(name, cmdName, mirror, type, right, right, up); \ - StdShape(name, cmdName, mirror, type, down, down, right) + StdShape(name, cmdName, mirror, type, left, left, down, character); \ + StdShape(name, cmdName, mirror, type, up, up, left, character); \ + StdShape(name, cmdName, mirror, type, right, right, up, character); \ + StdShape(name, cmdName, mirror, type, down, down, right, character) -#define TwoWayDecl(name, cmdName, mirror, type) \ +#define TwoWayDecl(name, cmdName, mirror, type, character) \ PreDecl(name, vert); \ - StdShape(name, cmdName, mirror, type, right, horiz, vert); \ - StdShape(name, cmdName, mirror, type, down, vert, horiz) + StdShape(name, cmdName, mirror, type, right, horiz, vert, character); \ + StdShape(name, cmdName, mirror, type, down, vert, horiz, character) static Cmd cmds_long[] = { C_back, C_plot, C_forw, C_plot, C_forw, C_plot, C_forw, C_plot, C_end }; -TwoWayDecl(long, long, 0, BT_blue); +TwoWayDecl(long, long, 0, BT_blue, '|'); static Cmd cmds_square[] = { C_plot, C_forw, C_left, C_plot, C_forw, C_left, C_plot, C_forw, C_left, C_plot, C_end }; static Shape shape_square = { &shape_square, 0, 0, D_up, 0, BT_magenta, - cmds_square }; + cmds_square, '#' }; static Cmd cmds_l[] = { C_right, C_back, C_plot, C_forw, C_plot, C_forw, C_plot, C_left, C_forw, C_plot, C_end }; -FourWayDecl(l, l, 0, BT_cyan); -FourWayDecl(l1, l, 1, BT_yellow); +FourWayDecl(l, l, 0, BT_cyan, 'L'); +FourWayDecl(l1, l, 1, BT_yellow, 'J'); static Cmd cmds_t[] = { C_plot, C_forw, C_plot, C_back, C_right, C_forw, C_plot, C_back, C_back, C_plot, C_end }; -FourWayDecl(t, t, 0, BT_white); +FourWayDecl(t, t, 0, BT_white, 'T'); static Cmd cmds_s[] = { C_back, C_plot, C_forw, C_plot, C_left, C_forw, C_plot, C_right, C_forw, C_plot, C_end }; -TwoWayDecl(s, s, 0, BT_green); -TwoWayDecl(s1, s, 1, BT_red); +TwoWayDecl(s, s, 0, BT_green, 'S'); +TwoWayDecl(s1, s, 1, BT_red, 'Z'); ShapeOption stdOptions[] = { {1, &shape_long_horiz},