Annotation of 43BSDTahoe/games/robots/main.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: char copyright[] =
                     20: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
                     21:  All rights reserved.\n";
                     22: #endif /* not lint */
                     23: 
                     24: #ifndef lint
                     25: static char sccsid[] = "@(#)main.c     5.3 (Berkeley) 6/18/88";
                     26: #endif /* not lint */
                     27: 
                     28: # include      "robots.h"
                     29: # include      <signal.h>
                     30: # include      <ctype.h>
                     31: 
                     32: main(ac, av)
                     33: int    ac;
                     34: char   **av;
                     35: {
                     36:        register char   *sp;
                     37:        register bool   bad_arg;
                     38:        register bool   show_only;
                     39:        extern char     *Scorefile;
                     40:        extern int      Max_per_uid;
                     41:        extern char     *rindex();
                     42: 
                     43:        show_only = FALSE;
                     44:        if (ac > 1) {
                     45:                bad_arg = FALSE;
                     46:                for (++av; ac > 1 && *av[0]; av++, ac--)
                     47:                        if (av[0][0] != '-')
                     48:                                if (isdigit(av[0][0]))
                     49:                                        Max_per_uid = atoi(av[0]);
                     50:                                else {
                     51:                                        setuid(getuid());
                     52:                                        setgid(getgid());
                     53:                                        Scorefile = av[0];
                     54: # ifdef        FANCY
                     55:                                        sp = rindex(Scorefile, '/');
                     56:                                        if (sp == NULL)
                     57:                                                sp = Scorefile;
                     58:                                        if (strcmp(sp, "pattern_roll") == 0)
                     59:                                                Pattern_roll = TRUE;
                     60:                                        else if (strcmp(sp, "stand_still") == 0)
                     61:                                                Stand_still = TRUE;
                     62:                                        if (Pattern_roll || Stand_still)
                     63:                                                Teleport = TRUE;
                     64: # endif
                     65:                                }
                     66:                        else
                     67:                                for (sp = &av[0][1]; *sp; sp++)
                     68:                                        switch (*sp) {
                     69:                                          case 's':
                     70:                                                show_only = TRUE;
                     71:                                                break;
                     72:                                          case 'r':
                     73:                                                Real_time = TRUE;
                     74:                                                break;
                     75:                                          case 'a':
                     76:                                                Start_level = 4;
                     77:                                                break;
                     78:                                          case 'j':
                     79:                                                Jump = TRUE;
                     80:                                                break;
                     81:                                          case 't':
                     82:                                                Teleport = TRUE;
                     83:                                                break;
                     84:                                          default:
                     85:                                                fprintf(stderr, "robots: uknown option: %c\n", *sp);
                     86:                                                bad_arg = TRUE;
                     87:                                                break;
                     88:                                        }
                     89:                if (bad_arg) {
                     90:                        exit(1);
                     91:                        /* NOTREACHED */
                     92:                }
                     93:        }
                     94: 
                     95:        if (show_only) {
                     96:                show_score();
                     97:                exit(0);
                     98:                /* NOTREACHED */
                     99:        }
                    100: 
                    101:        initscr();
                    102:        signal(SIGINT, quit);
                    103:        crmode();
                    104:        noecho();
                    105:        nonl();
                    106:        if (LINES != Y_SIZE || COLS != X_SIZE) {
                    107:                if (LINES < Y_SIZE || COLS < X_SIZE) {
                    108:                        endwin();
                    109:                        printf("Need at least a %dx%d screen\n", Y_SIZE, X_SIZE);
                    110:                        exit(1);
                    111:                }
                    112:                delwin(stdscr);
                    113:                stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
                    114:        }
                    115: 
                    116:        srand(getpid());
                    117:        if (Real_time)
                    118:                signal(SIGALRM, move_robots);
                    119:        do {
                    120:                init_field();
                    121:                for (Level = Start_level; !Dead; Level++) {
                    122:                        make_level();
                    123:                        play_level();
                    124:                }
                    125:                move(My_pos.y, My_pos.x);
                    126:                printw("AARRrrgghhhh....");
                    127:                refresh();
                    128:                score();
                    129:        } while (another());
                    130:        quit();
                    131: }
                    132: 
                    133: /*
                    134:  * quit:
                    135:  *     Leave the program elegantly.
                    136:  */
                    137: quit()
                    138: {
                    139:        extern int      _putchar();
                    140: 
                    141:        mvcur(0, COLS - 1, LINES - 1, 0);
                    142:        if (CE) {
                    143:                tputs(CE, 1, _putchar);
                    144:                endwin();
                    145:        }
                    146:        else {
                    147:                endwin();
                    148:                putchar('\n');
                    149:        }
                    150:        exit(0);
                    151:        /* NOTREACHED */
                    152: }
                    153: 
                    154: /*
                    155:  * another:
                    156:  *     See if another game is desired
                    157:  */
                    158: another()
                    159: {
                    160:        register int    y;
                    161: 
                    162: #ifdef FANCY
                    163:        if ((Stand_still || Pattern_roll) && !Newscore)
                    164:                return TRUE;
                    165: #endif
                    166: 
                    167:        if (query("Another game?")) {
                    168:                if (Full_clear) {
                    169:                        for (y = 1; y <= Num_scores; y++) {
                    170:                                move(y, 1);
                    171:                                clrtoeol();
                    172:                        }
                    173:                        refresh();
                    174:                }
                    175:                return TRUE;
                    176:        }
                    177:        return FALSE;
                    178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.