home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / y / bsdgames / bsd-game.000 / bsd-game / games / robots / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-25  |  4.8 KB  |  216 lines

  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, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. char copyright[] =
  36. "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  37.  All rights reserved.\n";
  38. #endif /* not lint */
  39.  
  40. #ifndef lint
  41. static char sccsid[] = "@(#)main.c    5.5 (Berkeley) 2/28/91";
  42. #endif /* not lint */
  43.  
  44. # include    "robots.h"
  45. # include    <signal.h>
  46. # include    <ctype.h>
  47. # ifdef linux
  48.   # include     <sgtty.h>
  49. # endif
  50.  
  51. #ifdef linux
  52.   struct sgttyb     save;
  53. #endif
  54.  
  55. main(ac, av)
  56. int    ac;
  57. char    **av;
  58. {
  59.     register char    *sp;
  60.     register bool    bad_arg;
  61.     register bool    show_only;
  62.     extern char    *Scorefile;
  63.     extern int    Max_per_uid;
  64.     void quit();
  65.  
  66. #ifdef linux
  67.     ioctl(0, TIOCGETP, &save);
  68. #endif
  69.     show_only = FALSE;
  70.     if (ac > 1) {
  71.         bad_arg = FALSE;
  72.         for (++av; ac > 1 && *av[0]; av++, ac--)
  73.             if (av[0][0] != '-')
  74.                 if (isdigit(av[0][0]))
  75.                     Max_per_uid = atoi(av[0]);
  76.                 else {
  77.                     setuid(getuid());
  78.                     setgid(getgid());
  79.                     Scorefile = av[0];
  80. # ifdef    FANCY
  81.                     sp = rindex(Scorefile, '/');
  82.                     if (sp == NULL)
  83.                         sp = Scorefile;
  84.                     if (strcmp(sp, "pattern_roll") == 0)
  85.                         Pattern_roll = TRUE;
  86.                     else if (strcmp(sp, "stand_still") == 0)
  87.                         Stand_still = TRUE;
  88.                     if (Pattern_roll || Stand_still)
  89.                         Teleport = TRUE;
  90. # endif
  91.                 }
  92.             else
  93.                 for (sp = &av[0][1]; *sp; sp++)
  94.                     switch (*sp) {
  95.                       case 's':
  96.                         show_only = TRUE;
  97.                         break;
  98.                       case 'r':
  99.                         Real_time = TRUE;
  100.                         break;
  101.                       case 'a':
  102.                         Start_level = 4;
  103.                         break;
  104.                       case 'j':
  105.                         Jump = TRUE;
  106.                         break;
  107.                       case 't':
  108.                         Teleport = TRUE;
  109.                         break;
  110.                       default:
  111.                         fprintf(stderr, "robots: uknown option: %c\n", *sp);
  112.                         bad_arg = TRUE;
  113.                         break;
  114.                     }
  115.         if (bad_arg) {
  116.             exit(1);
  117.             /* NOTREACHED */
  118.         }
  119.     }
  120.  
  121.     if (show_only) {
  122.         show_score();
  123.         exit(0);
  124.         /* NOTREACHED */
  125.     }
  126.  
  127.     initscr();
  128.     signal(SIGINT, quit);
  129.     crmode();
  130.     noecho();
  131.     nonl();
  132.     if (LINES != Y_SIZE || COLS != X_SIZE) {
  133.         if (LINES < Y_SIZE || COLS < X_SIZE) {
  134.             endwin();
  135.             printf("Need at least a %dx%d screen\n",
  136.                 Y_SIZE, X_SIZE);
  137.             exit(1);
  138.         }
  139.         delwin(stdscr);
  140.         stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
  141.     }
  142.  
  143.     srand(getpid());
  144.     if (Real_time)
  145.         signal(SIGALRM, move_robots);
  146.     do {
  147.         init_field();
  148.         for (Level = Start_level; !Dead; Level++) {
  149.             make_level();
  150.             play_level();
  151.         }
  152.         move(My_pos.y, My_pos.x);
  153.         printw("AARRrrgghhhh....");
  154.         refresh();
  155.         score();
  156.     } while (another());
  157.     quit();
  158. }
  159.  
  160. /*
  161.  * quit:
  162.  *    Leave the program elegantly.
  163.  */
  164. void
  165. quit()
  166. {
  167. #ifndef linux
  168.     extern int    _putchar();
  169. #endif
  170.  
  171.     mvcur(0, COLS - 1, LINES - 1, 0);
  172.     if (CE) {
  173. #ifdef linux
  174.         tputs(CE, 1, putchar);
  175. #else
  176.         tputs(CE, 1, _putchar);
  177. #endif
  178.         endwin();
  179.     }
  180.     else {
  181.         endwin();
  182.         putchar('\n');
  183.     }
  184. #ifdef linux
  185.     ioctl(0, TIOCSETP, &save);
  186. #endif
  187.     exit(0);
  188.     /* NOTREACHED */
  189. }
  190.  
  191. /*
  192.  * another:
  193.  *    See if another game is desired
  194.  */
  195. another()
  196. {
  197.     register int    y;
  198.  
  199. #ifdef    FANCY
  200.     if ((Stand_still || Pattern_roll) && !Newscore)
  201.         return TRUE;
  202. #endif
  203.  
  204.     if (query("Another game?")) {
  205.         if (Full_clear) {
  206.             for (y = 1; y <= Num_scores; y++) {
  207.                 move(y, 1);
  208.                 clrtoeol();
  209.             }
  210.             refresh();
  211.         }
  212.         return TRUE;
  213.     }
  214.     return FALSE;
  215. }
  216.