home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume7 / hotel / part01 / init.c < prev    next >
C/C++ Source or Header  |  1989-07-13  |  6KB  |  196 lines

  1. /*
  2.  * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
  3.  * in both source code and executable form.  Permission is given to 
  4.  * copy both the source code and the executable under the following
  5.  * conditions:
  6.  * 
  7.  * COPYING POLICIES
  8.  * 
  9.  *   1. You may copy and distribute verbatim copies of Hotel code as you
  10.  * receive it, in any medium, provided that you conspicuously and
  11.  * appropriately publish on each file a valid copyright notice such as
  12.  * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
  13.  * and license notices on all files.  You may charge a distribution fee for the
  14.  * physical act of transferring a copy, but that fee may not exceed
  15.  * your actual costs in creating and delivering the copy.
  16.  * 
  17.  *   2. You may modify your copy or copies of Hotel or any portion of it,
  18.  * and copy and distribute such modifications under the terms of
  19.  * Paragraph 1 above, provided that you also do the following:
  20.  * 
  21.  *     a) cause the modified files to carry prominent notices stating
  22.  *     who last changed such files and the date of any change; and
  23.  * 
  24.  *     b) cause the whole of any work that you distribute or publish,
  25.  *     that in whole or in part contains or is a derivative of Hotel
  26.  *     or any part thereof, to be licensed at no charge to all third
  27.  *     parties on terms identical to those contained in this License
  28.  *     Agreement (except that you may choose to grant more extensive
  29.  *     warranty protection to third parties, at your option).
  30.  *
  31.  *   3. You may not copy, sublicense, distribute or transfer Hotel
  32.  * except as expressly provided under this License Agreement.  Any attempt
  33.  * otherwise to copy, sublicense, distribute or transfer Hotel is void and
  34.  * your rights to use Hotel under this License agreement shall be
  35.  * automatically terminated.  However, parties who have received computer
  36.  * software programs from you with this License Agreement will not have
  37.  * their licenses terminated so long as such parties remain in full compliance.
  38.  * 
  39.  *   4.  Under no circumstances may you charge for copies of Hotel, for copies
  40.  * of any program containing code from Hotel in whole or in part, or for 
  41.  * any software package or collection of programs or code that contains Hotel
  42.  * in whole or part.
  43.  *
  44.  */ 
  45. /*
  46.  *  init.c
  47.  *  Scott R. Turner
  48.  *  9/7/88
  49.  *
  50.  *  init.c contains the routines to initialize the game and to 
  51.  *  ask the initial questions of the user (number of players, etc.)
  52.  *
  53.  */
  54. #include "defs.h"
  55. extern void newtile();
  56. extern void help();
  57. extern int getnum();
  58. extern void any_key();
  59. int human_player;
  60.  
  61. init()
  62. {
  63.   int i,j,x,y;
  64.   char ans[80], ch;
  65.  
  66.  
  67. /* Initialize run-time variables.  These will probably be modified
  68.    or set to new values by the function that will read the startup
  69.    file. 
  70. */
  71.  
  72.   numhotels = 7;
  73.   boardsize = 10;
  74.   numshares = 30;
  75.   startcash = 6000;
  76.   numtiles = 6;
  77.   maxbuy = 3;
  78.  
  79. /*   At this point, read the initialization file. */
  80.   
  81. /* Initialize the board */
  82.  
  83.   for(i=1;i<=MAXBOARD;i++)
  84.     for(j=1;j<=MAXBOARD;j++)
  85.       board[i][j] = 0;
  86.   
  87. /* Initialize the hotels */
  88.  
  89.   for(i=1;i<=MAXHOTELS;i++)
  90.     {
  91.       hotels[i].size = 0;
  92.       hotels[i].shares = numshares;
  93.  
  94.       /*  Class and Name will probably be set in the initialization file. */
  95.  
  96.     };
  97.  
  98.   strcpy(hotels[1].name,"American Motel");
  99.   hotels[1].class = 0;
  100.   strcpy(hotels[2].name,"Bedford Arms");
  101.   hotels[2].class = 0;
  102.   strcpy(hotels[3].name,"Century Plaza");
  103.   hotels[3].class = 1;
  104.   strcpy(hotels[4].name,"Danford Arms");
  105.   hotels[4].class = 1;
  106.   strcpy(hotels[5].name,"Eagle Overnight");
  107.   hotels[5].class = 1;
  108.   strcpy(hotels[6].name,"Fawlty Towers");
  109.   hotels[6].class = 2;
  110.   strcpy(hotels[7].name,"Girabaldi Deluxe");
  111.   hotels[7].class = 2;
  112.  
  113.   /*  Give the players various names, if they turn out to be computer */
  114.  
  115.   strcpy(players[1].name,"Andrew");
  116.   strcpy(players[2].name,"Betty");
  117.   strcpy(players[3].name,"Charley");
  118.   strcpy(players[4].name,"Darlene");
  119.   strcpy(players[5].name,"Edmond");
  120.   strcpy(players[6].name,"Freddy");
  121.   strcpy(players[7].name,"Gertrude");
  122.  
  123.   for(i=1;i<=MAXPLAYERS;i++)
  124.     {
  125.       players[i].cash = startcash;
  126.       for(j=1;j<=MAXHOTELS;j++)
  127.     players[i].shares[j] = 0;
  128.     };
  129.     
  130.   /* Copyright Screen */
  131.   clear();
  132.   move(3,0);
  133.   printw("                                   H*O*T*E*L\n");
  134.   printw("                       Copyright 1989 by Scott R. Turner\n");
  135.   refresh();
  136.   sleep(1);
  137.   clear();
  138.  
  139.   /* Time to query the user. */
  140.  
  141.   printw("Welcome to the game of Hotel.\n\n");
  142.   printw("Instructions? (Y/N) ");
  143.   refresh();
  144.   noecho();
  145.   crmode();
  146.   ch = getch();
  147.   if (ch == 'Y' || ch == 'y') help();
  148.   printw("\nHow many players? (2 to %d) ",MAXPLAYERS);
  149.   refresh();
  150.   numplayers = getnum(2,MAXPLAYERS);
  151.   for(i=1;i<=numplayers;i++){
  152.       players[i].strategy = 1;
  153.   };
  154.   human_player = randum(numplayers);
  155.   players[human_player].strategy = 0;
  156.   strcpy(players[human_player].name,"You");
  157.   printw("You will be the ");
  158.   switch (human_player) {
  159.       case 1: printw("first");
  160.           break;
  161.       case 2: printw("second");
  162.           break;
  163.       case 3: printw("third");
  164.           break;
  165.       case 4: printw("fourth");
  166.           break;
  167.       case 5: printw("fifth");
  168.           break;
  169.       case 6: printw("sixth");
  170.           break;
  171.       case 7: printw("seventh");
  172.           break;
  173.       };
  174.   printw(" player.\n");
  175.   any_key();
  176.   clear();
  177.   
  178. /* Give every player some initial tiles. */
  179.  
  180.   for(i=1;i<=numplayers;i++)
  181.     for(j=1;j<=numtiles;j++)
  182.       newtile(i);
  183.  
  184. /* Place one tile for each player. */
  185.  
  186.   for(i=1;i<=numplayers;i++) {
  187.     x = randum(boardsize);
  188.     y = randum(boardsize);
  189.     while(board[x][y] != 0) {
  190.       x = randum(boardsize);
  191.       y = randum(boardsize);
  192.     };
  193.     board[x][y] = UNUSED;
  194.   };
  195. };
  196.