home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / MATCHGAM.C < prev    next >
C/C++ Source or Header  |  1995-03-09  |  7KB  |  220 lines

  1. #include "top.h"
  2.  
  3. typedef struct  ////////////////!!!!!!!!!!!! Entire module
  4.     {
  5.     unsigned long freq[20];              // Times sq picked
  6.     unsigned long placefreq[3][20];      // Times sq picked as pick #
  7.     unsigned long chosen[4];             // Times pr picked
  8.     unsigned long placechose[3][4];      // Times pr picked as pick #
  9.     unsigned long combos[64];            // Times pr combo
  10.     unsigned long wins[4];               // Times pr won
  11.     unsigned long losses;                // Times lost
  12.     unsigned long wincds[4];             // CDs pr won
  13.     unsigned long losscds;               // CDs lost
  14.     unsigned long winfreq[20][4];        // Times sq picked when pr won
  15.     unsigned long lossfreq[20];          // Times sq picked as lost
  16.     unsigned long times[20][4];          // Times pr in sq
  17.     unsigned long seltimes[20][4];       // Times pr picked while in sq
  18.     } match_stat_typ;
  19.  
  20. void matchdisp(char *prg, char *arr, char *pick);
  21. void matchdone(char *prg, char *arr, char *pick);
  22. void matchstat(char *prg, char *arr, char *pick);
  23. void load_match_stats(match_stat_typ *mtbuf);
  24. void save_match_stats(match_stat_typ *mtbuf);
  25. void matchstat(char *prg, char *arr, char *pick);
  26.  
  27. char matchfreq[4] = { 7, 6, 4, 3 }; // Config maybe
  28. char matchprize[4] = { 5, 15, 30, 60 }; // Config maybe
  29. char *matchcol[4] = { "^B^o", "^F^p", "^E^p", "^K^p" }; // Lang maybe
  30.  
  31. void matchgame(void)
  32. {
  33. static char matchprog;
  34. static char matcharr[20];
  35. static char matchpick[3];
  36. char wasused = 0, md, mdd, mx; //proc!
  37.  
  38. if (!stricmp(get_word(1), "SHOW"))
  39.     {
  40.     matchdisp(&matchprog, matcharr, matchpick);
  41.     wasused = 1;
  42.     }
  43. if (!stricmp(get_word(1), "START"))
  44.     {
  45.     if (matchprog < 1 || matchprog > 3)
  46.         {
  47.         if (user.cybercash < 100000L)
  48.             {
  49.             ultoa(100000L, outnum[0], 10);
  50.             ultoa(user.cybercash, outnum[1], 10);
  51.             top_output(OUT_SCREEN, getlang("MatchNotEnoughCash"), outnum[0],
  52.                        outnum[1]);
  53.             return;
  54.             }
  55.  
  56.         user.cybercash -= 100000L;
  57.         save_user_data(user_rec_num, &user);
  58.         matchpick[0] = -1; matchpick[1] = -1; matchpick[2] = -1;
  59.         memset(matcharr, -1, 20);
  60.         for (md = 0; md < 4; md++)
  61.             {
  62.             for (mdd = 0; mdd < matchfreq[md]; mdd++)
  63.                 {
  64.                 do
  65.                     {
  66.                     mx = random(20);
  67.                     }
  68.                 while(matcharr[mx] != -1);
  69.                 matcharr[mx] = md;
  70.                 }
  71.             }
  72.         matchprog = 1;
  73.         top_output(OUT_SCREEN, getlang("MatchNewGame"));
  74.         matchdisp(&matchprog, matcharr, matchpick);
  75.         }
  76.     else
  77.         {
  78.         top_output(OUT_SCREEN, getlang("MatchGameAlreadyOn"));
  79.         }
  80.     wasused = 1;
  81.     }
  82.  
  83. if (atoi(get_word(1)) >= 1 && atoi(get_word(1)) <= 20 && !wasused)
  84.     {
  85.     if (matchprog < 1 || matchprog > 3)
  86.         {
  87.         top_output(OUT_SCREEN, getlang("MatchGameNotOn"));
  88.         }
  89.     else
  90.         {
  91.         if (atoi(get_word(1)) - 1 != matchpick[0] &&
  92.             atoi(get_word(1)) - 1 != matchpick[1])
  93.             {
  94.             matchpick[matchprog - 1] = atoi(get_word(1)) - 1;
  95.             matchprog++;
  96.             matchdisp(&matchprog, matcharr, matchpick);
  97.             if (matchprog == 4)
  98.                 {
  99.                 matchdone(&matchprog, matcharr, matchpick);
  100.                 }
  101.             }
  102.         else
  103.             {
  104.             top_output(OUT_SCREEN, getlang("MatchAlreadyPicked"));
  105.             }
  106.         }
  107.     wasused = 1;
  108.     }
  109.  
  110. if (!wasused)
  111.     { // To ANSI screen!
  112.     top_output(OUT_SCREEN, "\r\n\r\nMatchGame 3/20 Commands\r\n");
  113.     top_output(OUT_SCREEN, "-----------------------\r\n\r\n");
  114.     top_output(OUT_SCREEN, "SHOW  - Shows the board.\r\n");
  115.     top_output(OUT_SCREEN, "START - Starts a new MatchGame!\r\n");
  116.     top_output(OUT_SCREEN, "<##> - A number between 1 and 20 selects that number.\r\n");
  117.     top_output(OUT_SCREEN, "\r\nThe object of MatchGame 3/20 is to select three of the same prize values.\r\n");
  118.     top_output(OUT_SCREEN, "You only get three picks, so you will have to get lucky!\r\n\r\n");
  119.     wasused = 1;
  120.     }
  121.  
  122. }
  123.  
  124. #pragma argsused
  125. void matchdisp(char *prg, char *arr, char *pick)
  126. {
  127. XINT dd;
  128.  
  129. for (dd = 0; dd < 20; dd++)
  130.     {
  131.     if (dd % 5 == 0 || dd == 0)
  132.         {
  133.         top_output(OUT_SCREEN, getlang("MatchDispSep"));
  134.         giveup_slice();
  135.         }
  136.     if (pick[0] == dd || pick[1] == dd || pick[2] == dd)
  137.         {
  138.         itoa(matchprize[arr[dd]], outnum[0], 10);
  139.         strcpy(outbuf, top_output(OUT_STRING, getlang("MatchDispPicked"),
  140.                                   matchcol[arr[dd]], outnum[0]));
  141.         }
  142.     else
  143.         {
  144.         itoa(dd + 1, outnum[0], 10);
  145.         strcpy(outbuf, top_output(OUT_STRING, getlang("MatchDispUnPicked"),
  146.                                   outnum[0]));
  147.         }
  148.     top_output(OUT_SCREEN, outbuf);
  149.     }
  150. top_output(OUT_SCREEN, getlang("MatchDispBoardEnd"));
  151.  
  152. }
  153.  
  154. #pragma argsused
  155. void matchdone(char *prg, char *arr, char *pick)
  156. {
  157.  
  158. if (arr[pick[0]] == arr[pick[1]] && arr[pick[1]] == arr[pick[2]])
  159.     {
  160.     ultoa(100000L * (long) matchprize[arr[pick[0]]], outnum[0], 10);
  161.     top_output(OUT_SCREEN, getlang("MatchWin"), outnum[0]);
  162.     user.cybercash += 100000L * (long) matchprize[arr[pick[0]]];
  163.     save_user_data(user_rec_num, &user);
  164.     }
  165. else
  166.     { // Change to use cfg!
  167.     top_output(OUT_SCREEN, getlang("MatchLose"), "100000");
  168.     }
  169.  
  170. }
  171.  
  172. #pragma argsused
  173. void matchstat(char *prg, char *arr, char *pick)
  174. {
  175. match_stat_typ mstat;
  176.  
  177. load_match_stats(&mstat);
  178.  
  179. mstat.freq[pick[0]]++;
  180. mstat.freq[pick[1]]++;
  181. mstat.freq[pick[2]]++;
  182.  
  183. mstat.chosen[arr[pick[0]]]++;
  184. mstat.chosen[arr[pick[1]]]++;
  185. mstat.chosen[arr[pick[2]]]++;
  186.  
  187. mstat.combos[(arr[pick[0]] * 16) + (arr[pick[1]] * 4) + (arr[pick[2]])]++;
  188.  
  189. mstat.placechose[0][arr[pick[0]]]++;
  190. mstat.placechose[1][arr[pick[1]]]++;
  191. mstat.placechose[2][arr[pick[2]]]++;
  192.  
  193. if (arr[pick[0]] == arr[pick[1]] && arr[pick[1]] == arr[pick[2]])
  194.     {
  195. //    mstat.wins[arr[pick
  196.     }
  197.  
  198.  
  199. }
  200.  
  201. void load_match_stats(match_stat_typ *mtbuf)
  202. {
  203.  
  204. lseek(matchfil, 0L, SEEK_SET);
  205. rec_locking(REC_LOCK, matchfil, 0L, sizeof(match_stat_typ));
  206. read(matchfil, mtbuf, sizeof(match_stat_typ));
  207.  
  208. return;
  209. }
  210.  
  211. void save_match_stats(match_stat_typ *mtbuf)
  212. {
  213.  
  214. lseek(matchfil, 0L, SEEK_SET);
  215. write(matchfil, mtbuf, sizeof(match_stat_typ));
  216. rec_locking(REC_UNLOCK, matchfil, 0L, sizeof(match_stat_typ));
  217.  
  218. return;
  219. }
  220.