]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - gomoku/bdisp.c
1 /* $NetBSD: bdisp.c,v 1.17 2014/03/22 18:58:57 dholland Exp $ */
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)bdisp.c 8.2 (Berkeley) 5/3/95";
40 __RCSID("$NetBSD: bdisp.c,v 1.17 2014/03/22 18:58:57 dholland Exp $");
50 #define SCRNH 24 /* assume 24 lines for the moment */
51 #define SCRNW 80 /* assume 80 chars for the moment */
54 static char pcolor
[] = "*O.?";
57 * Initialize screen display.
64 errx(EXIT_FAILURE
, "Couldn't initialize screen");
66 if ((LINES
< SCRNH
) || (COLS
< SCRNW
)) {
67 errx(EXIT_FAILURE
, "Screen too small (need %d%xd)",
74 leaveok(stdscr
, FALSE
);
76 #if 0 /* no mouse support in netbsd curses yet */
77 mousemask(BUTTON1_CLICKED
, NULL
);
82 * Restore screen display.
96 * Initialize board display.
104 for (i
= 1; i
< BSZ1
; i
++) {
108 /* left and right edges */
109 for (j
= BSZ1
; --j
> 0; ) {
112 move(20 - j
, 2 * BSZ1
+ 1);
116 for (i
= 1; i
< BSZ1
; i
++) {
122 addstr("# black white");
128 * Update who is playing whom.
137 i
= strlen(plyr
[BLACK
]);
138 j
= strlen(plyr
[WHITE
]);
140 move(21, 10 - (i
+j
)/2);
141 printw("BLACK/%s (*) vs. WHITE/%s (O)",
142 plyr
[BLACK
], plyr
[WHITE
]);
147 } else if (j
<= 10) {
152 printw("BLACK/%.*s (*) vs. WHITE/%.*s (O)",
153 i
, plyr
[BLACK
], j
, plyr
[WHITE
]);
160 * Update the board display after a move.
168 for (j
= BSZ1
; --j
> 0; ) {
169 for (i
= 1; i
< BSZ1
; i
++) {
170 move(BSZ1
- j
, 2 * i
+ 1);
171 sp
= &board
[i
+ j
* BSZ1
];
172 if (debug
> 1 && sp
->s_occ
== EMPTY
) {
173 if (sp
->s_flags
& IFLAGALL
)
175 else if (sp
->s_flags
& CFLAGALL
)
180 c
= pcolor
[sp
->s_occ
];
189 * Dump board display to a file.
198 fprintf(fp
, " A B C D E F G H J K L M N O P Q R S T\n");
200 for (j
= BSZ1
; --j
> 0; ) {
202 fprintf(fp
, "%2d ", j
);
203 for (i
= 1; i
< BSZ1
; i
++) {
204 sp
= &board
[i
+ j
* BSZ1
];
205 if (debug
> 1 && sp
->s_occ
== EMPTY
) {
206 if (sp
->s_flags
& IFLAGALL
)
208 else if (sp
->s_flags
& CFLAGALL
)
213 c
= pcolor
[sp
->s_occ
];
218 fprintf(fp
, "%d\n", j
);
222 fprintf(fp
, " A B C D E F G H J K L M N O P Q R S T\n");
227 * Display a transcript entry
230 dislog(const char *str
)
233 if (++lastline
>= SCRNH
- 1) {
237 move(lastline
, TRANSCRIPT_COL
);
238 addnstr(str
, SCRNW
- TRANSCRIPT_COL
- 1);
240 move(lastline
+ 1, TRANSCRIPT_COL
);
245 * Display a question.
251 int len
= strlen(str
);
261 get_key(const char *allowed
)
267 if (allowed
!= NULL
&&
268 ch
!= '\0' && strchr(allowed
, ch
) == NULL
) {
279 get_line(char *buf
, int size
)
286 end
= buf
+ size
- 1; /* save room for the '\0' */
287 while (cp
< end
&& (c
= getchar()) != EOF
&& c
!= '\n' && c
!= '\r') {
324 * Decent (n)curses interface for the game, based on Eric S. Raymond's
325 * modifications to the battleship (bs) user interface.
330 static int curx
= BSZ
/ 2;
331 static int cury
= BSZ
/ 2;
339 mvprintw(BSZ3
, (BSZ
-6)/2, "(%c %d) ",
340 'A'+ ((curx
> 7) ? (curx
+1) : curx
), cury
+ 1);
428 (void)clearok(stdscr
, TRUE
);
437 if (myevent
.y
>= 1 && myevent
.y
<= BSZ1
&&
438 myevent
.x
>= 3 && myevent
.x
<= (2 * BSZ
+ 1)) {
439 curx
= (myevent
.x
- 3) / 2;
440 cury
= BSZ
- myevent
.y
;
441 return PT(curx
,cury
);
458 (void) mvaddstr(BSZ3
, (BSZ
-6)/2, " ");
459 return PT(curx
+1,cury
+1);