summaryrefslogtreecommitdiff
path: root/games/battlestar/fly.c
diff options
context:
space:
mode:
Diffstat (limited to 'games/battlestar/fly.c')
-rw-r--r--games/battlestar/fly.c279
1 files changed, 135 insertions, 144 deletions
diff --git a/games/battlestar/fly.c b/games/battlestar/fly.c
index 1139e80fe02..b40034b1da3 100644
--- a/games/battlestar/fly.c
+++ b/games/battlestar/fly.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fly.c,v 1.5 1997/12/16 07:54:25 angelos Exp $ */
+/* $OpenBSD: fly.c,v 1.6 1998/09/13 01:30:32 pjanzen Exp $ */
/* $NetBSD: fly.c,v 1.3 1995/03/21 15:07:28 cgd Exp $ */
/*
@@ -38,11 +38,10 @@
#if 0
static char sccsid[] = "@(#)fly.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: fly.c,v 1.3 1995/03/21 15:07:28 cgd Exp $";
+static char rcsid[] = "$OpenBSD: fly.c,v 1.6 1998/09/13 01:30:32 pjanzen Exp $";
#endif
#endif /* not lint */
-#include <unistd.h>
#include "extern.h"
#undef UP
#include <curses.h>
@@ -51,24 +50,17 @@ static char rcsid[] = "$NetBSD: fly.c,v 1.3 1995/03/21 15:07:28 cgd Exp $";
#define MIDR (LINES/2 - 1)
#define MIDC (COLS/2 - 1)
-int row, column;
-int dr = 0, dc = 0;
-char destroyed;
-int bclock = 120; /* time for all the flights in the game */
-char cross = 0;
-sig_t oldsig;
-
-void blast __P((void));
-void endfly __P((void));
-void moveenemy __P((int));
-void notarget __P((void));
-void screen __P((void));
-void succumb __P((int));
-void target __P((void));
+int row, column;
+int dr = 0, dc = 0;
+char destroyed;
+int ourclock = 120; /* time for all the flights in the game */
+char cross = 0;
+sig_t oldsig;
+
void
succumb(sigraised)
-int sigraised;
+ int sigraised;
{
if (oldsig == SIG_DFL) {
endfly();
@@ -84,105 +76,103 @@ int
visual()
{
destroyed = 0;
- if(initscr() == NULL){
+ if (initscr() == NULL) {
puts("Whoops! No more memory...");
- return(0);
+ return (0);
}
oldsig = signal(SIGINT, succumb);
crmode();
noecho();
screen();
- row = rnd(LINES-3) + 1;
- column = rnd(COLS-2) + 1;
+ row = rnd(LINES - 3) + 1;
+ column = rnd(COLS - 2) + 1;
moveenemy(0);
for (;;) {
- switch(getchar()){
-
- case 'h':
- case 'r':
- dc = -1;
- fuel--;
- break;
-
- case 'H':
- case 'R':
- dc = -5;
- fuel -= 10;
- break;
-
- case 'l':
- dc = 1;
- fuel--;
- break;
-
- case 'L':
- dc = 5;
- fuel -= 10;
- break;
-
- case 'j':
- case 'u':
- dr = 1;
- fuel--;
- break;
-
- case 'J':
- case 'U':
- dr = 5;
- fuel -= 10;
- break;
-
- case 'k':
- case 'd':
- dr = -1;
- fuel--;
- break;
-
- case 'K':
- case 'D':
- dr = -5;
- fuel -= 10;
- break;
-
- case '+':
- if (cross){
- cross = 0;
- notarget();
- }
- else
- cross = 1;
- break;
-
- case ' ':
- case 'f':
- if (torps){
- torps -= 2;
- blast();
- if (row == MIDR && column - MIDC < 2 && MIDC - column < 2){
- destroyed = 1;
- alarm(0);
- }
+ switch (getchar()) {
+
+ case 'h':
+ case 'r':
+ dc = -1;
+ fuel--;
+ break;
+
+ case 'H':
+ case 'R':
+ dc = -5;
+ fuel -= 10;
+ break;
+
+ case 'l':
+ dc = 1;
+ fuel--;
+ break;
+
+ case 'L':
+ dc = 5;
+ fuel -= 10;
+ break;
+
+ case 'j':
+ case 'u':
+ dr = 1;
+ fuel--;
+ break;
+
+ case 'J':
+ case 'U':
+ dr = 5;
+ fuel -= 10;
+ break;
+
+ case 'k':
+ case 'd':
+ dr = -1;
+ fuel--;
+ break;
+
+ case 'K':
+ case 'D':
+ dr = -5;
+ fuel -= 10;
+ break;
+
+ case '+':
+ if (cross) {
+ cross = 0;
+ notarget();
+ } else
+ cross = 1;
+ break;
+
+ case ' ':
+ case 'f':
+ if (torps) {
+ torps -= 2;
+ blast();
+ if (row == MIDR && column - MIDC < 2 && MIDC - column < 2) {
+ destroyed = 1;
+ alarm(0);
}
- else
- mvaddstr(0,0,"*** Out of torpedoes. ***");
- break;
+ } else
+ mvaddstr(0, 0, "*** Out of torpedoes. ***");
+ break;
- case 'q':
- endfly();
- return(0);
+ case 'q':
+ endfly();
+ return (0);
- default:
- mvaddstr(0,26,"Commands = r,R,l,L,u,U,d,D,f,+,q");
- continue;
+ default:
+ mvaddstr(0, 26, "Commands = r,R,l,L,u,U,d,D,f,+,q");
+ continue;
- case EOF:
- break;
+ case EOF:
+ break;
}
- if (destroyed){
+ if (destroyed) {
endfly();
- return(1);
+ return (1);
}
- if (bclock <= 0){
+ if (ourclock <= 0) {
endfly();
die(0);
}
@@ -192,63 +182,63 @@ visual()
void
screen()
{
- register int r,c,n;
- int i;
+ int r, c, n;
+ int i;
clear();
i = rnd(100);
- for (n=0; n < i; n++){
- r = rnd(LINES-3) + 1;
+ for (n = 0; n < i; n++) {
+ r = rnd(LINES - 3) + 1;
c = rnd(COLS);
mvaddch(r, c, '.');
}
- mvaddstr(LINES-1-1,21,"TORPEDOES FUEL TIME");
+ mvaddstr(LINES - 1 - 1, 21, "TORPEDOES FUEL TIME");
refresh();
}
void
target()
{
- register int n;
+ int n;
- move(MIDR,MIDC-10);
+ move(MIDR, MIDC - 10);
addstr("------- + -------");
- for (n = MIDR-4; n < MIDR-1; n++){
- mvaddch(n,MIDC,'|');
- mvaddch(n+6,MIDC,'|');
+ for (n = MIDR - 4; n < MIDR - 1; n++) {
+ mvaddch(n, MIDC, '|');
+ mvaddch(n + 6, MIDC, '|');
}
}
void
notarget()
{
- register int n;
+ int n;
- move(MIDR,MIDC-10);
+ move(MIDR, MIDC - 10);
addstr(" ");
- for (n = MIDR-4; n < MIDR-1; n++){
- mvaddch(n,MIDC,' ');
- mvaddch(n+6,MIDC,' ');
+ for (n = MIDR - 4; n < MIDR - 1; n++) {
+ mvaddch(n, MIDC, ' ');
+ mvaddch(n + 6, MIDC, ' ');
}
}
void
blast()
{
- register int n;
+ int n;
alarm(0);
- move(LINES-1, 24);
+ move(LINES - 1, 24);
printw("%3d", torps);
- for(n = LINES-1-2; n >= MIDR + 1; n--){
- mvaddch(n, MIDC+MIDR-n, '/');
- mvaddch(n, MIDC-MIDR+n, '\\');
+ for(n = LINES - 1 - 2; n >= MIDR + 1; n--) {
+ mvaddch(n, MIDC + MIDR - n, '/');
+ mvaddch(n, MIDC - MIDR + n, '\\');
refresh();
}
- mvaddch(MIDR,MIDC,'*');
- for(n = LINES-1-2; n >= MIDR + 1; n--){
- mvaddch(n, MIDC+MIDR-n, ' ');
- mvaddch(n, MIDC-MIDR+n, ' ');
+ mvaddch(MIDR, MIDC, '*');
+ for (n = LINES - 1 - 2; n >= MIDR + 1; n--) {
+ mvaddch(n, MIDC + MIDR - n, ' ');
+ mvaddch(n, MIDC - MIDR + n, ' ');
refresh();
}
alarm(1);
@@ -256,38 +246,39 @@ blast()
void
moveenemy(sigraised)
-int sigraised;
+ int sigraised;
{
- double d;
- int oldr, oldc;
+ double d;
+ int oldr, oldc;
oldr = row;
oldc = column;
- if (fuel > 0){
- if (row + dr <= LINES-3 && row + dr > 0)
+ if (fuel > 0) {
+ if (row + dr <= LINES - 3 && row + dr > 0)
row += dr;
- if (column + dc < COLS-1 && column + dc > 0)
+ if (column + dc < COLS - 1 && column + dc > 0)
column += dc;
- } else if (fuel < 0){
- fuel = 0;
- mvaddstr(0,60,"*** Out of fuel ***");
- }
- d = (double) ((row - MIDR)*(row - MIDR) + (column - MIDC)*(column - MIDC));
- if (d < 16){
+ } else
+ if (fuel < 0) {
+ fuel = 0;
+ mvaddstr(0, 60, "*** Out of fuel ***");
+ }
+ d = (double) ((row - MIDR) * (row - MIDR) + (column - MIDC) * (column - MIDC));
+ if (d < 16) {
row += (rnd(9) - 4) % (4 - abs(row - MIDR));
column += (rnd(9) - 4) % (4 - abs(column - MIDC));
}
- bclock--;
+ ourclock--;
mvaddstr(oldr, oldc - 1, " ");
if (cross)
target();
mvaddstr(row, column - 1, "/-\\");
- move(LINES-1, 24);
+ move(LINES - 1, 24);
printw("%3d", torps);
- move(LINES-1, 42);
+ move(LINES - 1, 42);
printw("%3d", fuel);
- move(LINES-1, 57);
- printw("%3d", bclock);
+ move(LINES - 1, 57);
+ printw("%3d", ourclock);
refresh();
signal(SIGALRM, moveenemy);
alarm(1);
@@ -298,7 +289,7 @@ endfly()
{
alarm(0);
signal(SIGALRM, SIG_DFL);
- mvcur(0,COLS-1,LINES-1,0);
+ mvcur(0, COLS - 1, LINES - 1, 0);
endwin();
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
signal(SIGTSTP, SIG_DFL);