home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1997 January / CD_shareware_1-97.iso / DOS / COMUNICA / TMLOTO11.ZIP / TIMELOTO.MEX < prev    next >
Encoding:
Text File  |  1996-10-21  |  15.5 KB  |  420 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2.  
  3. // A Lottery time gambling program written and copyright by Mark Taylor.   //
  4.  
  5. //                                                                         //
  6.  
  7. // Allows a user to gamble his online time left,against a set number of    //
  8.  
  9. // lines of lottery type numbers ie 6 numbers per line.                    //
  10.  
  11. // The maximum number of lines allowed is 10,but if a user does'nt have    //
  12.  
  13. // time left then only the time/bet can be chosen.                         //
  14.  
  15. // Most of the defines can be changed with no other changes to the program //
  16.  
  17. // The values of mine are based on a User having 60 mins a day on-line time//
  18.  
  19. //                                                                         //
  20.  
  21. // I use Maximus V3.01 for OS/2,but it should work with Dos systems        //
  22.  
  23. // To use this program I place it on the main menu with the following line //
  24.  
  25. // Mex             m\timelotto            Disgrace "Time Lottery"          //
  26.  
  27. //                                                                         //
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34.  
  35. // Normal rules apply,this is my copyrighted program                       //
  36.  
  37. //                                                                         //
  38.  
  39. // If you use and like the program please either netmail or email me at    //
  40.  
  41. // the address' below.If you like to send some money,then let me know and  //
  42.  
  43. // I'll give you my home address :)                                        //
  44.  
  45. //                                                                         //
  46.  
  47. // You may alter this program for YOUR OWN USE ONLY,you cannot alter it    //
  48.  
  49. // and send it out in a modified form.                                     //
  50.  
  51. // I'd welcome comments,bug reports,ideas or code to be added              //
  52.  
  53. // You may reach me at : 2:253/35@fidonet                                  //
  54.  
  55. //                       240:360/45@mercury                                //
  56.  
  57. //                       81:444/25@os2net                                  //
  58.  
  59. //                       mark.taylor@zetnet.co.uk                          //
  60.  
  61. //                       mark@trythat.coracle.com                          //
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #include <max.mh>
  70.  
  71. #include <rand.mh>
  72.  
  73.  
  74.  
  75. #define VERSION    " V1.1\n"  // Version number
  76.  
  77.  
  78.  
  79. #define MAX_LINES 10          // Maximum number of lines,use the users screen length
  80.  
  81. #define RANDOM    49          // Maximum value of number to pick
  82.  
  83. #define BALLS      6          // Number of random numbers to pick per line
  84.  
  85. #define TRY       50          // Number of random numbers before one is picked
  86.  
  87. #define BET        5          // Number of minutes to gamble on each line
  88.  
  89. #define MATCHED_2  2          // Number of minutes given for 2 numbers matched per line
  90.  
  91. #define MATCHED_3  5          // Number of minutes given for 3 numbers matched per line
  92.  
  93. #define MATCHED_4 10          // Number of minutes given for 4 numbers matched per line
  94.  
  95. #define MATCHED_5 15          // Number of minutes given for 5 numbers matched per line
  96.  
  97. #define MATCHED_6 25          // Number of minutes given for 6 numbers matched per line
  98.  
  99. #define MAX_TIME  120         // Maxium of time allowed for each user to be added
  100.  
  101.  
  102.  
  103. int:    minutes_won ;    // total minutes won,if any :)
  104.  
  105. string: blanks ;         // Blank line
  106.  
  107.  
  108.  
  109. array [1..BALLS] of int: computer_balls ; // Array for chosen balls
  110.  
  111. array [1..BALLS] of int: user_balls ;  // Array for user chosen lottery balls
  112.  
  113.  
  114.  
  115. // Prototypes
  116.  
  117. string centre(string: s1) ;
  118.  
  119. void cls() ;
  120.  
  121. void print_title() ;
  122.  
  123. void pick_numbers(array [1..BALLS] of int: balls) ;
  124.  
  125. int getrandom() ;
  126.  
  127. void sort_numbers(array[1..BALLS] of int: balls) ;
  128.  
  129. void get_user_numbers() ;
  130.  
  131. int get_number_of_trys() ;
  132.  
  133. void print_line(array[1..BALLS] of int: balls,int: x) ;
  134.  
  135. int check_for_match(int: ball_to_check) ;
  136.  
  137. int main() ;
  138.  
  139. void help() ;
  140.  
  141.  
  142.  
  143.  
  144.  
  145. // Centre Output
  146.  
  147. string centre(string: s1)
  148.  
  149. {
  150.  
  151.   string: s2;
  152.  
  153.   int: i1;
  154.  
  155.   s2:="\r";
  156.  
  157.   for(i1:=1; i1<=(((term_width()-2)-strlen(s1))/2); i1:=i1+1)
  158.  
  159.      { s2:=s2+" "; }
  160.  
  161.   s2:=s2+s1;
  162.  
  163.   return s2;
  164.  
  165. }
  166.  
  167.  
  168.  
  169. // Clear Screen
  170.  
  171. void cls()
  172.  
  173. {
  174.  
  175.   print("\x0c");
  176.  
  177. }
  178.  
  179.  
  180.  
  181. // Just print out title and advert etc..
  182.  
  183. void print_title()
  184.  
  185. {
  186.  
  187.   cls() ;
  188.  
  189.   print(COL_LCYAN) ;
  190.  
  191.   print(centre("Lottery Time Gamble"+VERSION)) ;
  192.  
  193.   print(centre("Written By Mark Taylor (c)\n")) ;
  194.  
  195.   print(centre("TryThat SoftWare  1996\n")) ;
  196.  
  197.   print(COL_WHITE"\n") ;
  198.  
  199. }
  200.  
  201.  
  202.  
  203. // computer picked numbers
  204.  
  205. void pick_numbers(array [1..BALLS] of int: balls)
  206.  
  207. {
  208.  
  209. int: i,x,test,number ;
  210.  
  211.  
  212.  
  213.   print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "                   ") ;
  214.  
  215.   print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "Picking Numbers ") ;
  216.  
  217.  
  218.  
  219.   for(i := 1 ; i <= BALLS ; i := i+1)
  220.  
  221.      {
  222.  
  223.      balls[i] := 50 ;  // Set ball to a number,that is false
  224.  
  225.      test := FALSE ;
  226.  
  227.      while(test = FALSE)
  228.  
  229.           {
  230.  
  231.           test := TRUE ;
  232.  
  233.           number := getrandom() ; // Get a random ball
  234.  
  235.           // Make sure no dupes
  236.  
  237.           for(x := 1 ; x < BALLS+1 ; x := x+1)
  238.  
  239.              if(balls[x] = number)
  240.  
  241.                test := FALSE ;
  242.  
  243.           }
  244.  
  245.      balls[i] := number ;
  246.  
  247.      }
  248.  
  249.   sort_numbers(balls) ;
  250.  
  251. }
  252.  
  253.  
  254.  
  255. // get a random number and print spinning bar
  256.  
  257. int getrandom()
  258.  
  259. {
  260.  
  261. int: number,z ;
  262.  
  263.  
  264.  
  265.   for(z := 0 ; z < TRY ; z := z+1)
  266.  
  267.      {
  268.  
  269.      number := (rand()%RANDOM)+1 ; // Get a random number
  270.  
  271.      if(z/4 = 0)
  272.  
  273.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "\\") ;
  274.  
  275.      if(z/8 = 0)
  276.  
  277.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "-") ;
  278.  
  279.      if(z/12 = 0)
  280.  
  281.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "/") ;
  282.  
  283.      if(z/16 = 0)
  284.  
  285.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "|") ;
  286.  
  287.      }
  288.  
  289.   print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE " ") ;
  290.  
  291.  
  292.  
  293. return number ;
  294.  
  295. }
  296.  
  297.  
  298.  
  299. // Put balls into order
  300.  
  301. void sort_numbers(array[1..BALLS] of int: balls)
  302.  
  303. {
  304.  
  305. // There may be a faster way to sort,but then again there are'nt many numbers
  306.  
  307.  
  308.  
  309. int: swtch,x,temp ;
  310.  
  311.  
  312.  
  313.    swtch := TRUE ;
  314.  
  315.    while(swtch = TRUE)
  316.  
  317.         {
  318.  
  319.         swtch := FALSE ;
  320.  
  321.         for(x := 1; x < BALLS ; x := x+1)
  322.  
  323.            if(balls[x] >balls[x+1])
  324.  
  325.              {
  326.  
  327.              temp := balls[x] ;
  328.  
  329.              balls[x] := balls[x+1] ;
  330.  
  331.              balls[x+1] := temp ;
  332.  
  333.              swtch := TRUE ;
  334.  
  335.              }
  336.  
  337.         }
  338.  
  339. }
  340.  
  341.  
  342.  
  343. // get user numbers
  344.  
  345. void get_user_numbers()
  346.  
  347. {
  348.  
  349. int:    number,swtch,x,i;
  350.  
  351. string: get_number,prompt;
  352.  
  353.  
  354.  
  355.   print(AVATAR_GOTO,(char)10,(char)1,blanks) ;
  356.  
  357.   // print line ready to display user numbers
  358.  
  359.   print(AVATAR_GOTO,(char)10,(char)1,"Your Numbers - ") ;
  360.  
  361.  
  362.  
  363.  
  364.  
  365.   for(i := 1 ; i < BALLS+1 ; i := i+1)
  366.  
  367.       {
  368.  
  369.       prompt := "Please enter a number between 1 and "+itostr(RANDOM)+",then press return ";
  370.  
  371.       swtch := TRUE ;
  372.  
  373.       user_balls[i] := 50 ; // set a dummy number
  374.  
  375.       while(swtch = TRUE)
  376.  
  377.            {
  378.  
  379.            while(swtch = TRUE)
  380.  
  381.                 {
  382.  
  383.                 // Get a number between 1 & RANDOM (49)
  384.  
  385.                 print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a line of blanks
  386.  
  387.                 print(AVATAR_GOTO,(char)5,(char)1 ) ;
  388.  
  389.                 input_str(get_number, INPUT_WORD, 0, 2,prompt);
  390.  
  391.                 number := strtoi(get_number) ;
  392.  
  393.                 if(number < 1 OR number > RANDOM)
  394.  
  395.                    prompt := "You must enter a number between 1 and "+itostr(RANDOM)+" " ;
  396.  
  397.                 else
  398.  
  399.                    swtch := FALSE ;
  400.  
  401.                 }
  402.  
  403.  
  404.  
  405.            // Make sure no dupes
  406.  
  407.            for(x := 1 ; x < BALLS+1 ; x := x+1)
  408.  
  409.               if(user_balls[x] = number)
  410.  
  411.                 {
  412.  
  413.                 swtch := TRUE ;
  414.  
  415.                 prompt := "Please pick a differnt a number " ;
  416.  
  417.                 }
  418.  
  419.  
  420.  
  421.            // this is a good number,so use it
  422.  
  423.            if(swtch = FALSE)
  424.  
  425.              {
  426.  
  427.              user_balls[i] := number ;
  428.  
  429.              print(AVATAR_GOTO,(char)10,(char)(15+(i*3)),COL_YELLOW,number,COL_WHITE) ;
  430.  
  431.              }
  432.  
  433.             }
  434.  
  435.       }
  436.  
  437.  
  438.  
  439.   sort_numbers(user_balls) ;   // put the balls in order
  440.  
  441. }
  442.  
  443.  
  444.  
  445. // get number of lines to bet on
  446.  
  447. int get_number_of_trys()
  448.  
  449. {
  450.  
  451. int:    number,swtch ;
  452.  
  453. long:   available_trys ;
  454.  
  455. string: get_number,prompt ;
  456.  
  457.  
  458.  
  459.   available_trys := timeleft() / BET ;  // Get users time left,and see how many bets
  460.  
  461.   if(available_trys > MAX_LINES)        // available.
  462.  
  463.     available_trys := MAX_LINES ;       // If more than max limit,set it to max limit
  464.  
  465.  
  466.  
  467.   prompt := "You have "+ltostr(timeleft())+" minutes to play with.\n"+
  468.  
  469.             "Enter how many bets you'd like,upto a maximum of "+
  470.  
  471.             ltostr(available_trys)+",\nand remember each bet is "+itostr(BET)+
  472.  
  473.             " Minutes taken off of your time? ";
  474.  
  475.  
  476.  
  477.   swtch := TRUE ;
  478.  
  479.   while(swtch = TRUE)
  480.  
  481.        {
  482.  
  483.        print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a blank line
  484.  
  485.        print(AVATAR_GOTO,(char)6,(char)1,blanks) ; // Print a blank line
  486.  
  487.        print(AVATAR_GOTO,(char)7,(char)1,blanks) ; // Print a blank line
  488.  
  489.        print(AVATAR_GOTO,(char)5,(char)1 ) ;       // set ready for printing
  490.  
  491.        input_str(get_number, INPUT_WORD, 0, 2,prompt);
  492.  
  493.        number := strtoi(get_number) ;   // convert string to int
  494.  
  495.        if(number < 1 OR number > available_trys)
  496.  
  497.           prompt := "You must enter a number between 1 and "+ltostr(available_trys)+" ? " ;
  498.  
  499.        else
  500.  
  501.           swtch := FALSE ;
  502.  
  503.        }
  504.  
  505.  
  506.  
  507.   timeadjustsoft(-(number * BET * 60) ) ; // take off bet from users time
  508.  
  509.   print(AVATAR_GOTO,(char)6,(char)1,blanks) ;
  510.  
  511.   print(AVATAR_GOTO,(char)7,(char)1,blanks) ;
  512.  
  513.   print(AVATAR_GOTO,(char)6,(char)1 ) ;
  514.  
  515.   print("You have ",timeleft()," minutes left,after your bet of ",number*BET," minutes.\n") ;
  516.  
  517.   log("-Bet "+itostr((number * BET))+" minutes" ); // Log the bet to logfile
  518.  
  519.  
  520.  
  521. return number ;
  522.  
  523. }
  524.  
  525.  
  526.  
  527. // print out each computer line,then check for any winning numbers
  528.  
  529. void print_line(array[1..BALLS] of int: balls,int: x)
  530.  
  531. {
  532.  
  533. int: y,
  534.  
  535.      matches ;
  536.  
  537.  
  538.  
  539.   matches := 0 ;
  540.  
  541.   // Print out results,pad with spaces to make neat
  542.  
  543.   print(AVATAR_GOTO,(char)(11+x),(char)1,
  544.  
  545.         COL_LRED,"Line ",strpadleft(itostr(x),2,' ')," : ",COL_WHITE) ;
  546.  
  547.  
  548.  
  549.   for(y := 1 ; y < BALLS+1 ; y := y+1)
  550.  
  551.      if(check_for_match(balls[y]) = TRUE)
  552.  
  553.         {
  554.  
  555.         print(COL_GREEN,strpadleft(itostr(balls[y]),4,' '),COL_WHITE) ;
  556.  
  557.         matches := matches + 1 ;
  558.  
  559.         }
  560.  
  561.      else
  562.  
  563.         print(strpadleft(itostr(balls[y]),4,' ')) ;
  564.  
  565.  
  566.  
  567. // print out results of any matches above 2 numbers
  568.  
  569.   if(matches = 2)
  570.  
  571.      {
  572.  
  573.      print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_2," Minutes",COL_WHITE ) ;
  574.  
  575.      minutes_won := minutes_won+MATCHED_2 ;
  576.  
  577.      }
  578.  
  579.   else if(matches = 3)
  580.  
  581.          {
  582.  
  583.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_3," Minutes",COL_WHITE ) ;
  584.  
  585.          minutes_won := minutes_won+MATCHED_3 ;
  586.  
  587.          }
  588.  
  589.   else if(matches = 4)
  590.  
  591.          {
  592.  
  593.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_4," Minutes",COL_WHITE ) ;
  594.  
  595.          minutes_won := minutes_won+MATCHED_4 ;
  596.  
  597.          }
  598.  
  599.   else if(matches = 5)
  600.  
  601.          {
  602.  
  603.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_5," Minutes",COL_WHITE ) ;
  604.  
  605.          minutes_won := minutes_won+MATCHED_5 ;
  606.  
  607.          }
  608.  
  609.   else if(matches = 6)
  610.  
  611.          {
  612.  
  613.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_6," Minutes",COL_WHITE ) ;
  614.  
  615.          minutes_won := minutes_won+MATCHED_6 ;
  616.  
  617.          }
  618.  
  619.        else
  620.  
  621.          print(AVATAR_GOTO,(char)(11+x),(char)40,"You Have Not Won Anything!" ) ;
  622.  
  623.  
  624.  
  625. }
  626.  
  627.  
  628.  
  629. //simple check routine
  630.  
  631. int check_for_match(int: ball_to_check)
  632.  
  633. {
  634.  
  635. int: x,swtch ;
  636.  
  637.  
  638.  
  639.  swtch := FALSE ;
  640.  
  641.  
  642.  
  643.  for(x := 1 ; x < BALLS+1 ; x := x+1)
  644.  
  645.     if(user_balls[x] = ball_to_check)
  646.  
  647.        swtch := TRUE ;
  648.  
  649.  
  650.  
  651. return swtch ;
  652.  
  653. }
  654.  
  655.  
  656.  
  657. // show a very simple help screen
  658.  
  659. void help()
  660.  
  661. {
  662.  
  663. int: x ;
  664.  
  665.  
  666.  
  667. // you should'nt need to touch this much,unless you choose differnt colours
  668.  
  669. // for the results etc,but it does use the defines for most things.
  670.  
  671. // and its only 1 screen long :)
  672.  
  673.  
  674.  
  675.   print(AVATAR_GOTO,(char)5,(char)1,"Do you need instructions [y/N]" ) ;
  676.  
  677.   x := getch() ;
  678.  
  679.   if(x = 'N' or x = 'n' or x =13) // or return key
  680.  
  681.      return ;    // if not then lets get back to business
  682.  
  683.  
  684.  
  685.   print(AVATAR_GOTO,(char)5,(char)1 ) ;
  686.  
  687.   print("The object for this game is to gain on-line time,you do this by playing",
  688.  
  689.       "\nthe lottery,with a slight difference,you are gambling your time for    ",
  690.  
  691.       "\ntoday,if you lose it all don't worry,you'll be back to normal tomorrow.",
  692.  
  693.       "\n",
  694.  
  695.       "\nYou pick ",BALLS," numbers within the range of 1 to ",RANDOM,
  696.  
  697.       ",and then decide how many",
  698.  
  699.       "\nlines you want the computer to generate,each line costs you ",BET," minutes,   ",
  700.  
  701.       "\nand you can have a maximum of ",MAX_LINES," lines.                     ",
  702.  
  703.       "\nYou can win time back for a match on 2 to ",BALLS," numbers,upto a maximum of   ",
  704.  
  705.       "\n",MAX_TIME," minutes.",
  706.  
  707.       "\nWhen you get a matching number it will show up as green eg ",COL_GREEN,"10"
  708.  
  709.       ,COL_WHITE," and any    ",
  710.  
  711.       "\ntime won will show up as blue eg ",COL_LCYAN,"15",COL_WHITE,".",
  712.  
  713.       "\n",
  714.  
  715.       "\nThats about it really,if you have problems please,let the sysop know,so   ",
  716.  
  717.       "\nI can fix them quickly.",
  718.  
  719.       "\n\nHave Fun. Mark Taylor.",
  720.  
  721.       "\n\nPress A Key"
  722.  
  723.       ) ;
  724.  
  725.  
  726.  
  727.   x := getch() ;
  728.  
  729.   // Clear the screen from just below the title
  730.  
  731.   for(x := 5 ; x < 23 ; x:= x+1)
  732.  
  733.      print(AVATAR_GOTO,(char)x,(char)1,blanks ) ;
  734.  
  735. }
  736.  
  737.  
  738.  
  739. // main loop
  740.  
  741. int main()
  742.  
  743. {
  744.  
  745. int: x,lines ;
  746.  
  747.  
  748.  
  749.      log(":Starting Lottery Time Gamble"); // Log the start to logfile
  750.  
  751.      srand(time()); // Seed random generator
  752.  
  753.      blanks := strpad(blanks,term_width(),' ') ; // set a blank line to users screen width
  754.  
  755.      minutes_won := 0 ;        // set winnings to zero
  756.  
  757.  
  758.  
  759.  
  760.  
  761.      print_title() ;      // print title
  762.  
  763.      help() ;             // check if instructions needed
  764.  
  765.      get_user_numbers();  // Get user numbers
  766.  
  767.      lines := get_number_of_trys() ;   // get number of lines
  768.  
  769.  
  770.  
  771.      // go through for each line
  772.  
  773.      for(x:= 1 ; x < lines+1 ; x := x+1)
  774.  
  775.         {
  776.  
  777.         pick_numbers(computer_balls) ;
  778.  
  779.         print_line(computer_balls,x) ;
  780.  
  781.         }
  782.  
  783.  
  784.  
  785. // pretty up screen and print results
  786.  
  787. // it does seem as though the user comes off worse most times :)
  788.  
  789. // I expect this could be changed so there is a slight bias in favour os the user,
  790.  
  791. // but that would take all the fun out of it :)
  792.  
  793.  
  794.  
  795.   print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "                   ") ;
  796.  
  797.  
  798.  
  799.   if(minutes_won > MAX_TIME)
  800.  
  801.      minutes_won := MAX_TIME ;
  802.  
  803.  
  804.  
  805.   timeadjustsoft(minutes_won * 60 ) ; // Add any time won to user time,in minutes
  806.  
  807.  
  808.  
  809.   // print(AVATAR_GOTO,(char)22,(char)1,"You added a total of ",minutes_won,
  810.  
  811.   //     " minutes to your time,you now have ",timeleft()," minutes") ;
  812.  
  813.   // print(AVATAR_GOTO,(char)23,(char)1,"Please Press A Key") ;
  814.  
  815.  
  816.  
  817.   print(AVATAR_GOTO,(char)(11+lines),(char)1) ;  //set cursor to line after all numbers
  818.  
  819.   print("\n\nYou added a total of ",minutes_won," minutes to your time,"
  820.  
  821.         "you now have ",timeleft()," minutes") ;
  822.  
  823.   print("\nPlease Press A Key") ;
  824.  
  825.   x := getch() ;
  826.  
  827.   log("-Gained "+itostr(minutes_won)+" minutes" ); // Log any winnings logfile
  828.  
  829.  
  830.  
  831.  
  832.  
  833. return 0;
  834.  
  835. }
  836.  
  837.  
  838.  
  839.