From b832dece316930d89df04476c872cb967a95c7e5 Mon Sep 17 00:00:00 2001 From: jsm Date: Thu, 30 Aug 2001 10:49:50 +0000 Subject: Check for screen sizes that are too small. Fix off-by-one error in trying to place the prize. Position the score appropriately for screens that may not be 80 columns wide. --- worm/worm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'worm') diff --git a/worm/worm.c b/worm/worm.c index f6e1be7c..67dfc20f 100644 --- a/worm/worm.c +++ b/worm/worm.c @@ -1,4 +1,4 @@ -/* $NetBSD: worm.c,v 1.20 2001/08/29 23:25:58 jsm Exp $ */ +/* $NetBSD: worm.c,v 1.21 2001/08/30 10:49:50 jsm Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: worm.c,v 1.20 2001/08/29 23:25:58 jsm Exp $"); +__RCSID("$NetBSD: worm.c,v 1.21 2001/08/30 10:49:50 jsm Exp $"); #endif #endif /* not lint */ @@ -117,6 +117,15 @@ main(argc, argv) #endif slow = (baudrate() <= 1200); clear(); + if (COLS < 18 || LINES < 5) { + /* + * Insufficient room for the line with " Worm" and the + * score if fewer than 18 columns; insufficient room for + * anything much if fewer than 5 lines. + */ + endwin(); + errx(1, "screen too small"); + } if (argc == 2) start_len = atoi(argv[1]); if ((start_len <= 0) || (start_len > ((LINES-3) * (COLS-2)) / 3)) @@ -225,7 +234,7 @@ newpos(bp) struct body * bp; { do { - bp->y = rnd(LINES-3)+ 2; + bp->y = rnd(LINES-3)+ 1; bp->x = rnd(COLS-3) + 1; wmove(tv, bp->y, bp->x); } while(winch(tv) != ' '); @@ -311,7 +320,7 @@ process(ch) prize(); score += growing; running = 0; - wmove(stw, 0, 68); + wmove(stw, 0, COLS - 12); wprintw(stw, "Score: %3d", score); wrefresh(stw); } -- cgit v1.2.3-56-ge451