pjc@ptsfa.UUCP (Paul Condie) (07/28/86)
This is a robot game for Unix system V using curses.
Man page included.
{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pjc
------------------------- CUT HERE -----------------------
: This is a shar archive. Extract with sh, not csh.
: The rest of this file will extract:
: AppendNode.c ClrBoard.c DeleteNode.c GameBoard.c InsertNode.c Main.c TopTen.c define.h deleterbts.c dmpscore.c dress.c dumpstats.c getargs.c getdate.c gettops.c loadtops.c makefile modifylog.h moverbts.c moveyou.c printprg.sh robots.1 showrbts.c showscore.c showyou.c writetop.c
echo x - AppendNode.c
sed 's/^X//' >AppendNode.c <<'*-*-END-of-AppendNode.c-*-*'
X#include "define.h"
X
X#define NULL 0
X
XAppendNode (head, tail, size)
X
X ToptenNode *head, *tail;
X int size;
X{
X ToptenNode newnode;
X ToptenNode malloc();
X
X if ((newnode = malloc (size)) == NULL) return (-1);
X if (*tail == NULL)
X {
X *head = newnode;
X *tail = newnode;
X newnode->prev = NULL;
X newnode->next = NULL;
X }
X else
X {
X (*tail)->next = newnode;
X newnode->prev = *tail;
X newnode->next = NULL;
X *tail = newnode;
X }
X return (0);
X}
*-*-END-of-AppendNode.c-*-*
echo x - ClrBoard.c
sed 's/^X//' >ClrBoard.c <<'*-*-END-of-ClrBoard.c-*-*'
X#include <curses.h>
X#include "define.h"
X
XClrBoard ()
X{
X int row, col;
X
X for (row = 1; row <= MAXrows; row++)
X for (col = 1; col <= MAXcols; col++)
X {
X move (row, col);
X addch (' ');
X }
X refresh ();
X}
*-*-END-of-ClrBoard.c-*-*
echo x - DeleteNode.c
sed 's/^X//' >DeleteNode.c <<'*-*-END-of-DeleteNode.c-*-*'
X#include "define.h"
X
X#define NULL 0
X
XDeleteNode (node, head, tail)
X
X ToptenNode *head, *tail, node;
X{
X if (node == *head)
X *head = node->next;
X else
X node->prev->next = node->next;
X if (node == *tail)
X *tail = node->prev;
X else
X node->next->prev = node->prev;
X free (node);
X}
*-*-END-of-DeleteNode.c-*-*
echo x - GameBoard.c
sed 's/^X//' >GameBoard.c <<'*-*-END-of-GameBoard.c-*-*'
X#include <curses.h>
X#include "define.h"
X
XGameBoard (Manual)
X
X int Manual;
X{
X int row, col;
X
X attrset (A_REVERSE);
X for (row = 0; row <= MAXrows + 1; row++)
X {
X if (row == 0 || row == MAXrows + 1)
X for (col = 0; col <= MAXcols + 1; col++)
X {
X move (row, col);
X addch (BORDERCHAR);
X }
X else
X {
X move (row, 0);
X addch (BORDERCHAR);
X move (row, MAXcols + 1);
X addch (BORDERCHAR);
X }
X }
X move (0, (MAXcols+1)/2-2); addstr ("ROBOTS");
X move (23, (MAXcols+1)/2-1); addstr ("PJC");
X attrset (A_NORMAL);
X move (0, 66); addstr ("MOVE");
X move (2, 64); addstr (" 8 ");
X move (3, 64); addstr (" 7 9 ");
X move (4, 64); addstr (" 4 6");
X move (5, 64); addstr (" 1 3 ");
X move (6, 66); addstr (" 2 ");
X
X if (Manual)
X {
X move (10, 65); addstr ("COMMANDS");
X move (11, 63); addstr ("s - last stand");
X move (12, 63); addstr ("t - teleport");
X }
X
X move (14, 70); addstr ("KEY");
X move (15, 67); addch (YOU);
X move (15, 69); addstr ("-you");
X move (16, 67); addch (ROBOT);
X move (16, 69); addstr ("-robot");
X move (17, 67); addch (JUNKHEEP);
X move (17, 69); addstr ("-junk heep");
X move (20, 67); addstr ("SCREEN");
X move (21, 67); addstr ("ROBOTS");
X move (23, 63); addstr ("SCORE");
X move (0, 76); addstr (VERSION);
X refresh ();
X}
*-*-END-of-GameBoard.c-*-*
echo x - InsertNode.c
sed 's/^X//' >InsertNode.c <<'*-*-END-of-InsertNode.c-*-*'
X#include "define.h"
X
X#define NULL 0
X
X
XInsertNode (here, head, tail, size)
X
X ToptenNode *head, *tail, *here;
X int size;
X{
X ToptenNode newnode;
X ToptenNode malloc();
X
X
X if ((newnode = malloc (size)) == NULL) return (-1);
X newnode->prev = (*here)->prev;
X newnode->next = *here;
X (*here)->prev = newnode;
X if (*here == *head)
X *head = newnode;
X else
X newnode->prev->next = newnode;
X *here = newnode;
X return (0);
X}
*-*-END-of-InsertNode.c-*-*
echo x - Main.c
sed 's/^X//' >Main.c <<'*-*-END-of-Main.c-*-*'
X/* PROGRAM: Robots
X** AUTHOR: Paul J. Condie
X** DATE: 02/04/86
X*/
X#include "modifylog.h"
X
X#include <curses.h>
X#include "define.h"
X
X#define ENDSCREEN Rcount == 0
X
Xmain (argc, argv)
X
X int argc;
X char *argv[];
X{
X long time();
X void srand48();
X char *getlogin();
X long seed;
X char Todaysdate[9], player[10], TopTenFile[50];
X int Rbts[1000], Junks[1000], You;
X long score, TopScore, LastTop;
X int i, screens, rbtvalue, key, Rindex, row, col;
X int MUNCH, QUIT, DEBUG, DmpScore = FALSE, Manual = FALSE, LASTSTAND;
X
X initscr ();
X if (argc >= 2) getargs (argc, argv, &DmpScore, &Manual);
X if (Manual)
X strcpy (TopTenFile, TOPMANUAL);
X else
X strcpy (TopTenFile, TOPAUTO);
X if (DmpScore)
X {
X dmpscore (TopTenFile);
X endwin ();
X exit (0);
X }
X nonl ();
X cbreak ();
X noecho ();
X leaveok (stdscr, TRUE);
X typeahead (-1);
X getdate (Todaysdate);
X strcpy (player, getlogin());
X QUIT = FALSE;
X gettops (&TopScore, &LastTop, TopTenFile);
X seed = time ((long *) 0);
X srand48 (seed);
X
X/*
X** A NEW GAME
X*/
X
X do
X {
X MUNCH = FALSE;
X DEBUG = FALSE;
X screens = 0;
X score = 0;
X GameBoard (Manual);
X showscore (score, TopScore, LastTop, 0);
X
X/*
X** A NEW SCREEN
X*/
X
X do
X {
X LASTSTAND = FALSE;
X screens++;
X Rcount = Jcount = 0;
X Rindex = 0;
X showrbts (screens, &rbtvalue, Rbts);
X showyou (&You, Rbts);
X key = getch ();
X if ((key >= '1' && key <= '9' && key != '5') ||
X (Manual && (key == 's' || key == 't')))
X MUNCH = moveyou (key, &You, Rbts, Junks, &LASTSTAND);
X if (!Manual) nodelay (stdscr, TRUE);
X
X/*
X** GO MAN GO
X*/
X
X while (!MUNCH && !ENDSCREEN)
X {
X if (Manual)
X for (Rindex = 0; Rindex < Rcount;)
X {
X MUNCH = moverbts (&Rindex, Rbts, Junks, You, &score, rbtvalue,
X TopScore, LastTop);
X if (MUNCH) break;
X }
X else
X MUNCH = moverbts (&Rindex, Rbts, Junks, You, &score, rbtvalue,
X TopScore, LastTop);
X refresh ();
X if (MUNCH || ENDSCREEN || LASTSTAND) continue;
Xdebug:
X key = getch ();
X if ((key >= '1' && key <= '9' && key != '5') ||
X (Manual && (key == 's' || key == 't')))
X MUNCH = moveyou (key, &You, Rbts, Junks, &LASTSTAND);
X };
X if (!Manual) nodelay (stdscr, FALSE);
X flushinp ();
X } while (!MUNCH);
X
X getxy (You, row, col);
X if (col > MAXcols - 4) col = MAXcols - 4;
X move (row, col);
X addstr ("MUNCH");
X refresh ();
X sleep (4);
X QUIT = TopTen (player, Todaysdate, score, screens, &TopScore, &LastTop,
X &DEBUG, TopTenFile);
X if (DEBUG)
X {
X char command[80];
X
X QUIT = dumpstats (You, Rbts, Junks, score, screens, rbtvalue,
X TopScore, LastTop);
X sprintf (command, "lp -s %s", DEBUGFILE);
X system (command);
X MUNCH = FALSE;
X ClrBoard ();
X for (i = 1; i <= Rcount; i++)
X {
X getxy (Rbts[i], row, col);
X move (row, col);
X addch (ROBOT);
X }
X for (i = 1; i <= Jcount; i++)
X {
X getxy (Junks[i], row, col);
X move (row, col);
X addch (JUNKHEEP);
X }
X getxy (You, row, col);
X move (row, col);
X addch (YOU);
X refresh ();
X goto debug;
X }
X } while (!QUIT);
X
X endwin ();
X}
*-*-END-of-Main.c-*-*
echo x - TopTen.c
sed 's/^X//' >TopTen.c <<'*-*-END-of-TopTen.c-*-*'
X#include <curses.h>
X#include "define.h"
X
X
XTopTen (player, Tdate, score, screens, TopScore, LastTop, DEBUG, TopTenFile)
X
X char player[], Tdate[], TopTenFile[];
X long score, *TopScore, *LastTop;
X int screens, *DEBUG;
X{
X FILE *fopen();
X FILE *fp;
X ToptenNode head, tail, here, YourNode;
X int i, key, rc, you, rank;
X char tmpstr[10], fmtscore[10];
X
X ClrBoard ();
X head = tail = NULL;
X
X/*
X** First load top ten file if there is one.
X*/
X
X if ((fp = fopen (TopTenFile, "r")) != NULL)
X if ((rc = loadtops (fp, &head, &tail)) != 0)
X {
X move (5, 4);
X addstr ("ERROR: Ran out of memory loading Top Ten list.");
X goto EXIT;
X }
X
X/*
X** Now find the right spot to put your score.
X*/
X
X for (here = head, you = 1; here != NULL && score <= here->tdata.score;
X here = here->next, you++);
X if (here == NULL)
X {
X if (AppendNode (&head, &tail, sizeof (struct topten)) != 0)
X {
X move (5, 4);
X addstr ("ERROR: Ran out of memory loading Top Ten list.");
X goto EXIT;
X }
X YourNode = tail;
X }
X else
X {
X if (InsertNode (&here, &head, &tail, sizeof (struct topten)) != 0)
X {
X move (5, 4);
X addstr ("ERROR: Ran out of memory loading Top Ten list.");
X goto EXIT;
X }
X YourNode = here;
X }
X strcpy (YourNode->tdata.name, player);
X YourNode->tdata.score = score;
X strcpy (YourNode->tdata.date, Tdate);
X YourNode->tdata.screen = screens;
X
X/*
X** Now write the top ten file out if there was a change.
X*/
X
X fclose (fp);
X if (you <= ENTRYMAX && *DEBUG == FALSE)
X if ((fp = fopen (TopTenFile, "w")) != NULL)
X {
X writetop (fp, head, tail);
X fclose (fp);
X }
X else
X {
X move (5,10);
X addstr ("ERROR: Unable to open top file for writing.");
X refresh ();
X }
X
X/*
X** Now display top ten.
X*/
X
X move (2, (MAXcols+1)/2-4);
X attrset (A_BOLD);
X addstr ("TOP TEN");
X attrset (A_NORMAL);
X if (strcmp (TopTenFile, TOPMANUAL) == 0)
X {
X move (1, 1); addstr ("Manual");
X move (2, 1); addstr ("Mode");
X }
X else
X {
X move (1, MAXcols-8); addstr ("Automatic");
X move (2, MAXcols-3); addstr ("Fire");
X }
X for (here = head, i = 1; here != NULL && i <= 10; here = here->next, i++)
X {
X if (YourNode == here) attrset (A_REVERSE);
X sprintf (tmpstr, "%7ld", here->tdata.score);
X if (here->tdata.score < 1000)
X strcpy (fmtscore, tmpstr);
X else
X if (here->tdata.score >= 1000 && here->tdata.score < 1000000)
X dress (fmtscore, tmpstr, "9999,999");
X else
X dress (fmtscore, tmpstr, "9,999,999");
X move (i+3, (MAXcols+1)/2-23);
X printw (" %3d. %-8s %9s %8s %3d ", i, here->tdata.name, fmtscore,
X here->tdata.date, here->tdata.screen);
X if (YourNode == here) attrset (A_NORMAL);
X *LastTop = here->tdata.score;
X }
X
X if (you > 10 && you <= ENTRYMAX)
X {
X for (here = YourNode->prev, i = 1, rank = you - 1;
X here != NULL && i <= 3; here = here->next, i++, rank++)
X {
X if (YourNode == here) attrset (A_REVERSE);
X sprintf (tmpstr, "%7ld", here->tdata.score);
X if (here->tdata.score < 1000)
X strcpy (fmtscore, tmpstr);
X else
X if (here->tdata.score >= 1000 && here->tdata.score < 1000000)
X dress (fmtscore, tmpstr, "9999,999");
X else
X dress (fmtscore, tmpstr, "9,999,999");
X move (i+15, (MAXcols+1)/2-23);
X printw (" %3d. %-8s %9s %8s %3d ", rank, here->tdata.name,
X fmtscore, here->tdata.date, here->tdata.screen);
X if (YourNode == here) attrset (A_NORMAL);
X }
X }
X refresh ();
X
X
X *TopScore = head->tdata.score;
X for (here = head; here != NULL; here = here->next)
X DeleteNode (here, &head, &tail);
X
X
XEXIT:
X move (21, (MAXcols+1)/2-4); addstr ("QUIT ? ");
X refresh ();
X sleep (1);
X flushinp ();
X key = getch ();
X if (key == 'y' || key == 'Y') return (TRUE);
X if (key == 'D' && strcmp (player, THEMAN) == 0) *DEBUG = TRUE;
X return (FALSE);
X}
*-*-END-of-TopTen.c-*-*
echo x - define.h
sed 's/^X//' >define.h <<'*-*-END-of-define.h-*-*'
X#define VERSION "V3.0"
X
X#define THEMAN "pjc"
X#define BORDERCHAR ' '
X#define YOU 'I'
X#define ROBOT '#'
X#define JUNKHEEP '@'
X
X#define MAXrows 22
X#define MAXcols 58
X
X#define Rcount Rbts[0]
X#define Jcount Junks[0]
X
X#define DEBUGFILE "/usr/games/lib/robots.debug"
X#define TOPAUTO "/usr/games/lib/robots.log"
X#define TOPMANUAL "/usr/games/lib/robot.log"
X#define ENTRYMAX 100
X#define INCREMENT 20 /* robots per screen */
X
X#define getloc(r, c, l) l = ((r - 1) * MAXcols) + c;
X#define getxy(l, r, c) r = l / MAXcols; \
X if (l % MAXcols != 0) (r)++; \
X c = l - ((r - 1) * MAXcols);
X
X
X struct TopInfo
X {
X char name [10];
X char date [9];
X int screen;
X long score;
X };
X
X typedef struct topten
X {
X struct topten *prev;
X struct topten *next;
X struct TopInfo tdata;
X } *ToptenNode;
*-*-END-of-define.h-*-*
echo x - deleterbts.c
sed 's/^X//' >deleterbts.c <<'*-*-END-of-deleterbts.c-*-*'
X#include "define.h"
X
Xdeleterbts (Rbts, argone, argtwo)
X
X int Rbts[], argone, argtwo;
X{
X register int i;
X int tmpint;
X
X if (argone > argtwo && argtwo > 0)
X {
X tmpint = argtwo;
X argtwo = argone;
X argone = tmpint;
X }
X if (argtwo > 0)
X {
X for (i = argtwo; i < Rcount; i++)
X Rbts[i] = Rbts[i+1];
X Rcount--;
X }
X if (argone > 0)
X {
X for (i = argone; i < Rcount; i++)
X Rbts[i] = Rbts[i+1];
X Rcount--;
X }
X}
*-*-END-of-deleterbts.c-*-*
echo x - dmpscore.c
sed 's/^X//' >dmpscore.c <<'*-*-END-of-dmpscore.c-*-*'
X#include <stdio.h>
X#include "define.h"
X
Xdmpscore (TopTenFile)
X
X char TopTenFile[];
X{
X FILE *fopen(), *fp;
X ToptenNode head, tail, here;
X char fmtscore[10], tmpstr[10];
X int i, rc;
X
X head = tail = NULL;
X if ((fp = fopen (TopTenFile, "r")) != NULL)
X {
X if ((rc = loadtops (fp, &head, &tail)) != 0)
X {
X fprintf (stderr, "ERROR: Ran out of memory loading Top Ten list.");
X return;
X }
X }
X else
X {
X fprintf (stderr, "ERROR: Unable to open Top Ten file.");
X return;
X }
X fclose (fp);
X
X printf ("\n **** ROBOTS **** %s\n", VERSION);
X if (strcmp (TopTenFile, TOPMANUAL) == 0)
X printf ("\n Manual Mode\n");
X else
X printf ("\n Repeating Rifle Mode\n");
X for (here = head, i = 1; here != NULL; here = here->next, i++)
X {
X sprintf (tmpstr, "%7ld", here->tdata.score);
X if (here->tdata.score < 1000)
X strcpy (fmtscore, tmpstr);
X else
X if (here->tdata.score >= 1000 && here->tdata.score < 1000000)
X dress (fmtscore, tmpstr, "9999,999");
X else
X dress (fmtscore, tmpstr, "9,999,999");
X printf ("\n%3d. %s %s %2d %9s", i, here->tdata.name, here->tdata.date,
X here->tdata.screen, fmtscore);
X }
X printf ("\n");
X}
*-*-END-of-dmpscore.c-*-*
echo x - dress.c
sed 's/^X//' >dress.c <<'*-*-END-of-dress.c-*-*'
Xdress (destination, source, mask)
X
X char *destination, *source, *mask;
X{
X for (;*mask != '\0'; mask++, destination++)
X {
X if (*mask == '9')
X {
X if (*source != '\0')
X {
X *destination = *source;
X source++;
X }
X else
X *destination = ' ';
X }
X else
X {
X *destination = *mask;
X }
X }
X *destination = '\0';
X}
*-*-END-of-dress.c-*-*
echo x - dumpstats.c
sed 's/^X//' >dumpstats.c <<'*-*-END-of-dumpstats.c-*-*'
X#include <curses.h>
X#include "define.h"
X
Xdumpstats (You, Rbts, Junks, score, screens, rbtvalue, TopScore, LastTop)
X
X int You, Rbts[], Junks[], screens, rbtvalue;
X long score, TopScore, LastTop;
X{
X FILE *fopen();
X FILE *fp;
X int i, row, col;
X
X if ((fp = fopen (DEBUGFILE, "w")) == NULL) return (TRUE);
X
X fprintf (fp, "\nscore = %ld", score);
X fprintf (fp, "\nscreens = %d", screens);
X fprintf (fp, "\nrbtvalue = %d", rbtvalue);
X fprintf (fp, "\nTopScore = %ld", TopScore);
X fprintf (fp, "\nLastTop = %ld", LastTop);
X
X getxy (You, row, col);
X fprintf (fp, "\n\nYOU\t%d\t%d\t%d", You, row, col);
X
X fprintf (fp, "\n\n*** ROBOTS ***");
X for (i = 1; i <= Rcount; i++)
X {
X getxy (Rbts[i], row, col);
X fprintf (fp, "\n%d\t%d\t%d\t%d", i, Rbts[i], row, col);
X }
X
X fprintf (fp, "\n\n*** JUNK HEEPS ***");
X for (i = 1; i <= Jcount; i++)
X {
X getxy (Junks[i], row, col);
X fprintf (fp, "\n%d\t%d\t%d\t%d", i, Junks[i], row, col);
X }
X fclose (fp);
X return (FALSE);
X}
*-*-END-of-dumpstats.c-*-*
echo x - getargs.c
sed 's/^X//' >getargs.c <<'*-*-END-of-getargs.c-*-*'
X#include <curses.h>
X
Xgetargs (argc, argv, DmpScore, Manual)
X
X int argc, *DmpScore, *Manual;
X char *argv[];
X{
X char *Program, *s;
X
X Program = argv[0];
X while (--argc > 0 && (*++argv)[0] == '-')
X for (s = argv[0]+1; *s != '\0'; s++)
X switch (*s)
X {
X case 'm':
X *Manual = TRUE;
X break;
X case 's':
X *DmpScore = TRUE;
X break;
X
X default:
X fprintf (stderr, "\nUsage: %s [ -m ] [ -s ]", Program);
X exit (1);
X }
X}
*-*-END-of-getargs.c-*-*
echo x - getdate.c
sed 's/^X//' >getdate.c <<'*-*-END-of-getdate.c-*-*'
X#include <sys/types.h>
X#include <time.h>
X
X
Xgetdate (DATE)
X
X char DATE[];
X{
X long secs;
X register struct tm *tp;
X struct tm *localtime();
X
X time (&secs);
X tp = localtime(&secs);
X sprintf (DATE,"%.2d/%.2d/%.2d", tp->tm_mon+1, tp->tm_mday, tp->tm_year);
X}
*-*-END-of-getdate.c-*-*
echo x - gettops.c
sed 's/^X//' >gettops.c <<'*-*-END-of-gettops.c-*-*'
X#include <stdio.h>
X#include "define.h"
X
X
Xgettops (TopScore, LastTop, TopTenFile)
X
X long *TopScore, *LastTop;
X char TopTenFile[];
X{
X FILE *fopen();
X FILE *fp;
X struct TopInfo tbuf;
X int count;
X
X *TopScore = *LastTop = 0;
X if ((fp = fopen (TopTenFile, "r")) == NULL) return;
X count = 0;
X while (fread ((char *) &tbuf, sizeof (struct TopInfo), 1, fp))
X {
X count++;
X if (count == 1) *TopScore = tbuf.score;
X if (count == 10)
X {
X *LastTop = tbuf.score;
X break;
X }
X }
X fclose (fp);
X}
*-*-END-of-gettops.c-*-*
echo x - loadtops.c
sed 's/^X//' >loadtops.c <<'*-*-END-of-loadtops.c-*-*'
X#include <stdio.h>
X#include "define.h"
X
X#define NEWNODE (*tail)->tdata
X
Xloadtops (fp, head, tail)
X
X FILE *fp;
X ToptenNode *head, *tail;
X{
X struct TopInfo tbuf;
X ToptenNode here, node;
X int rc;
X
X rc = fread ((char *) &tbuf, sizeof (struct TopInfo), 1, fp);
X while (rc)
X {
X for (here = *head; here != NULL && tbuf.score <= here->tdata.score;
X here = here->next);
X if (here == NULL)
X {
X if (AppendNode (head, tail, sizeof (struct topten)) != 0)
X return (-1);
X node = *tail;
X }
X else
X {
X if (InsertNode (&here, head, tail, sizeof (struct topten)) != 0)
X return (-1);
X node = here;
X }
X strcpy (node->tdata.name, tbuf.name);
X node->tdata.score = tbuf.score;
X strcpy (node->tdata.date, tbuf.date);
X node->tdata.screen = tbuf.screen;
X rc = fread ((char *) &tbuf, sizeof (struct TopInfo), 1, fp);
X }
X return (0);
X}
*-*-END-of-loadtops.c-*-*
echo x - makefile
sed 's/^X//' >makefile <<'*-*-END-of-makefile-*-*'
XFILES = makefile Main.c GameBoard.c showrbts.c showyou.c ClrBoard.c \
X showscore.c moveyou.c moverbts.c deleterbts.c \
X getdate.c TopTen.c dress.c loadtops.c AppendNode.c \
X InsertNode.c DeleteNode.c writetop.c gettops.c dumpstats.c \
X getargs.c dmpscore.c
XOBJECTS = Main.o GameBoard.o showrbts.o showyou.o ClrBoard.o \
X showscore.o moveyou.o moverbts.o deleterbts.o \
X getdate.o TopTen.o dress.o loadtops.o AppendNode.o \
X InsertNode.o DeleteNode.o writetop.o gettops.o dumpstats.o \
X getargs.o dmpscore.o
XLIBS = -lcurses -lc -lm
XCFLAGS = -f -ns -O
XCOPIES = 1
XTITLE = "ROBOTS"
X
Xrobots: $(OBJECTS)
X cc $(CFLAGS) $(OBJECTS) $(LIBS) -o robots
X size robots
X @echo
X
Xprint: $(FILES)
X pr -f $? | lp -n$(COPIES) -t$(TITLE)
X touch print
X
Xcleanup:
X -rm *.o
X -du
X
XMain.o: Main.c define.h modifylog.h
XGameBoard.o: GameBoard.c define.h
Xshowrbts.o: showrbts.c define.h
Xshowyou.o: showyou.c define.h
XClrBoard.o: ClrBoard.c define.h
Xmoveyou.o: moveyou.c define.h
Xmoverbts.o: moverbts.c define.h
Xdeleterbts.o: deleterbts.c define.h
XTopTen.o: TopTen.c define.h
Xloadtops.o: loadtops.c define.h
Xwritetop.o: writetop.c define.h
Xgettops.o: gettops.c define.h
XAppendNode.o: AppendNode.c define.h
XInsertNode.o: InsertNode.c define.h
XDeleteNode.o: DeleteNode.c define.h
Xdumpstats.o: dumpstats.c define.h
Xdmpscore.o: dmpscore.c define.h
*-*-END-of-makefile-*-*
echo x - modifylog.h
sed 's/^X//' >modifylog.h <<'*-*-END-of-modifylog.h-*-*'
X/*
X** ***** M O D I F I C A T I O N L O G *****
X**
X**
X** Version 2.0 - Features
X**
X** 1. Robots will be incremented by 20 instead of 10 for each
X** new screen.
X** 2. If your score is in topten score will blink.
X** 3. If your score is the new top high score will be in reverse
X** video.
X** 4. Robot count will reflect the # of robots currently on the screen.
X
X
X** Version 2.1 pjc 7/10/86
X**
X** 1. Dump robots log file scores with $ robots -s
X
X
X** Version 3.0 pjc 7/25/86
X**
X** 1. Manual Mode robot game. robots -m
X*/
*-*-END-of-modifylog.h-*-*
echo x - moverbts.c
sed 's/^X//' >moverbts.c <<'*-*-END-of-moverbts.c-*-*'
X#include <curses.h>
X#include "define.h"
X
Xmoverbts(Rindex, Rbts, Junks, You, score, rbtvalue, TopScore, LastTop)
X
X int *Rindex;
X int Rbts[], Junks[], You;
X long *score, TopScore, LastTop;
X int rbtvalue;
X{
X register int i;
X int Rrow, Rcol, Yrow, Ycol, newloc;
X
X (*Rindex)++;
X if (*Rindex > Rcount) *Rindex = 1;
X getxy (Rbts[*Rindex], Rrow, Rcol);
X move (Rrow, Rcol); addch (' '); /* blank old location */
X getxy (You, Yrow, Ycol);
X if (Rrow > Yrow) Rrow--;
X if (Rrow < Yrow) Rrow++;
X if (Rcol > Ycol) Rcol--;
X if (Rcol < Ycol) Rcol++;
X getloc (Rrow, Rcol, newloc);
X move (Rrow, Rcol);
X switch (winch (stdscr))
X {
X default:
X/*
X** ok nothing is sitting in
X** new location
X*/
X Rbts[*Rindex] = newloc;
X addch (ROBOT);
X return (FALSE);
X
X case ROBOT:
X/*
X Now check for a robot
X sitting in new location */
X
X for (i = 1; i <= Rcount; i++)
X if (newloc == Rbts[i])
X {
X *score += rbtvalue * 2;
X deleterbts (Rbts, i, *Rindex); /* delete both rbts from pile */
X (*Rindex)--;
X if (i < *Rindex) (*Rindex)--;
X Junks[++Jcount] = newloc; /* add new loc to junk pile */
X addch (JUNKHEEP); /* new junk heep */
X showscore (*score, TopScore, LastTop, Rcount);
X return (FALSE);
X }
X
X case JUNKHEEP:
X *score += rbtvalue;
X deleterbts (Rbts, *Rindex, NULL); /* delete robot from pile */
X (*Rindex)--;
X showscore (*score, TopScore, LastTop, Rcount);
X return (FALSE);
X
X case YOU:
X return (TRUE); /* MUNCHED */
X
X }
X}
*-*-END-of-moverbts.c-*-*
echo x - moveyou.c
sed 's/^X//' >moveyou.c <<'*-*-END-of-moveyou.c-*-*'
X#include <curses.h>
X#include "define.h"
X
Xmoveyou (key, You, Rbts, Junks, LASTSTAND)
X
X int key, *You, Rbts[], Junks[], *LASTSTAND;
X{
X int row, col, newrow, newcol, oldlocation;
X char MUNCH;
X register int i;
X
X
X oldlocation = *You;
X getxy (*You, row, col);
X newrow = row;
X newcol = col;
X switch (key)
X {
X case '8':
X case KEY_UP:
X if (newrow > 1) newrow--;
X break;
X
X case '9':
X case KEY_A3:
X if (newrow > 1) newrow--;
X if (newcol < MAXcols) newcol++;
X break;
X
X case '6':
X case KEY_RIGHT:
X if (newcol < MAXcols) newcol++;
X break;
X
X case '3':
X case KEY_C3:
X if (newrow < MAXrows) newrow++;
X if (newcol < MAXcols) newcol++;
X break;
X
X case '2':
X case KEY_DOWN:
X if (newrow < MAXrows) newrow++;
X break;
X
X case '1':
X case KEY_C1:
X if (newrow < MAXrows) newrow++;
X if (newcol > 1) newcol--;
X break;
X
X case '4':
X case KEY_LEFT:
X if (newcol > 1) newcol--;
X break;
X
X case '7':
X case KEY_A1:
X if (newrow > 1) newrow--;
X if (newcol > 1) newcol--;
X break;
X
X case 's':
X *LASTSTAND = TRUE;
X break;
X
X case 't':
X showyou (You, Rbts);
X getxy (*You, newrow, newcol);
X break;
X
X default:
X break;
X }
X
X move (row, col); addch (' ');
X move (newrow, newcol);
X i = winch (stdscr);
X if (i == ROBOT || i == JUNKHEEP) return (TRUE);
X getloc (newrow, newcol, *You);
X addch (YOU);
X refresh ();
X return (FALSE);
X}
*-*-END-of-moveyou.c-*-*
echo x - printprg.sh
sed 's/^X//' >printprg.sh <<'*-*-END-of-printprg.sh-*-*'
Xpr makefile > junk.listing;echo "\f\c" >> junk.listing
Xcb Main.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb moveyou.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb moverbts.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb showrbts.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb showyou.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb GameBoard.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb ClrBoard.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb showscore.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb deleterbts.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb TopTen.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb loadtops.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb writetop.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb gettops.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb AppendNode.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb InsertNode.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb DeleteNode.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb dress.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb getdate.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb dumpstats.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb dmpscore.c >> junk.listing;echo "\f\c" >> junk.listing
Xcb getargs.c >> junk.listing;echo "\f\c" >> junk.listing
Xcat define.h >> junk.listing;echo "\f\c" >> junk.listing
Xcat modifylog.h >> junk.listing;echo "\f\c" >> junk.listing
Xcat junk.listing | lp
*-*-END-of-printprg.sh-*-*
echo x - robots.1
sed 's/^X//' >robots.1 <<'*-*-END-of-robots.1-*-*'
X.TH ROBOTS public
X.SH NAME
Xrobots \- an action packed (edge of your toilet seat) game
X.SH SYNOPSIS
Xrobots [ -m ] [ -s ]
X.SH DESCRIPTION
XRobots is a display oriented game that requires hand, feet
Xand eye coordination ?? This is a game I used to play on a dual
Xunix-like machine until they took it away. So out of addiction,
Xrobots system V was born. The curses(3x) screen management
Xlibrary is used to handle the display so you must set your TERM
Xenvironment variable.
X
XThe idea is to avoid the moving robots by either running away
Xfrom the little buggers or by hiding behind the junk heeps that
Xare created when two or more robots run into each other.
X
XThere are two modes of operation (Automatic and Manual mode).
XThe automatic mode (which is the default) is for those who have
Xthe need ... for speed (recommended only at 9600 baud).
X.SS OPTIONS
X.P
X-m manual mode. This is more of a strategy game.
X Recommended operation for bods lower than 9600.
X.P
X-s will print to stdout the log file containing the
X top one hundred scores.
X.SH SCORING
XYou get points when a robot gets turned into a junk heep.
XScreen one starts out with twenty robots and each screen
Xafter that is incremented by twenty robots. Also the value
Xof each robot is incremented with each screen. Your score
Xwill start blinking when you have made the Top Ten list and
Xturn to reverse video when you make top gun.
X.SH FILES
X/usr/games/lib/robots.log automatic mode score sheet
X/usr/games/lib/robot.log manual mode score sheet
X/usr/games/lib/robots.debug debug stats
X.SH AUTHOR
XPaul J. Condie
X.SH COMPLAINT/SUGGESTION BOX
X{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pjc
X.SH BUGS
XNone known.
*-*-END-of-robots.1-*-*
echo x - showrbts.c
sed 's/^X//' >showrbts.c <<'*-*-END-of-showrbts.c-*-*'
X#include <curses.h>
X#include "define.h"
X
Xshowrbts (screens, rbtvalue, Rbts)
X
X int screens, *rbtvalue;
X int Rbts[];
X{
X double drand48();
X int i, ii, row, col, randomnum;
X int UNIQUE;
X char tmpstr[10];
X
X ClrBoard ();
X Rcount = *rbtvalue = screens * INCREMENT;
X for (i = 1; i <= Rcount + 1; i++)
X Rbts[i] = 0;
X sprintf (tmpstr, "%4d", screens);
X move (20, 74);
X addstr (tmpstr);
X sprintf (tmpstr, "%4d", Rcount);
X move (21, 74);
X addstr (tmpstr);
X for (i = 1; i <= Rcount; i++)
X {
X do
X {
X UNIQUE = FALSE;
X randomnum = (int)(drand48() * 10000) % (MAXrows * MAXcols + 1);
X if (randomnum < 1 || randomnum > MAXrows * MAXcols) continue;
X UNIQUE = TRUE;
X for (ii = 1; ii < i; ii++)
X if (randomnum == Rbts[ii])
X {
X UNIQUE = FALSE;
X break;
X }
X } while (!UNIQUE);
X Rbts[i] = randomnum;
X getxy (randomnum, row, col);
X move (row, col);
X addch (ROBOT);
X refresh ();
X }
X}
*-*-END-of-showrbts.c-*-*
echo x - showscore.c
sed 's/^X//' >showscore.c <<'*-*-END-of-showscore.c-*-*'
X#include <curses.h>
X
Xshowscore (score, TopScore, LastTop, robots)
X
X long score, TopScore, LastTop;
X int robots;
X{
X char tmpstr[10], fmtscore[10];
X
X
X sprintf (tmpstr, "%4d", robots);
X move (21, 74); addstr (tmpstr);
X sprintf (tmpstr, "%7ld", score);
X if (score < 1000)
X strcpy (fmtscore, tmpstr);
X else
X if (score >= 1000 && score < 1000000)
X dress (fmtscore, tmpstr, "9999,999");
X else
X dress (fmtscore, tmpstr, "9,999,999");
X move (23, 69);
X if (score <= LastTop) attrset (A_BOLD);
X else
X if (score > TopScore) attrset (A_REVERSE);
X else
X attrset (A_BLINK);
X printw ("%9s", fmtscore);
X attrset (A_NORMAL);
X}
*-*-END-of-showscore.c-*-*
echo x - showyou.c
sed 's/^X//' >showyou.c <<'*-*-END-of-showyou.c-*-*'
X#include <curses.h>
X#include "define.h"
X
Xshowyou (You, Rbts)
X
X int *You;
X int Rbts[];
X{
X double drand48();
X int i, rnum, row, col;
X int UNIQUE;
X
X
X do
X {
X UNIQUE = FALSE;
X rnum = (int)(drand48() * 10000) % (MAXrows * MAXcols + 1);
X if (rnum < 1 || rnum > MAXrows * MAXcols) continue;
X UNIQUE = TRUE;
X getxy (rnum, row, col);
X move (row, col);
X i = winch (stdscr);
X if (i == ROBOT || i == JUNKHEEP) UNIQUE = FALSE;
X } while (!UNIQUE);
X *You = rnum;
X addch (YOU);
X refresh ();
X}
*-*-END-of-showyou.c-*-*
echo x - writetop.c
sed 's/^X//' >writetop.c <<'*-*-END-of-writetop.c-*-*'
X#include <stdio.h>
X#include "define.h"
X
Xwritetop (fp, head, tail)
X
X FILE *fp;
X ToptenNode head, tail;
X{
X ToptenNode here;
X register int i;
X int rc;
X
X for (here = head, i = 1; here != NULL && i <= ENTRYMAX;
X here = here->next, i++)
X {
X rc = fwrite ((char *) &here->tdata, sizeof (struct TopInfo), 1, fp);
X }
X}
*-*-END-of-writetop.c-*-*
exit