home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / SLOTS.C < prev    next >
C/C++ Source or Header  |  1995-05-18  |  15KB  |  333 lines

  1. #include "top.h"
  2.  
  3. void slots_game(void) ///////!!!!! Massively.
  4. {//proc
  5. slots_stat_typ sstat;
  6.  
  7. char wasused = 0;
  8.  
  9. if (!stricmp(get_word(1), "BET"))
  10.     {
  11.     if (strtoul(get_word(2), NULL, 10) < 1L ||
  12.         strtoul(get_word(2), NULL, 10) > 500000L)
  13.         {
  14.         if (!get_word_char(2, 0))
  15.             {
  16.             sprintf(outbuf, "\r\n^nCurrent Slots bet:  ^l%lu^n.\r\n",
  17.                     slotsbet);
  18.             top_output(OUT_SCREEN, outbuf);
  19.             }
  20.         else
  21.             {
  22.             top_output(OUT_SCREEN, "\r\n^mInvalid bet!  Bets must be between ^p1^m "
  23.                        "and ^p500000^m.\r\n");
  24.             top_output(OUT_SCREEN, "Sample bet command:  ^kSLOTS BET 150\r\n");
  25.             }
  26.         }
  27.     else
  28.         {
  29.         slotsbet = strtoul(get_word(2), NULL, 10);
  30.         sprintf(outbuf, "\r\n^nSlots bet set to ^l%lu^n.\r\n",
  31.                 slotsbet);
  32.         top_output(OUT_SCREEN, outbuf);
  33.         }
  34.     wasused = 1;
  35.     }
  36. if (!stricmp(get_word(1), "PULL"))
  37.     {
  38.     XINT sd, st;
  39.     char snum[5], allok = 1, wintype;
  40.     XINT spincalc, numtimes, pullcount;
  41.     unsigned long payoff;
  42.  
  43.     if (get_word_char(2, 0))
  44.         {
  45.         numtimes = atoi(get_word(2));
  46.         }
  47.     else
  48.         {
  49.         numtimes = 1;
  50.         }
  51.  
  52.     if (numtimes < 1 || numtimes > 10)
  53.         {
  54.         top_output(OUT_SCREEN, "\r\n^mInvalid number of pulls!  You may only pull "
  55.                    "the lever ^p1^m to ^p10^m\r\ntimes per PULL "
  56.                    "command.\r\n");
  57.         allok = 0;
  58.         }
  59.  
  60.     for (pullcount = 0; pullcount < numtimes && allok; pullcount++)
  61.         {
  62.         if (slotsbet < 1L || slotsbet > 500000L)
  63.             {
  64.             top_output(OUT_SCREEN, "\r\n^mYou must set a bet first!\r\n");
  65.             allok = 0;
  66.             }
  67.         if (user.cybercash < slotsbet)
  68.             {
  69.             sprintf(outbuf, "\r\n^mNot enough CyberCash left!  "
  70.                     "(Bet = ^l%lu^m, CyberCash = ^l%lu^m)\r\n",
  71.                     slotsbet, user.cybercash);
  72.             top_output(OUT_SCREEN, outbuf);
  73.             allok = 0;
  74.             }
  75.  
  76.         if (allok)
  77.             {
  78.             user.cybercash -= slotsbet;
  79.             top_output(OUT_SCREEN, "\r\n\r\n^pThe Lucky 7 Slot Machine "
  80.                        "spins...     ^k");
  81.             if (od_control.baud == 0)
  82.                 {
  83.                 st = 38400 / 10 / 10;
  84.                 }
  85.             else
  86.                 {
  87.                 st = od_control.baud / 10 / 10;
  88.                 }
  89.             for (sd = 0; sd < st; sd++)
  90.                 {
  91.                 giveup_slice();
  92.                 snum[0] = random(10); snum[1] = random(10);
  93.                 snum[2] = random(10); snum[3] = random(10);
  94.                 snum[4] = random(10);
  95.                 sprintf(outbuf, "\b\b\b\b\b%i%i%i%i%i", snum[0], snum[1],
  96.                         snum[2], snum[3], snum[4]);
  97.                 top_output(OUT_SCREEN, outbuf);
  98.                 }
  99.             top_output(OUT_SCREEN, "\r\n\r\n");
  100.             wintype = 0;
  101.  
  102.             if (snum[0] == snum[1] || snum[3] == snum[4])
  103.                 {
  104.                 wintype = 1;
  105.                 }
  106.             if (snum[0] == 7)
  107.                 {
  108.                 wintype = 2;
  109.                 }
  110.             if (((snum[0] == snum[1]) && (snum[1] == snum[2])) ||
  111.                 ((snum[2] == snum[3]) && (snum[3] == snum[4])))
  112.                 {
  113.                 wintype = 3;
  114.                 }
  115.             if (snum[0] == 7 && snum[1] == 7)
  116.                 {
  117.                 wintype = 4;
  118.                 }
  119.             if (((snum[0] == snum[1]) && (snum[1] == snum[2]) &&
  120.                 (snum[2] == snum[3])) || ((snum[4] == snum[3]) &&
  121.                 (snum[3] == snum[2]) &&    (snum[2] == snum[1])))
  122.                 {
  123.                 wintype = 5;
  124.                 }
  125.             if (snum[0] == 7 && snum[1] == 7 && snum[2] == 7)
  126.                 {
  127.                 wintype = 6;
  128.                 }
  129.             if ((snum[0] == snum[1]) && (snum[1] == snum[2]) &&
  130.                 (snum[2] == snum[3]) && (snum[3] == snum[4]))
  131.                 {
  132.                 wintype = 7;
  133.                 }
  134.             if (snum[0] == 7 && snum[1] == 7 && snum[2] == 7 && snum[3] == 7)
  135.                 {
  136.                 wintype = 8;
  137.                 }
  138.             if (snum[0] == 7 && snum[1] == 7 && snum[2] == 7 &&
  139.                 snum[3] == 7 && snum[4] == 7)
  140.                 {
  141.                 wintype = 9;
  142.                 }
  143.  
  144.             switch(wintype)
  145.                 {
  146.                 case 0:
  147.                     payoff = slotsbet;
  148.                     sprintf(outbuf, "^mSorry, you lost your bet of "
  149.                             "^l%lu^m CyberDollar%s.\r\n", slotsbet,
  150.                             slotsbet == 1 ? "" : "s");
  151.                     top_output(OUT_SCREEN, outbuf);
  152.                     break;
  153.                 case 1:
  154.                     payoff = slotsbet * 2L;
  155.                     top_output(OUT_SCREEN, "^kYou got Two Of A Kind!!^n\r\n");
  156.                     sprintf(outbuf, "The payoff was ^l%lu^n "
  157.                             "CyberDollar%s.\r\n", payoff,
  158.                             payoff == 1 ? "" : "s");
  159.                     top_output(OUT_SCREEN, outbuf);
  160.                     user.cybercash += payoff;
  161.                     break;
  162.                 case 2:
  163.                     // Change the rest to check at the end for s or no s
  164.                     payoff = slotsbet * 3L;
  165.                     top_output(OUT_SCREEN, "^kYou got One Lucky 7!^n\r\n");
  166.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  167.                             "\r\n", payoff);
  168.                     top_output(OUT_SCREEN, outbuf);
  169.                     user.cybercash += payoff;
  170.                     break;
  171.                 case 3:
  172.                     payoff = slotsbet * 7L;
  173.                     top_output(OUT_SCREEN, "^I^kYou got Three Of A Kind!!!^A^n\r\n");
  174.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  175.                             "\r\n", payoff);
  176.                     top_output(OUT_SCREEN, outbuf);
  177.                     user.cybercash += payoff;
  178.                     break;
  179.                 case 4:
  180.                     payoff = slotsbet * 10L;
  181.                     top_output(OUT_SCREEN, "^I^kYou got Two Lucky 7s!!!!^A^n\r\n");
  182.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  183.                             "\r\n", payoff);
  184.                     top_output(OUT_SCREEN, outbuf);
  185.                     user.cybercash += payoff;
  186.                     break;
  187.                 case 5:
  188.                     payoff = slotsbet * 35L;
  189.                     top_output(OUT_SCREEN, "^I^kYou got Four Of A Kind!!!!!^A^n\r\n");
  190.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  191.                             "\r\n", payoff);
  192.                     top_output(OUT_SCREEN, outbuf);
  193.                     user.cybercash += payoff;
  194.                     break;
  195.                 case 6:
  196.                     payoff = slotsbet * 77L;
  197.                     top_output(OUT_SCREEN, "^I^kYou got Three Lucky 7s!!!!!!!^A^n\r\n");
  198.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  199.                             "\r\n", payoff);
  200.                     top_output(OUT_SCREEN, outbuf);
  201.                     user.cybercash += payoff;
  202.                     break;
  203.                 case 7:
  204.                     payoff = slotsbet * 500L;
  205.                     top_output(OUT_SCREEN, "^I^kYou got Five Of A "
  206.                                "Kind!!!!!!!!!!!!^A^n\r\n");
  207.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  208.                             "\r\n", payoff);
  209.                     top_output(OUT_SCREEN, outbuf);
  210.                     user.cybercash += payoff;
  211.                     break;
  212.                 case 8:
  213.                     payoff = slotsbet * 777L;
  214.                     top_output(OUT_SCREEN, "^I^kYou got Four Lucky "
  215.                                "7s!!!!!!!!!!^A^n\r\n");
  216.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  217.                             "\r\n", payoff);
  218.                         top_output(OUT_SCREEN, outbuf);
  219.                     user.cybercash += payoff;
  220.                     break;
  221.                 case 9:
  222.                     payoff = slotsbet * 7777L;
  223.                     top_output(OUT_SCREEN, "^I^k**************************************^A^k\r\n");
  224.                     top_output(OUT_SCREEN, "^I^k* You got the JACKPOT!!!!!!!!!!!!!!! *^A^k\r\n");
  225.                     top_output(OUT_SCREEN, "^I^k**************************************^A^n\r\n");
  226.                     sprintf(outbuf, "The payoff was ^l%lu^n CyberDollars."
  227.                             "\r\n", payoff);
  228.                     top_output(OUT_SCREEN, outbuf);
  229.                     user.cybercash += payoff;
  230.                     break;
  231.                 }
  232.             save_user_data(user_rec_num, &user);
  233.             sprintf(outbuf, "\r\n^jYou now have ^o%lu^j CyberDollars."
  234.                     "\r\n\r\n", user.cybercash);
  235.             top_output(OUT_SCREEN, outbuf);
  236.             load_slots_stats(&sstat);
  237.             sstat.pulls++;
  238.             sstat.spent += slotsbet;
  239.             sstat.hits[wintype]++;
  240.             sstat.totals[wintype] += payoff;
  241.             save_slots_stats(&sstat);
  242.             }
  243.         }
  244.     wasused = 1;
  245.     }
  246. if (!stricmp(get_word(1), "ODDS"))
  247.     {
  248.     top_output(OUT_SCREEN, "\r\n\r\n            ^oLucky 7 Slots ^h- ^pOdds and Payoff Table\r\n");
  249.     top_output(OUT_SCREEN, "^c+------------------+---------------+-------------+-----------+\r\n");
  250.     top_output(OUT_SCREEN, "^c| ^mCombination Name ^c| ^mExample       ^c| ^mOdds        ^c| ^mPayoff    ^c|\r\n");
  251.     top_output(OUT_SCREEN, "^c+------------------+---------------+-------------+-----------+\r\n");
  252.     top_output(OUT_SCREEN, "^c| ^nTwo Of A Kind    ^c| ^pnnxxx / xxxnn ^c| ^o1 ^jin ^o5      ^c| ^l   2 ^nto ^l1 ^c|\r\n");
  253.     top_output(OUT_SCREEN, "^c| ^nOne Lucky 7      ^c| ^p  7 x x x x   ^c| ^o1 ^jin ^o10     ^c| ^l   3 ^nto ^l1 ^c|\r\n");
  254.     top_output(OUT_SCREEN, "^c| ^nThree Of A Kind  ^c| ^pnnnxx / xxnnn ^c| ^o1 ^jin ^o50     ^c| ^l   7 ^nto ^l1 ^c|\r\n");
  255.     top_output(OUT_SCREEN, "^c| ^nTwo Lucky 7s     ^c| ^p  7 7 x x x   ^c| ^o1 ^jin ^o100    ^c| ^l  10 ^nto ^l1 ^c|\r\n");
  256.     top_output(OUT_SCREEN, "^c| ^nFour Of A Kind   ^c| ^pnnnnx / xnnnn ^c| ^o1 ^jin ^o500    ^c| ^l  35 ^nto ^l1 ^c|\r\n");
  257.     top_output(OUT_SCREEN, "^c| ^nThree Lucky 7s   ^c| ^p  7 7 7 x x   ^c| ^o1 ^jin ^o1000   ^c| ^l  77 ^nto ^l1 ^c|\r\n");
  258.     top_output(OUT_SCREEN, "^c| ^nFive Of A Kind   ^c| ^p  n n n n n   ^c| ^o1 ^jin ^o10000  ^c| ^l 500 ^nto ^l1 ^c|\r\n");
  259.     top_output(OUT_SCREEN, "^c| ^nFour Lucky 7s    ^c| ^p  7 7 7 7 x   ^c| ^o1 ^jin ^o10000  ^c| ^l 777 ^nto ^l1 ^c|\r\n");
  260.     top_output(OUT_SCREEN, "^c| ^nLucky 7 JACKPOT! ^c| ^p  7 7 7 7 7   ^c| ^o1 ^jin ^o100000 ^c| ^l7777 ^nto ^l1 ^c|\r\n");
  261.     top_output(OUT_SCREEN, "^c+------------------+---------------+-------------+-----------+\r\n");
  262.     top_output(OUT_SCREEN, "^c| ^nOverall          ^c| ^i- - - - - - - ^c| ^o1 ^jin ^o3.0011 ^c| ^i- - - - - ^c|\r\n");
  263.     top_output(OUT_SCREEN, "^c+------------------+---------------+-------------+-----------+\r\n\r\n");
  264.     wasused = 1;
  265.     }
  266. if (!stricmp(get_word(1), "STATS"))
  267.     {
  268.     unsigned long tval1, tval2;
  269.     long tval3;
  270.     char ssd;
  271.  
  272.     load_slots_stats(&sstat); save_slots_stats(&sstat);
  273.     sprintf(outbuf, "\r\n\r\n                 ^oLucky 7 Slots ^h- ^pStatistics\r\n"); top_output(OUT_SCREEN, outbuf);
  274.     sprintf(outbuf, "^c+------------------+-------------+-------------------------+\r\n"); top_output(OUT_SCREEN, outbuf);
  275.     sprintf(outbuf, "^c| ^mCategory         ^c| ^mOccurrences ^c| ^mCyberCash Totals        ^c|\r\n"); top_output(OUT_SCREEN, outbuf);
  276.     sprintf(outbuf, "^c+------------------+-------------+-------------------------+\r\n"); top_output(OUT_SCREEN, outbuf);
  277.     sprintf(outbuf, "^c| ^nNo Prize         ^c| ^l%11lu ^c| ^o%11lu ^j(Collected) ^c|\r\n", sstat.hits[0], sstat.totals[0]); top_output(OUT_SCREEN, outbuf);
  278.     sprintf(outbuf, "^c| ^nTwo Of A Kind    ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[1], sstat.totals[1]); top_output(OUT_SCREEN, outbuf);
  279.     sprintf(outbuf, "^c| ^nOne Lucky 7      ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[2], sstat.totals[2]); top_output(OUT_SCREEN, outbuf);
  280.     sprintf(outbuf, "^c| ^nThree Of A Kind  ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[3], sstat.totals[3]); top_output(OUT_SCREEN, outbuf);
  281.     sprintf(outbuf, "^c| ^nTwo Lucky 7s     ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[4], sstat.totals[4]); top_output(OUT_SCREEN, outbuf);
  282.     sprintf(outbuf, "^c| ^nFour Of A Kind   ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[5], sstat.totals[5]); top_output(OUT_SCREEN, outbuf);
  283.     sprintf(outbuf, "^c| ^nThree Lucky 7s   ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[6], sstat.totals[6]); top_output(OUT_SCREEN, outbuf);
  284.     sprintf(outbuf, "^c| ^nFive Of A Kind   ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[7], sstat.totals[7]); top_output(OUT_SCREEN, outbuf);
  285.     sprintf(outbuf, "^c| ^nFour Lucky 7s    ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[8], sstat.totals[8]); top_output(OUT_SCREEN, outbuf);
  286.     sprintf(outbuf, "^c| ^nLucky 7 JACKPOT! ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", sstat.hits[9], sstat.totals[9]); top_output(OUT_SCREEN, outbuf);
  287.     sprintf(outbuf, "^c+------------------+-------------+-------------------------+\r\n"); top_output(OUT_SCREEN, outbuf);
  288.     sprintf(outbuf, "^c| ^nTotal  -  Wagers ^c| ^l%11lu ^c| ^o%11lu ^j(Wagered)   ^c|\r\n", sstat.pulls, sstat.spent); top_output(OUT_SCREEN, outbuf);
  289.     for (tval1 = 0, tval2 = 0, ssd = 1; ssd < 10; tval1 += sstat.hits[ssd],
  290.          tval2 += sstat.totals[ssd], ssd++);
  291.     sprintf(outbuf, "^c|           ^nPrizes ^c| ^l%11lu ^c| ^o%11lu ^j(Awarded)   ^c|\r\n", tval1, tval2); top_output(OUT_SCREEN, outbuf);
  292.     tval3 = sstat.spent - tval2;
  293.     sprintf(outbuf, "^c|           ^nProfit ^c|             ^c| ^o%11li ^j(Profit)    ^c|\r\n", tval3); top_output(OUT_SCREEN, outbuf);
  294.     sprintf(outbuf, "^c+------------------+-------------+-------------------------+\r\n\r\n"); top_output(OUT_SCREEN, outbuf);
  295.     wasused = 1;
  296.     }
  297.  
  298. if (!wasused)
  299.     {
  300.     top_output(OUT_SCREEN, "\r\n\r\n^oLucky 7 Slots ^h- ^pCommands\r\n");
  301.     top_output(OUT_SCREEN, "^c------------------------\r\n\r\n");
  302.     top_output(OUT_SCREEN, "^lHELP     ^g- ^mThis help screen.\r\n");
  303.     top_output(OUT_SCREEN, "^lBET xxxx ^g- ^mChange bet to ^oxxxx^m (^k1^m to ^k500000^m).  Omit ^oxxxx^m to show current bet.\r\n");
  304.     top_output(OUT_SCREEN, "^lPULL xx  ^g- ^mPull the lever ^oxx^m times (^k1^m to ^k10^m).  Omit ^oxx^m to pull just once.\r\n");
  305.     top_output(OUT_SCREEN, "^lODDS     ^g- ^mShow odds and payoff table.\r\n");
  306.     top_output(OUT_SCREEN, "^lSTATS    ^g- ^mShow cumulative Lucky 7 Statistics.\r\n");
  307.     top_output(OUT_SCREEN, "\r\n^nTo use a command, type ^lSLOTS^n followed by a "
  308.                "space and then the command.\r\n\r\n");
  309.     }
  310.  
  311. return;
  312. }
  313.  
  314. void load_slots_stats(slots_stat_typ *slbuf)
  315. {
  316.  
  317. lseek(slotsfil, 0L, SEEK_SET);
  318. rec_locking(REC_LOCK, slotsfil, 0L, sizeof(slots_stat_typ));
  319. read(slotsfil, slbuf, sizeof(slots_stat_typ));
  320.  
  321. return;
  322. }
  323.  
  324. void save_slots_stats(slots_stat_typ *slbuf)
  325. {
  326.  
  327. lseek(slotsfil, 0L, SEEK_SET);
  328. write(slotsfil, slbuf, sizeof(slots_stat_typ));
  329. rec_locking(REC_UNLOCK, slotsfil, 0L, sizeof(slots_stat_typ));
  330.  
  331. return;
  332. }
  333.