Skip to content

Commit 5dcb186

Browse files
committed
Move game logic out of the file with the curses code.
1 parent f398267 commit 5dcb186

File tree

4 files changed

+89
-60
lines changed

4 files changed

+89
-60
lines changed

games/atc/extern.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: extern.h,v 1.18 2015/06/19 06:02:31 dholland Exp $ */
1+
/* $NetBSD: extern.h,v 1.19 2015/06/25 05:33:02 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -64,6 +64,13 @@ extern struct termios tty_start, tty_new;
6464

6565
extern DISPLACEMENT displacement[MAXDIR];
6666

67+
/* in graphics.c */
68+
void shutdown_gr(void);
69+
void ioaskquit(void);
70+
void ionoquit(void);
71+
void losermsg(const PLANE *p, const char *msg);
72+
73+
/* misc */
6774
void addplane(void);
6875
void append(LIST *, PLANE *);
6976
void check_adir(int, int, int);
@@ -88,7 +95,6 @@ char name(const PLANE *);
8895
int number(int);
8996
void open_score_file(void);
9097
void planewin(void);
91-
void quit(int);
9298
void redraw(void);
9399
void setup_screen(const C_SCREEN *);
94100
void update(int);

games/atc/graphics.c

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: graphics.c,v 1.19 2015/06/19 06:02:31 dholland Exp $ */
1+
/* $NetBSD: graphics.c,v 1.20 2015/06/25 05:33:02 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
4646
#if 0
4747
static char sccsid[] = "@(#)graphics.c 8.1 (Berkeley) 5/31/93";
4848
#else
49-
__RCSID("$NetBSD: graphics.c,v 1.19 2015/06/19 06:02:31 dholland Exp $");
49+
__RCSID("$NetBSD: graphics.c,v 1.20 2015/06/25 05:33:02 dholland Exp $");
5050
#endif
5151
#endif /* not lint */
5252

@@ -135,6 +135,15 @@ init_gr(void)
135135
planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
136136
}
137137

138+
void
139+
shutdown_gr(void)
140+
{
141+
(void)clear(); /* move to top of screen */
142+
(void)refresh();
143+
(void)fflush(stdout);
144+
(void)endwin();
145+
}
146+
138147
void
139148
setup_screen(const C_SCREEN *scp)
140149
{
@@ -293,43 +302,25 @@ ioerror(int pos, int len, const char *str)
293302
(void)fflush(stdout);
294303
}
295304

296-
/* ARGSUSED */
305+
static int ioquit_x, ioquit_y;
306+
297307
void
298-
quit(int dummy __unused)
308+
ioaskquit(void)
299309
{
300-
int c, y, x;
301-
#ifdef BSD
302-
struct itimerval itv;
303-
#endif
304-
305-
getyx(input, y, x);
310+
getyx(input, ioquit_y, ioquit_x);
306311
(void)wmove(input, 2, 0);
307312
(void)waddstr(input, "Really quit? (y/n) ");
308313
(void)wclrtobot(input);
309314
(void)wrefresh(input);
310315
(void)fflush(stdout);
316+
}
311317

312-
c = getchar();
313-
if (c == EOF || c == 'y') {
314-
/* disable timer */
315-
#ifdef BSD
316-
itv.it_value.tv_sec = 0;
317-
itv.it_value.tv_usec = 0;
318-
(void)setitimer(ITIMER_REAL, &itv, NULL);
319-
#endif
320-
#ifdef SYSV
321-
alarm(0);
322-
#endif
323-
(void)fflush(stdout);
324-
(void)clear();
325-
(void)refresh();
326-
(void)endwin();
327-
(void)log_score(0);
328-
exit(0);
329-
}
318+
void
319+
ionoquit(void)
320+
{
330321
(void)wmove(input, 2, 0);
331322
(void)wclrtobot(input);
332-
(void)wmove(input, y, x);
323+
(void)wmove(input, ioquit_y, ioquit_x);
333324
(void)wrefresh(input);
334325
(void)fflush(stdout);
335326
}
@@ -378,42 +369,20 @@ planewin(void)
378369
}
379370

380371
void
381-
loser(const PLANE *p, const char *s)
372+
losermsg(const PLANE *p, const char *msg)
382373
{
383-
int c;
384-
#ifdef BSD
385-
struct itimerval itv;
386-
#endif
387-
388-
/* disable timer */
389-
#ifdef BSD
390-
itv.it_value.tv_sec = 0;
391-
itv.it_value.tv_usec = 0;
392-
(void)setitimer(ITIMER_REAL, &itv, NULL);
393-
#endif
394-
#ifdef SYSV
395-
alarm(0);
396-
#endif
397-
398374
(void)wmove(input, 0, 0);
399375
(void)wclrtobot(input);
400376
/* p may be NULL if we ran out of memory */
401377
if (p == NULL)
402378
(void)wprintw(input, "%s\n\nHit space for top players list...",
403-
s);
379+
msg);
404380
else {
405-
(void)wprintw(input, "Plane '%c' %s\n\n", name(p), s);
381+
(void)wprintw(input, "Plane '%c' %s\n\n", name(p), msg);
406382
(void)wprintw(input, "Hit space for top players list...");
407383
}
408384
(void)wrefresh(input);
409385
(void)fflush(stdout);
410-
while ((c = getchar()) != EOF && c != ' ')
411-
;
412-
(void)clear(); /* move to top of screen */
413-
(void)refresh();
414-
(void)endwin();
415-
(void)log_score(0);
416-
exit(0);
417386
}
418387

419388
void

games/atc/main.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: main.c,v 1.23 2015/06/19 06:02:31 dholland Exp $ */
1+
/* $NetBSD: main.c,v 1.24 2015/06/25 05:33:02 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993\
5151
#if 0
5252
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
5353
#else
54-
__RCSID("$NetBSD: main.c,v 1.23 2015/06/19 06:02:31 dholland Exp $");
54+
__RCSID("$NetBSD: main.c,v 1.24 2015/06/25 05:33:02 dholland Exp $");
5555
#endif
5656
#endif /* not lint */
5757

@@ -75,6 +75,7 @@ static int read_file(const char *);
7575
static const char *default_game(void);
7676
static const char *okay_game(const char *);
7777
static int list_games(void);
78+
static void quit(int);
7879

7980
int
8081
main(int argc, char *argv[])
@@ -327,3 +328,30 @@ list_games(void)
327328
}
328329
return (0);
329330
}
331+
332+
/* ARGSUSED */
333+
static void
334+
quit(int dummy __unused)
335+
{
336+
int c;
337+
#ifdef BSD
338+
struct itimerval itv;
339+
#endif
340+
ioaskquit();
341+
c = getAChar();
342+
if (c == EOF || c == 'y') {
343+
/* disable timer */
344+
#ifdef BSD
345+
itv.it_value.tv_sec = 0;
346+
itv.it_value.tv_usec = 0;
347+
(void)setitimer(ITIMER_REAL, &itv, NULL);
348+
#endif
349+
#ifdef SYSV
350+
alarm(0);
351+
#endif
352+
shutdown_gr();
353+
(void)log_score(0);
354+
exit(0);
355+
}
356+
ionoquit();
357+
}

games/atc/update.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: update.c,v 1.26 2015/06/19 06:02:31 dholland Exp $ */
1+
/* $NetBSD: update.c,v 1.27 2015/06/25 05:33:02 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
4646
#if 0
4747
static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93";
4848
#else
49-
__RCSID("$NetBSD: update.c,v 1.26 2015/06/19 06:02:31 dholland Exp $");
49+
__RCSID("$NetBSD: update.c,v 1.27 2015/06/25 05:33:02 dholland Exp $");
5050
#endif
5151
#endif /* not lint */
5252

@@ -232,6 +232,32 @@ update(int dummy __unused)
232232
#endif
233233
}
234234

235+
void
236+
loser(const PLANE *p, const char *s)
237+
{
238+
int c;
239+
#ifdef BSD
240+
struct itimerval itv;
241+
#endif
242+
243+
/* disable timer */
244+
#ifdef BSD
245+
itv.it_value.tv_sec = 0;
246+
itv.it_value.tv_usec = 0;
247+
(void)setitimer(ITIMER_REAL, &itv, NULL);
248+
#endif
249+
#ifdef SYSV
250+
alarm(0);
251+
#endif
252+
253+
losermsg(p, s);
254+
while ((c = getAChar()) != EOF && c != ' ')
255+
;
256+
shutdown_gr();
257+
(void)log_score(0);
258+
exit(0);
259+
}
260+
235261
const char *
236262
command(const PLANE *pp)
237263
{

0 commit comments

Comments
 (0)