home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d158 / yachtc3.lha / YachtC3 / src / main.c < prev    next >
C/C++ Source or Header  |  1988-10-02  |  20KB  |  833 lines

  1. /***********************************************************************
  2. *
  3. *                           Yachtc
  4. *             Yes, Friends, it My First Amiga Program
  5. *             Copyright 1985 by Sheldon Leemon
  6. *             Feel free to copy and distribute the program and
  7. *             source code, but don't try to sell, license, or
  8. *             otherwise commercially exploit it.
  9. *
  10. *             If you have questions or comments, you may contact
  11. *             the author through Delphi (username = DRX)
  12. *             or Compuserve ID 72705,1355.  No late-night phone calls,
  13. *             please.
  14. *
  15. ************************************************************************/
  16.  
  17. /*    Version 2.0  modifications by Mark Schretlen of Calgary,Alberta
  18.                     86-03-16   ( some fixes & Steve Bennett's "scales"
  19.                      incorporated with calls to Happy,Bomb, and YahtzeeSound).
  20.  
  21.       Version 3.0  further modifications by M. Schretlen for
  22.                    multitasking "scales" 87-12-30.
  23. */
  24.  
  25. #include "bones.h"
  26. /***************** Image and other data structs ****************/
  27.  
  28. /* Image data for dice spots.  All 48 bits are used for the image.
  29.    We move this data down to CHIP memory, just in case (later versions
  30.    will lets us allocate structures in CHIP memory--so they say)*/
  31.  
  32. unsigned short SpotData [] [57] ={
  33. /* one spot */
  34.  
  35.    0x0000, 0x0000, 0x0000,
  36.    0x0000, 0x0000, 0x0000,
  37.    0x0000, 0x0000, 0x0000,
  38.    0x0000, 0x0000, 0x0000,
  39.    0x0000, 0x0000, 0x0000,
  40.    0x0000, 0x0000, 0x0000,
  41.    0x0000, 0x0000, 0x0000,
  42.    0x0000, 0x07E0, 0x0000,
  43.    0x0000, 0x1FF8, 0x0000,
  44.    0x0000, 0x1FF8, 0x0000,
  45.    0x0000, 0x1FF8, 0x0000,
  46.    0x0000, 0x07E0, 0x0000,
  47.    0x0000, 0x0000, 0x0000,
  48.    0x0000, 0x0000, 0x0000,
  49.    0x0000, 0x0000, 0x0000,
  50.    0x0000, 0x0000, 0x0000,
  51.    0x0000, 0x0000, 0x0000,
  52.    0x0000, 0x0000, 0x0000,
  53.    0x0000, 0x0000, 0x0000,
  54.  
  55. /* two spots*/
  56.  
  57.    0x1F80, 0x0000, 0x0000,
  58.    0x7FE0, 0x0000, 0x0000,
  59.    0x7FE0, 0x0000, 0x0000,
  60.    0x7FE0, 0x0000, 0x0000,
  61.    0x1F80, 0x0000, 0x0000,
  62.    0x0000, 0x0000, 0x0000,
  63.    0x0000, 0x0000, 0x0000,
  64.    0x0000, 0x0000, 0x0000,
  65.    0x0000, 0x0000, 0x0000,
  66.    0x0000, 0x0000, 0x0000,
  67.    0x0000, 0x0000, 0x0000,
  68.    0x0000, 0x0000, 0x0000,
  69.    0x0000, 0x0000, 0x0000,
  70.    0x0000, 0x0000, 0x0000,
  71.    0x0000, 0x0000, 0x01F8,
  72.    0x0000, 0x0000, 0x07FE,
  73.    0x0000, 0x0000, 0x07FE,
  74.    0x0000, 0x0000, 0x07FE,
  75.    0x0000, 0x0000, 0x01F8,
  76.  
  77. /* three spots */
  78.  
  79.    0x1F80, 0x0000, 0x0000,
  80.    0x7FE0, 0x0000, 0x0000,
  81.    0x7FE0, 0x0000, 0x0000,
  82.    0x7FE0, 0x0000, 0x0000,
  83.    0x1F80, 0x0000, 0x0000,
  84.    0x0000, 0x0000, 0x0000,
  85.    0x0000, 0x0000, 0x0000,
  86.    0x0000, 0x07E0, 0x0000,
  87.    0x0000, 0x1FF8, 0x0000,
  88.    0x0000, 0x1FF8, 0x0000,
  89.    0x0000, 0x1FF8, 0x0000,
  90.    0x0000, 0x07E0, 0x0000,
  91.    0x0000, 0x0000, 0x0000,
  92.    0x0000, 0x0000, 0x0000,
  93.    0x0000, 0x0000, 0x01F8,
  94.    0x0000, 0x0000, 0x07FE,
  95.    0x0000, 0x0000, 0x07FE,
  96.    0x0000, 0x0000, 0x07FE,
  97.    0x0000, 0x0000, 0x01F8,
  98.  
  99. /* four spots */
  100.  
  101.    0x1F80, 0x0000, 0x01F8,
  102.    0x7FE0, 0x0000, 0x07FE,
  103.    0x7FE0, 0x0000, 0x07FE,
  104.    0x7FE0, 0x0000, 0x07FE,
  105.    0x1F80, 0x0000, 0x01F8,
  106.    0x0000, 0x0000, 0x0000,
  107.    0x0000, 0x0000, 0x0000,
  108.    0x0000, 0x0000, 0x0000,
  109.    0x0000, 0x0000, 0x0000,
  110.    0x0000, 0x0000, 0x0000,
  111.    0x0000, 0x0000, 0x0000,
  112.    0x0000, 0x0000, 0x0000,
  113.    0x0000, 0x0000, 0x0000,
  114.    0x0000, 0x0000, 0x0000,
  115.    0x1F80, 0x0000, 0x01F8,
  116.    0x7FE0, 0x0000, 0x07FE,
  117.    0x7FE0, 0x0000, 0x07FE,
  118.    0x7FE0, 0x0000, 0x07FE,
  119.    0x1F80, 0x0000, 0x01F8,
  120.  
  121. /* five spots */
  122.  
  123.    0x1F80, 0x0000, 0x01F8,
  124.    0x7FE0, 0x0000, 0x07FE,
  125.    0x7FE0, 0x0000, 0x07FE,
  126.    0x7FE0, 0x0000, 0x07FE,
  127.    0x1F80, 0x0000, 0x01F8,
  128.    0x0000, 0x0000, 0x0000,
  129.    0x0000, 0x0000, 0x0000,
  130.    0x0000, 0x07E0, 0x0000,
  131.    0x0000, 0x1FF8, 0x0000,
  132.    0x0000, 0x1FF8, 0x0000,
  133.    0x0000, 0x1FF8, 0x0000,
  134.    0x0000, 0x07E0, 0x0000,
  135.    0x0000, 0x0000, 0x0000,
  136.    0x0000, 0x0000, 0x0000,
  137.    0x1F80, 0x0000, 0x01F8,
  138.    0x7FE0, 0x0000, 0x07FE,
  139.    0x7FE0, 0x0000, 0x07FE,
  140.    0x7FE0, 0x0000, 0x07FE,
  141.    0x1F80, 0x0000, 0x01F8,
  142.  
  143. /* six spots */
  144.  
  145.    0x1F80, 0x0000, 0x01F8,
  146.    0x7FE0, 0x0000, 0x07FE,
  147.    0x7FE0, 0x0000, 0x07FE,
  148.    0x7FE0, 0x0000, 0x07FE,
  149.    0x1F80, 0x0000, 0x01F8,
  150.    0x0000, 0x0000, 0x0000,
  151.    0x0000, 0x0000, 0x0000,
  152.    0x1F80, 0x0000, 0x01F8,
  153.    0x7FE0, 0x0000, 0x07FE,
  154.    0x7FE0, 0x0000, 0x07FE,
  155.    0x7FE0, 0x0000, 0x07FE,
  156.    0x1F80, 0x0000, 0x01F8,
  157.    0x0000, 0x0000, 0x0000,
  158.    0x0000, 0x0000, 0x0000,
  159.    0x1F80, 0x0000, 0x01F8,
  160.    0x7FE0, 0x0000, 0x07FE,
  161.    0x7FE0, 0x0000, 0x07FE,
  162.    0x7FE0, 0x0000, 0x07FE,
  163.    0x1F80, 0x0000, 0x01F8,
  164. };
  165. USHORT (*SpotData_chip)[57];
  166. SHORT boardlines[] =
  167.  {
  168.    HLINR,VLINT,
  169.    HLINR,VLINB,
  170.    HLINL-1,VLINB,
  171.    HLINL-1,VLINT,
  172.    HLINL,VLINT,
  173.    HLINL,VLINB,
  174.    HLINR-1,VLINB,
  175.    HLINR-1,VLINT
  176. };
  177.  
  178.    static USHORT colormap [8] =
  179.       {
  180.       WHITE,   /* background color */
  181. #define BGRP     0
  182.       RED,      /* color of window-close box */
  183. #define REDP     1
  184.       GREEN,   /* color of menu title */
  185. #define GRNP     2
  186.       YELLOW,   /* color of window-close dot */
  187. #define YELP     3
  188.       AQUA,
  189. #define AQUP     4
  190.       PURPLE,
  191. #define PURP     5
  192.       BLUE,
  193. #define BLUP     6
  194.       BLACK
  195. #define BLKP     7
  196.       };
  197.  
  198. extern void init_sound();
  199. extern void do_sound();
  200.  
  201. #include "endless.h"
  202.  
  203. /* *************************Program Begins Here******************* */
  204.  
  205. main()
  206. {
  207.    USHORT bones [6];         /* The array for dice values */
  208.    USHORT cats;
  209.    int scores [MAXPLAYERS] [SCORECATS];
  210.    USHORT IMsg(), flag;
  211.    USHORT players, cur_player, turns;
  212.  
  213. init_sound();
  214. do_sound(YAHSOUND,7);
  215.  
  216. init_scr();          /* do one-time initialization of screen */
  217.  
  218. for (;;)
  219. {
  220.  
  221.                  /* get number of players */
  222.  
  223.  while( (flag=IMsg()) < 64);   /* wait til new game menu item selected */
  224.  
  225.                  /* initialize the scores */
  226.  
  227.   for(players=cur_player=0;players<MAXPLAYERS;players++)
  228.    {
  229.      for(cats=0; cats<SCORECATS; scores[players][cats++] = -1)
  230.       ;   /* blank the scoring columns to -1 to start with */
  231.  
  232.    scores[players][6] = 0;
  233.    scores[players][7] = 0;
  234.    scores[players][8] = 0;
  235.    scores[players][9] = 0;
  236.    scores[players][17] = 0;
  237.    scores[players][18] = 0;
  238.    scores[players][19] = 0;
  239.    scores[players][20] = 0;
  240.  
  241.          /* except for the rows with graphics or totals (they = 0) */
  242.    }
  243.  
  244. players = flag - 63;      /* 1-4 player game selected */
  245.  
  246. init_pad();      /* draw the score pad */
  247.  
  248. SetDrMd (BdRp,JAM1);
  249. for (turns=0;turns<players;turns++)
  250.    Name(turns);
  251.  
  252. /* play a whole round */
  253.  
  254. for (turns=0;turns<13;turns++)
  255.    {
  256.    for (cur_player=0; cur_player<players ;cur_player++)
  257.       {
  258.  
  259.       SetDrMd(BdRp,JAM2+INVERSVID);   /*   highlight the player's name */
  260.       Name(cur_player);
  261.       roll_dice(bones);   /* get dice values */
  262.       do_sound(DICEROLL,4);
  263.       score_turn(scores[cur_player],bones,cur_player);
  264.  
  265.       SetDrMd(BdRp,JAM2);         /* unhighlight the player's name */
  266.       Name(cur_player);
  267.  
  268.       }   /* for */
  269.    }
  270. }   /* infinite for */
  271. }   /* end of main */
  272.  
  273. roll_dice(bones)
  274. USHORT bones [];
  275. {
  276.    USHORT changed,dieno,flag;
  277.    USHORT Shake(),Rollrep(),IMsg();
  278.  
  279. for(dieno=0;dieno<DICE;dieno++)      /* do first roll */
  280.  
  281.    {
  282.       DieGadg[dieno].Activation = TOGGLESELECT;
  283.       bones[dieno]=Rollrep(dieno);  /* roll dice 5 times and store result */
  284.    } /* for */
  285.  
  286. OnGadget(&ButtonGadget,BdWdw,NULL);
  287. changed = bones[TURNS] = 1;
  288.  
  289. while(changed && bones[TURNS]<3)
  290.  
  291.   {
  292.    while( ((flag=IMsg()) < 17) || (flag >24) );   /* wait til button pushed */
  293.    changed = Shake(bones);                        /* shake if any are changed */
  294.   }
  295.  
  296. OffGadget(&ButtonGadget,BdWdw,NULL);
  297. for(dieno = 0; dieno < DICE ; dieno++)      /* turn gadgets off */
  298.    DieGadg[dieno].Activation = NULL;
  299.  
  300. if( (bones[0] == bones[1]) && (bones[1] == bones[2]) && (bones[2] == bones[3]) && (bones[3] == bones[4]) ) do_sound(YAHSOUND,5);
  301.  
  302. }/* end of roll_ */
  303.  
  304.  
  305. score_turn(scores,bones,cur_player)
  306.  
  307. int scores[];
  308. USHORT bones[];
  309. USHORT cur_player;
  310.  
  311. {
  312.    USHORT IMsg();
  313.    unsigned int Evaluate(),score;
  314.    USHORT row,values[7],count;
  315.  
  316. /********************************************************************/
  317. /* This routine evaluates the current dice values in the bones array
  318.    in terms of the score they produce for the scoring category passed
  319.    in row for the function "Evaluate"(returns the score). */
  320.  
  321.     for(count=0;count<7;count++)
  322.         values[count]=0;         /* zero out temporarily sort array */
  323.  
  324.     for(count=0;count<5;count++)   /* sort dice by number of spots */
  325.       {
  326.         values[bones[count]]++;
  327.  
  328.  
  329.         values[6]+=(1+bones[count]);   /* add die to total */
  330.       }
  331. /********************************************************************/
  332.  
  333.           /* position score gadget */
  334.  
  335.  
  336.      ScoreGadget.LeftEdge = VLINL + (VLINS*cur_player) + 4;
  337.    /*   AddGadget(BdWdw,&ScoreGadget,-1); */
  338.  
  339. /* show possible scores to let player select */
  340.  
  341.  
  342.  
  343. for (row = 0; row <17; row ++)
  344.    if (scores[row] == -1)
  345.    {
  346.       SetAPen (BdRp,BGRP);   /* erase dots with bg pen */
  347.       ShowDots (row,cur_player);
  348.       SetAPen (BdRp,REDP);   /* possible scores in green */
  349.       score = Evaluate(values,row);
  350.       ShowScore (score,row,cur_player);
  351.    }
  352.  
  353.  
  354.    /* wait  until user clicks on a score of an unused category */
  355.    while( ( (row=IMsg()) > 17) || (scores[row] != -1 ) );
  356.  
  357.  
  358. SetAPen (BdRp,BLKP);   /* selected scores in black */
  359. score = Evaluate(values,row);   /* evaluate row selected */
  360. ShowScore (scores[row]=score,row,cur_player);   /* print in black */
  361.  
  362. /*********Steve Bennett's "scales" sounds.******/
  363.  
  364. if ((score < 3) || ((score < 6) && (row > 2)) )  do_sound(BOMBSOUND,5);
  365. else if ( ((score > 18) && (row < 6)) || ((score > 25) && (row > 8)) )  do_sound(HAPPYSOUND,5);
  366. else if ((score < 20) && (row > 8) )  do_sound(HAPPYSOUND,1);
  367.  
  368. /***********************************************/
  369.  
  370. if (row<7)
  371.    {
  372.    ClearRow(7,cur_player);
  373.    ShowScore (scores[7]+=score,7,cur_player);   /* do upper sub-total */
  374.    }
  375. else
  376.    {
  377.    ClearRow(18,cur_player);
  378.    ShowScore (scores[18]+=score,18,cur_player);   /* or else lower total */
  379.    }
  380. if (scores[7] > BONUS)
  381.    {
  382.    ClearRow(8,cur_player);
  383.    ShowScore (scores[8] = 35, 8, cur_player);   /* check for bonus */
  384.    }
  385.  
  386. /*add sub-totals to total and display  */
  387.  
  388. ClearRow(20,cur_player);
  389. ShowScore (scores[20]=scores[7]+scores[8]+scores[18],20,cur_player);
  390.  
  391.  
  392.  
  393. for (row = 0; row <17; row ++)
  394.    if (scores[row] == -1)
  395.    {
  396.       SetAPen (BdRp,BGRP);   /* erase scores with bg pen */
  397.       score = Evaluate(values,row);
  398.       ShowScore (score,row,cur_player);
  399.       SetAPen (BdRp,BLKP);   /* draw dots in black pen */
  400.  
  401.  
  402.       ShowDots (row,cur_player);
  403.    }
  404.  
  405. }
  406.  
  407.  
  408. USHORT IMsg()
  409.  
  410. {
  411.    struct IntuiMessage *BdMsg;      /* Intuition message structure */
  412.    ULONG Mclass;               /* Message class */
  413.    USHORT Mcode,flag;            /* Message code */
  414.    APTR Maddress;               /* Address of structure that caused message */
  415.    SHORT Mmx, Mmy ;            /* Message mouse x and y */
  416.  
  417.  
  418. flag = 35;
  419. Wait (1 << BdWdw->UserPort->mp_SigBit);
  420. while (BdMsg = (struct IntuiMessage *)GetMsg(BdWdw->UserPort))
  421.    {
  422.    Mclass = BdMsg->Class;
  423.    Mcode = BdMsg->Code;
  424.    Maddress = BdMsg->IAddress;
  425.    Mmx = BdMsg->MouseX;
  426.    Mmy = BdMsg->MouseY;
  427.    ReplyMsg(BdMsg);
  428.    switch (Mclass) {
  429.       case CLOSEWINDOW:
  430.          Cleanup();
  431.          exit(TRUE);
  432.          break;
  433.  
  434.       case GADGETUP:
  435.          flag = (Mmy-29)/8;
  436.          break;
  437.  
  438.       case MENUPICK:
  439.          switch (MENUNUM(Mcode)){
  440.             case 0:
  441.                flag = 64 + ITEMNUM(Mcode);
  442.                break;
  443.             case 1:
  444.                switch (ITEMNUM(Mcode)){
  445.                   case 0:
  446.                      AutoRequest
  447.                      (BdWdw,&InstructText[13],NULL,&OKText,0,0,515,180);
  448.                      flag = 32;
  449.                      break;
  450.                   case 1:
  451.                      AutoRequest
  452.                      (BdWdw,&AboutText[10],NULL,&OKText,0,0,515,148);
  453.                      flag = 32;
  454.                      break;
  455.                   }   /* end of Item switch */
  456.                   break;
  457.             }   /* end of MenuNum switch */
  458.             break;
  459.    }
  460.  
  461.   /* end of Class switch */
  462.  
  463.    }/* while */
  464.  
  465. return(flag);
  466. }
  467.  
  468. USHORT Shake(bones)
  469. USHORT bones[];
  470. {
  471.    USHORT dieno,changed,Rollrep();
  472.    for(dieno=changed=0;dieno<DICE;dieno++)
  473.    {
  474.       OnGadget(&DieGadg[dieno],BdWdw,NULL);
  475.       if(DieGadg[dieno].Flags & SELECTED)
  476.       {
  477.          bones[dieno]=Rollrep(dieno);  /* roll dice and store result */
  478.          Deselect(dieno);
  479.          changed++;
  480.       } /* if */
  481.    } /* for */
  482.    bones[TURNS]++;
  483. return(changed);
  484. }
  485.  
  486. USHORT Rollrep(dieno)
  487. USHORT dieno;
  488. {
  489. USHORT reps, throw;
  490.  
  491. for (reps=0;reps<9;reps++)
  492. {
  493.    throw = rand()%6;
  494.    DrawImage(BdRp,&Blank,BLANKL, (BLANKS*dieno)+BLANKT);
  495.    DrawImage(BdRp,&DieImage[throw],BLANKL, (BLANKS*dieno)+BLANKT);
  496. }
  497. DieGadg[dieno].GadgetRender=(APTR)&DieImage[throw];
  498. return(throw);
  499. }
  500.  
  501. Deselect (dieno)
  502. USHORT dieno;
  503. {
  504. USHORT Gadgetno ;
  505.  
  506. /* Since its not nice to change the SELECTED flag while the gadget is active */
  507. /* (only the user is supposed to do that, by clicking on it), we'l be nice */
  508. /* and first Remove the die gadget from the list, THEN change the flag */
  509. /* and finally, Add it back to the list again. */
  510.  
  511. Gadgetno = RemoveGadget(BdWdw, &DieGadg[dieno]);
  512. DieGadg[dieno].Flags ^= SELECTED;               /* toggle SELECTED flag */
  513. AddGadget(BdWdw,&DieGadg[dieno],Gadgetno);
  514. }
  515.  
  516.  
  517. unsigned int Evaluate (values,row)
  518. USHORT values[];
  519. USHORT row;
  520. {
  521.   unsigned int count,flagg,save;
  522.  
  523.   switch(row)
  524.       {
  525.   /* spot dice */
  526.  
  527.       case 0:
  528.       case 1:
  529.       case 2:
  530.       case 3:
  531.       case 4:
  532.       case 5:         return((row+1)*values[row]);   /* return total of desired spots */
  533.  
  534.   /* 3 of a kind */
  535.  
  536.       case 10:
  537.          for(count=flagg=0;count<6;count++)
  538.             if(values[count] > 2)
  539.                flagg = 1;
  540.          return( (flagg) ? values[6] : 0);
  541.  
  542.   /* 4 of a kind */
  543.  
  544.       case 11:
  545.          for(count=flagg=0;count<6;count++)
  546.             if(values[count] > 3)
  547.                flagg = 1;
  548.          return( (flagg) ? values[6] : 0);
  549.  
  550.   /* full house */
  551.       case 12:
  552.          for(count=flagg=0;count<6;count++)
  553.             if(values[count] > 1)
  554.                flagg+=values[count];
  555.  
  556.  
  557.          return((unsigned int) ((flagg == 5) ? 25 : 0));
  558.  
  559.   /* small straight */
  560.  
  561.       case 13:
  562.          flagg = 0;
  563.          save = 100;
  564.          for (count = 0;count < 6;count++)
  565.          {
  566.             if(values[count] > 1)    /* are there more than one pair */
  567.              {
  568.                flagg = flagg + values[count];
  569.                save = count;
  570.              }
  571.          }
  572.          if (flagg > 2) return(0);
  573.  
  574.          if (save != 100) values[save] = values[save] - 1;
  575.  
  576.          flagg = 0;
  577.  
  578.          if (((values[0] == 1) && (values[1] == 1) && (values[2] == 1) && (values[3] == 1) )
  579.          ||  ((values[1] == 1) && (values[2] == 1) && (values[3] == 1) && (values[4] == 1) )
  580.          ||  ((values[2] == 1) && (values[3] == 1) && (values[4] == 1) && (values[5] == 1) ))
  581.          flagg = 30;  /* whew! */
  582.  
  583.          if(save != 100) values[save] = values[save] + 1;
  584.  
  585.          return(flagg);
  586.  
  587.   /* large straight */
  588.  
  589.       case 14:
  590.          flagg = 0;
  591.          for (count = 0;count < 6;count++)
  592.          {
  593.             if(values[count] > 1) return(0);
  594.          }
  595.          if (values[0] == values[1] == values[2] == values[3] == values[4] == 1  ||
  596.              values[1] == values[2] == values[3] == values[4] == values[5] == 1 )
  597.              return(40);      /* if five in a row, score */
  598.          return(0);
  599.  
  600.   /* yacht */
  601.  
  602.       case 15:
  603.          for(count=flagg=0;count<6;count++)
  604.             if(values[count] == 5) flagg = 50;
  605.          return(flagg);
  606.  
  607.   /* yarboro */
  608.  
  609.       case 16:
  610.          return((unsigned int)values[6]);
  611.  
  612.   /* better not get here! */
  613.  
  614.       default:
  615.          return(0);
  616.    }
  617.  
  618. }
  619.  
  620.  
  621. ShowScore(score,row,player)
  622. USHORT score,row,player;
  623. {
  624. int length;
  625. char *score_str = "0000";
  626.  
  627.    SetDrMd(BdRp,JAM1);
  628.    Move (BdRp,DOTL + (DOTS*player), (row*TEXTS)+DOTT );
  629.    Text (BdRp, "    ",4);
  630.    length = stcu_d (score_str,score,4);
  631.    Move (BdRp,
  632.       DOTL + (DOTS*player + ((4-length)*SPACEW) ), (row*TEXTS)+DOTT );
  633.    Text (BdRp, score_str, length);
  634.  
  635. }
  636.  
  637.  
  638. ShowDots (row,player)
  639. USHORT row,player;
  640. {
  641.    Move (BdRp,DOTL + (DOTS*player), (row*TEXTS)+DOTT );
  642.    SetDrMd(BdRp,JAM1);
  643.    Text (BdRp, "....",4);
  644.  
  645. }
  646.  
  647. ClearRow (row,player)
  648. USHORT row,player;
  649. {
  650.  
  651.    Move (BdRp,DOTL + (DOTS*player), (row*TEXTS)+DOTT );
  652.    SetDrMd(BdRp,JAM2);
  653.    Text (BdRp, "    ",4);
  654.  
  655. }
  656.  
  657. Name (player)
  658. USHORT player;
  659. {
  660.  
  661.    Move(BdRp, DOTL -(2*SPACEW) + (DOTS*player), TEXTT+2);
  662.    Text(BdRp, textline[MAXLINES+player], 8);
  663.  
  664. }
  665.  
  666.  
  667.  
  668. init_scr()
  669. {
  670.  
  671. /* move image data to chip memory*/
  672.  
  673. if (InitImages() != TRUE) {
  674.    printf("Not enough chip memory for images.\n");
  675.  
  676.  
  677.   FreeImages();
  678.    Exit(FALSE);
  679.    }
  680.  
  681. /* Open the Intuition and Graphics libraries.
  682.  * Get pointer to WCS routines, and if = 0, libraries aren't available.
  683.  */
  684.    IntuitionBase = (struct IntuitionBase *)
  685.          OpenLibrary("intuition.library",INTUITION_REV);
  686.    if (IntuitionBase == NULL) exit(FALSE);
  687.  
  688.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", GRAPHICS_REV);
  689.    if (GfxBase == NULL)
  690.     {
  691.         CloseLibrary(IntuitionBase);
  692.         exit(FALSE);
  693.     }
  694.  
  695. /* Open the Screen and Windows.  If they = 0, they weren't opened. */
  696.  
  697.    if ((NewBoardWindow.Screen = BackWindow.Screen = BdScr =
  698.  (struct Screen *)OpenScreen(&NewBdScr)) == NULL)
  699.       exit(FALSE);
  700.  
  701.    if (( BackWdw = (struct Window *)OpenWindow(&BackWindow)) == NULL)
  702.       exit(FALSE);
  703.  
  704.    if (( BdWdw = (struct Window *)OpenWindow(&NewBoardWindow)) == NULL)
  705.       exit(FALSE);
  706.  
  707. SetMenuStrip(BdWdw,&BdMenu);
  708.  
  709. init_pad();      /* draw the score pad */
  710.  
  711.  
  712.  
  713. }   /* end of init_scr */
  714.  
  715. init_pad()
  716. {
  717. /* Set up the board outline */
  718.  
  719.    ULONG Seconds,Micros;
  720.    int count, column;
  721.  
  722.    WVPort = (struct ViewPort *)ViewPortAddress(BdWdw); /* find the viewport */
  723.    LoadRGB4(WVPort,&colormap,8);   /* load our new set of colors */
  724.  
  725.    SetAPen (BdRp,BLKP);
  726.    Move(BdRp,0,VLINT);
  727.    SetDrMd (BdRp,JAM2);      /* JAM2 substituted */
  728.  
  729.    PolyDraw(BdRp,8,&boardlines);
  730.  
  731. /* Put in text and horizontal lines for board */
  732.  
  733.    Move(BdRp,TEXTL,TEXTT+2);
  734.    Text(BdRp,textline[0],strlen(textline[0]) );
  735.  
  736.  
  737.    for(count = 1; count<MAXLINES;count++) {
  738.       if(*textline[count] == ' '){
  739.          Move(BdRp,1,(count*HLINS)+HLINT);
  740.          Draw(BdRp,HLINR,(count*HLINS)+HLINT);
  741.          }
  742.  
  743.       else{
  744.          Move(BdRp,TEXTL,(count*TEXTS)+TEXTT);
  745.          Text(BdRp,textline[count],strlen(textline[count]) );
  746.  
  747.          for (column = 0; column < MAXPLAYERS; column ++)
  748.             {
  749.             ClearRow(count-2,column);
  750.             ShowDots(count-2,column);
  751.             }   /* for columns */
  752.  
  753.  
  754.        }   /* else */
  755.  
  756.       };   /* for count */
  757.  
  758.  
  759. /* Draw vertical lines for board */
  760.  
  761.    for(count = 0; count<MAXPLAYERS;count++) {   /* replace this with RectFill */
  762.       Move(BdRp,(count*VLINS)+VLINL+1,VLINT);
  763.       Draw(BdRp,(count*VLINS)+VLINL+1,VLINB);
  764.       Move(BdRp,(count*VLINS)+VLINL,VLINT);
  765.       Draw(BdRp,(count*VLINS)+VLINL,VLINB);
  766.       }
  767.  
  768. /* Blank players names */
  769.    SetDrMd(BdRp,JAM2);
  770.    for (count=0;count<MAXPLAYERS;count++)
  771.       {
  772.       Move(BdRp, DOTL - (2*SPACEW) + (DOTS*count), TEXTT+2);
  773.       Text(BdRp, "        ", 8);
  774.       }
  775.  
  776. /* Draw initial die images */
  777.    for(count = 0; count <5 ;count++){
  778.    DrawImage (BdRp, &Blank, BLANKL, (BLANKS*count) + BLANKT);
  779.    DrawImage (BdRp, &DieImage[5], BLANKL, (BLANKS*count) + BLANKT);
  780.    }
  781.  
  782.  
  783.  
  784. /* use time to seed random number generator */
  785. CurrentTime(&Seconds,&Micros);
  786. srand(Micros);
  787.  
  788. }   /* end of init_pad */
  789.  
  790. InitImages()
  791. {
  792.    extern USHORT (*SpotData_chip)[57];
  793.    int row,col;
  794.  
  795.    if ((SpotData_chip = (USHORT (*)[57]) AllocMem(sizeof(SpotData),MEMF_CHIP))   == 0) return(FALSE);   /* allocate chip memory for images */
  796.  
  797.    row = 0;
  798.    while (row < 6)
  799.    {
  800.       for (col=0 ; col < 57 ;col++){
  801.             SpotData_chip[row][col] = SpotData[row][col];
  802.             }
  803.       DieImage[row].ImageData = SpotData_chip[row++];
  804.    }
  805.  
  806.  
  807.    return(TRUE);
  808.  
  809. }
  810.  
  811. FreeImages()
  812. {
  813. extern USHORT (*SpotData_chip)[57];
  814.  
  815.    if (SpotData_chip != 0){
  816.       FreeMem(SpotData_chip, sizeof(SpotData));
  817.       }
  818.  
  819. }
  820.  
  821. Cleanup()
  822. {
  823.    do_sound(NULL,0);
  824.    FreeImages();
  825.    CloseWindow(BdWdw);
  826.    CloseWindow(BackWdw);
  827.    CloseScreen(BdScr);
  828.    CloseLibrary(GfxBase);
  829.    CloseLibrary(IntuitionBase);
  830. }
  831.  
  832. /* *********************** program ends here ****************** */
  833.