1
0
mirror of https://salsa.debian.org/games-team/bsdgames synced 2024-06-08 17:30:46 +00:00

Add keys (^a, ^t) to rotate cubes.

This commit is contained in:
b9 2020-08-26 18:58:41 -07:00
parent 3de70963a4
commit 128a8cbb1a
3 changed files with 94 additions and 29 deletions

View File

@ -96,6 +96,13 @@ char board[17];
int wordpath[MAXWORDLEN + 1];
int wordlen; /* Length of last word returned by nextword() */
int usedbits;
int orientation=0; /* 1: 90 deg clockwise, 2: 180, 3: 270. */
int rotation[4][16] = { /* Mapping based on orientation. */
{0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF},
{0xC,0x8,0x4,0x0,0xD,0x9,0x5,0x1,0xE,0xA,0x6,0x2,0xF,0xB,0x7,0x3},
{0xF,0xE,0xD,0xC,0xB,0xA,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0},
{0x3,0x7,0xB,0xF,0x2,0x6,0xA,0xE,0x1,0x5,0x9,0xD,0x0,0x4,0x8,0xC},
};
const char *pword[MAXPWORDS];
char pwords[MAXPSPACE], *pwordsp;
@ -336,7 +343,7 @@ playgame()
}
while (1) {
if (getline(buf) == NULL) {
if (get_line(buf) == NULL) {
if (feof(stdin))
clearerr(stdin);
break;
@ -668,6 +675,7 @@ newgame(b)
board[i] = b[i];
}
board[16] = '\0';
orientation = 0;
/*
* Set up the map from letter to location(s)

View File

@ -1,4 +1,3 @@
Commands:
Enter word: <return> or <linefeed> or <space>
@ -7,6 +6,7 @@ Delete line: <^u> or <^w>
Redraw screen: <^l> or <^r>
Pause game: <^s>
Resume game: <^q> or <^s>
Rotate board: <^a> or <^t>
Suspend game (BSD only): <^z>
Give up on current cube: <^d>
Show remaining time: <space> first thing on a line

View File

@ -69,6 +69,8 @@ int ncols, nlines;
extern const char *pword[], *mword[];
extern int ngames, nmwords, npwords, tnmwords, tnpwords;
extern char board[];
extern int orientation;
extern int rotation[4][16];
extern int usedbits, wordpath[];
extern time_t start_t;
extern int debug;
@ -76,11 +78,13 @@ extern int debug;
static void cont_catcher(int);
static int prwidth(const char *const [], int);
static void prword(const char *const [], int);
static void prpwords(void);
static void stop_catcher(int);
static void tty_cleanup(void);
static int tty_setup(void);
static void tty_showboard(const char *);
static void winch_catcher(int);
static void clrtosol(void);
/*
* Do system dependent initialization
@ -168,7 +172,7 @@ prwidth(base, indx)
* - doesn't accept words longer than MAXWORDLEN or containing caps
*/
char *
getline(q)
get_line(q)
char *q;
{
int ch, done;
@ -193,19 +197,29 @@ getline(q)
if (p == q)
break;
p--;
getyx(stdscr, row, col);
move(row, col - 1);
clrtoeol();
putstr("\b \b");
refresh();
break;
case '\001': /* <^a> */
orientation=(orientation+3)%4;
showboard(board);
redraw();
break;
case '\024': /* <^t> */
orientation=(orientation+1)%4;
showboard(board);
redraw();
break;
case '\025': /* <^u> */
case '\027': /* <^w> */
if (p == q)
break;
getyx(stdscr, row, col);
move(row, col - (int) (p - q));
p = q;
clrtoeol();
while (p>q)
{
p--;
putstr("\b \b"); /* backspace over character */
refresh();
}
refresh();
break;
#ifdef SIGTSTP
@ -218,9 +232,9 @@ getline(q)
printw("<PAUSE>");
refresh();
while ((ch = inputch()) != '\021' && ch != '\023')
;
; /* wait for ^Q or ^S */
move(crow, ccol);
clrtoeol();
clrtoeol();
refresh();
starttime();
break;
@ -272,6 +286,25 @@ void
redraw()
{
clearok(stdscr, 1);
move(LIST_LINE, LIST_COL);
prpwords();
move(crow, ccol);
refresh();
}
/*
* Re-print all the words the player has found.
*/
void
prpwords(void)
{
int n, row, col;
for (n = 0; n < npwords; n++) {
row = LIST_LINE + n % (lastline - LIST_LINE + 1);
col = colstarts[n / (lastline - LIST_LINE + 1)];
move(row, col);
printw("%s", pword[n]);
}
refresh();
}
@ -397,7 +430,7 @@ showword(n)
* If it's found, show the word on the board for a short time and then
* erase the word
*
* Note: this function knows about the format of the board
* Note: this function knows about the format of the board.
*/
void
findword()
@ -426,13 +459,13 @@ findword()
wordpath[i] = -1;
usedbits = 0;
if (!found || checkword(buf, -1, wordpath) == -1) {
move(r, c);
clrtoeol();
clrtosol();
addstr("[???]");
c=c+strlen("[???]");
refresh();
delay(10);
move(r, c);
clrtoeol();
clrtosol();
refresh();
return;
}
@ -462,11 +495,28 @@ findword()
else
printw("%c", toupper((unsigned char)board[wordpath[i]]));
}
move(r, c);
clrtoeol();
move(r, c+strlen(buf)+1);
clrtosol();
refresh();
}
/*
* Clears from current cursor location to Start Of Line.
*/
void
clrtosol(void)
{
int c, r;
getyx(stdscr, r, c);
do {
addch(' '); /* Space */
addch('\b'); /* Backspace */
addch('\b'); /* Backspace */
} while (c--);
}
/*
* Display a string at the current cursor position for the given number of secs
*/
@ -513,18 +563,23 @@ getword(q)
if (p == q)
break;
p--;
getyx(stdscr, row, col);
move(row, col - 1);
clrtoeol();
addch('\b'); /* backspace */
addch(' '); /* clear char */
addch('\b'); /* backspace */
refresh();
break;
case '\025': /* <^u> */
case '\027': /* <^w> */
if (p == q)
break;
getyx(stdscr, row, col);
move(row, col - (int) (p - q));
p = q;
clrtoeol();
while (p>q)
{
p--;
addch('\b'); /* backspace */
addch(' '); /* clear char */
addch('\b'); /* backspace */
refresh();
}
break;
case ' ':
case '\n':
@ -533,8 +588,7 @@ getword(q)
break;
case '\014': /* <^l> */
case '\022': /* <^r> */
clearok(stdscr, 1);
refresh();
redraw();
break;
default:
if (islower(ch)) {
@ -625,6 +679,7 @@ cont_catcher(signo)
/*
* The signal is caught but nothing is done about it...
* It would mean reformatting the entire display
* XXX TODO XXX
*/
static void
winch_catcher(signo)
@ -658,6 +713,7 @@ tty_showboard(b)
{
int i;
int line;
char c;
clear();
move(BOARD_LINE, BOARD_COL);
@ -665,10 +721,11 @@ tty_showboard(b)
printw("+---+---+---+---+");
move(++line, BOARD_COL);
for (i = 0; i < 16; i++) {
if (b[i] == 'q')
c = b[rotation[orientation][i]];
if (c == 'q')
printw("| Qu");
else
printw("| %c ", toupper((unsigned char)b[i]));
printw("| %c ", toupper((unsigned char)c));
if ((i + 1) % 4 == 0) {
printw("|");
move(++line, BOARD_COL);