]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - gomoku/bdisp.c
fix prototype, PR#5867
[bsdgames-darwin.git] / gomoku / bdisp.c
1 /* $NetBSD: bdisp.c,v 1.5 1997/10/10 13:36:02 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)bdisp.c 8.2 (Berkeley) 5/3/95";
43 #else
44 __RCSID("$NetBSD: bdisp.c,v 1.5 1997/10/10 13:36:02 lukem Exp $");
45 #endif
46 #endif /* not lint */
47
48 #include <curses.h>
49 #include <string.h>
50 #include "gomoku.h"
51
52 #define SCRNH 24 /* assume 24 lines for the moment */
53 #define SCRNW 80 /* assume 80 chars for the moment */
54
55 static int lastline;
56 static char pcolor[] = "*O.?";
57
58 /*
59 * Initialize screen display.
60 */
61 void
62 cursinit()
63 {
64
65 initscr();
66 noecho();
67 cbreak();
68 leaveok(stdscr, TRUE);
69 }
70
71 /*
72 * Restore screen display.
73 */
74 void
75 cursfini()
76 {
77
78 leaveok(stdscr, FALSE);
79 move(23, 0);
80 clrtoeol();
81 refresh();
82 endwin();
83 }
84
85 /*
86 * Initialize board display.
87 */
88 void
89 bdisp_init()
90 {
91 int i, j;
92
93 /* top border */
94 for (i = 1; i < BSZ1; i++) {
95 move(0, 2 * i + 1);
96 addch(letters[i]);
97 }
98 /* left and right edges */
99 for (j = BSZ1; --j > 0; ) {
100 move(20 - j, 0);
101 printw("%2d ", j);
102 move(20 - j, 2 * BSZ1 + 1);
103 printw("%d ", j);
104 }
105 /* bottom border */
106 for (i = 1; i < BSZ1; i++) {
107 move(20, 2 * i + 1);
108 addch(letters[i]);
109 }
110 bdwho(0);
111 move(0, 47);
112 addstr("# black white");
113 lastline = 0;
114 bdisp();
115 }
116
117 /*
118 * Update who is playing whom.
119 */
120 void
121 bdwho(update)
122 int update;
123 {
124 int i;
125 extern char *plyr[];
126
127 move(21, 0);
128 clrtoeol();
129 i = 6 - strlen(plyr[BLACK]) / 2;
130 move(21, i > 0 ? i : 0);
131 printw("BLACK/%s", plyr[BLACK]);
132 i = 30 - strlen(plyr[WHITE]) / 2;
133 move(21, i);
134 printw("WHITE/%s", plyr[WHITE]);
135 move(21, 19);
136 addstr(" vs. ");
137 if (update)
138 refresh();
139 }
140
141 /*
142 * Update the board display after a move.
143 */
144 void
145 bdisp()
146 {
147 int i, j, c;
148 struct spotstr *sp;
149
150 for (j = BSZ1; --j > 0; ) {
151 for (i = 1; i < BSZ1; i++) {
152 move(BSZ1 - j, 2 * i + 1);
153 sp = &board[i + j * BSZ1];
154 if (debug > 1 && sp->s_occ == EMPTY) {
155 if (sp->s_flg & IFLAGALL)
156 c = '+';
157 else if (sp->s_flg & CFLAGALL)
158 c = '-';
159 else
160 c = '.';
161 } else
162 c = pcolor[sp->s_occ];
163 addch(c);
164 }
165 }
166 refresh();
167 }
168
169 #ifdef DEBUG
170 /*
171 * Dump board display to a file.
172 */
173 void
174 bdump(fp)
175 FILE *fp;
176 {
177 int i, j, c;
178 struct spotstr *sp;
179
180 /* top border */
181 fprintf(fp, " A B C D E F G H J K L M N O P Q R S T\n");
182
183 for (j = BSZ1; --j > 0; ) {
184 /* left edge */
185 fprintf(fp, "%2d ", j);
186 for (i = 1; i < BSZ1; i++) {
187 sp = &board[i + j * BSZ1];
188 if (debug > 1 && sp->s_occ == EMPTY) {
189 if (sp->s_flg & IFLAGALL)
190 c = '+';
191 else if (sp->s_flg & CFLAGALL)
192 c = '-';
193 else
194 c = '.';
195 } else
196 c = pcolor[sp->s_occ];
197 putc(c, fp);
198 putc(' ', fp);
199 }
200 /* right edge */
201 fprintf(fp, "%d\n", j);
202 }
203
204 /* bottom border */
205 fprintf(fp, " A B C D E F G H J K L M N O P Q R S T\n");
206 }
207 #endif /* DEBUG */
208
209 /*
210 * Display a transcript entry
211 */
212 void
213 dislog(str)
214 char *str;
215 {
216
217 if (++lastline >= SCRNH - 1) {
218 /* move 'em up */
219 lastline = 1;
220 }
221 if (strlen(str) >= SCRNW - 46)
222 str[SCRNW - 46 - 1] = '\0';
223 move(lastline, 46);
224 addstr(str);
225 clrtoeol();
226 move(lastline + 1, 46);
227 clrtoeol();
228 }
229
230 /*
231 * Display a question.
232 */
233
234 void
235 ask(str)
236 char *str;
237 {
238 int len = strlen(str);
239
240 move(23, 0);
241 addstr(str);
242 clrtoeol();
243 move(23, len);
244 refresh();
245 }
246
247 int
248 getline(buf, size)
249 char *buf;
250 int size;
251 {
252 char *cp, *end;
253 int c;
254 extern int interactive;
255
256 c = 0;
257 cp = buf;
258 end = buf + size - 1; /* save room for the '\0' */
259 while (cp < end && (c = getchar()) != EOF && c != '\n' && c != '\r') {
260 *cp++ = c;
261 if (interactive) {
262 switch (c) {
263 case 0x0c: /* ^L */
264 wrefresh(curscr);
265 cp--;
266 continue;
267 case 0x15: /* ^U */
268 case 0x18: /* ^X */
269 while (cp > buf) {
270 cp--;
271 addch('\b');
272 }
273 clrtoeol();
274 break;
275 case '\b':
276 case 0x7f: /* DEL */
277 if (cp == buf + 1) {
278 cp--;
279 continue;
280 }
281 cp -= 2;
282 addch('\b');
283 c = ' ';
284 /* FALLTHROUGH */
285 default:
286 addch(c);
287 }
288 refresh();
289 }
290 }
291 *cp = '\0';
292 return(c != EOF);
293 }