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

Merge branch 'master' into 'master'

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

See merge request games-team/bsdgames!4
This commit is contained in:
Ben Wong 2023-07-28 11:39:22 +00:00
commit 2a65695bbb
4 changed files with 95 additions and 30 deletions

View File

@ -0,0 +1,5 @@
((nil . ((indent-tabs-mode . t)
(fill-column . 80)))
(c-mode . ((c-file-style . "BSD")
(subdirs . nil))))

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;
@ -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
@ -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()
@ -439,13 +472,19 @@ findword()
standout();
for (i = 0; wordpath[i] != -1; i++) {
row = BOARD_LINE + (wordpath[i] / 4) * 2 + 1;
col = BOARD_COL + (wordpath[i] % 4) * 4 + 2;
int w = wordpath[i];
if (orientation == 1 || orientation == 3)
w=rotation[4-orientation][w]; /* Unrotate +/- 90 degrees*/
else
w=rotation[orientation][w]; /* Unrotate 0 or 180 degrees */
row = BOARD_LINE + (w / 4) * 2 + 1;
col = BOARD_COL + (w % 4) * 4 + 2;
move(row, col);
if (board[wordpath[i]] == 'q')
unsigned char k = board[wordpath[i]];
if (k == 'q')
printw("Qu");
else
printw("%c", toupper((unsigned char)board[wordpath[i]]));
printw("%c", toupper(k));
move(r, c);
refresh();
delay(5);
@ -454,13 +493,19 @@ findword()
standend();
for (i = 0; wordpath[i] != -1; i++) {
row = BOARD_LINE + (wordpath[i] / 4) * 2 + 1;
col = BOARD_COL + (wordpath[i] % 4) * 4 + 2;
int w = wordpath[i];
if (orientation == 1 || orientation == 3)
w=rotation[4-orientation][w]; /* Unrotate +/- 90 degrees*/
else
w=rotation[orientation][w]; /* Unrotate 0 or 180 degrees */
row = BOARD_LINE + (w / 4) * 2 + 1;
col = BOARD_COL + (w % 4) * 4 + 2;
move(row, col);
if (board[wordpath[i]] == 'q')
unsigned char k = board[wordpath[i]];
if (k == 'q')
printw("Qu");
else
printw("%c", toupper((unsigned char)board[wordpath[i]]));
printw("%c", toupper(k));
}
move(r, c);
clrtoeol();
@ -513,18 +558,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 +583,7 @@ getword(q)
break;
case '\014': /* <^l> */
case '\022': /* <^r> */
clearok(stdscr, 1);
refresh();
redraw();
break;
default:
if (islower(ch)) {
@ -625,6 +674,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 +708,7 @@ tty_showboard(b)
{
int i;
int line;
char k;
clear();
move(BOARD_LINE, BOARD_COL);
@ -665,10 +716,11 @@ tty_showboard(b)
printw("+---+---+---+---+");
move(++line, BOARD_COL);
for (i = 0; i < 16; i++) {
if (b[i] == 'q')
k = b[rotation[orientation][i]];
if (k == 'q')
printw("| Qu");
else
printw("| %c ", toupper((unsigned char)b[i]));
printw("| %c ", toupper((unsigned char)k));
if ((i + 1) % 4 == 0) {
printw("|");
move(++line, BOARD_COL);