/////////////////////////////////////////////////////////////////////////////// // File: jackpot.cs // // Contents: // A sample script that acts as a simple slot machine. // It also demonstrates capture of command return codes. // // It will look its best if the TinyTERM window is maximized first. // // Originated by P. Clark, Century Software Inc. 3/11/99 /////////////////////////////////////////////////////////////////////////////// // intro text te.cls(); te.displaynl(" Welcome to the JACKPOT! game."); te.displaynl(""); te.display(" Slots cost "); te.display(_chr(36)); te.display("1 per pull. Two of a kind wins "); te.display(_chr(36)); te.display("1 to "); te.display(_chr(36)); te.displaynl("10."); te.display(" Three of a kind wins "); te.display(_chr(36)); te.display("10 to "); te.display(_chr(36)); te.displaynl("100!"); te.displaynl(""); // check for usable emulation if (te.emulation > 20) { te.displaynl("JACKPOT! cannot be run on TN3270, TN5250 or TTY emulation."); return(0); } // initialize variables global done = false; global tries = 0; global wins = 0; global finished = false; global fruit = dimstr(10); global w_temp = _val(right(_str(time()),5)); global n_temp = w_temp * w_temp; // initialize the fruit array fruit[0] = "LEMON "; fruit[1] = "LIME "; fruit[2] = "ORANGE "; fruit[3] = "CHERRY "; fruit[4] = "APPLE "; fruit[5] = "GUAVA "; fruit[6] = "PLUM "; fruit[7] = "PEACH "; fruit[8] = "BELL "; fruit[9] = "KEY "; // get permission to proceed if ( msgbox("Do you want to play?","Jackpot!",2) == 1 ) { te.displaynl(""); te.displaynl(" OK. Come back some other time."); return(0); } SetFocus(GetObjectHWND(TEObj)); global start = _val(te.read("How much money did you bring? ", true)); global cash = start; // start the slots do { winnings = 0; tries = tries + 1; cash = cash - 1; ShowCash(); Spin(); if (winnings > 0) Count(); else loseDisplay(); ShowCash(); // check to see if the game is over if ( cash == 0 ) { finished = true; te.cls(); te.displaynl(" You're out of money."); te.displaynl(""); } else { if ( MsgBox("Would you like to spin again?","Jackpot!",2) == 1) finished = true; } } while (finished == false); // set a final message based on winnings or loss if ( cash < start ) { finalmsg = "Come back and lose more money anytime."; } else { if ( cash == start ) finalmsg = "Come back again."; else finalmsg = "Enjoy your winnings. Come back soon."; } te.displaynl(""); te.displaynl(finalmsg); // functions follow function ShowCash() { te.cls(); te.display("You have "); te.display(_chr(36)); te.display(_str(cash)); te.displaynl(" now."); } function Spin() { // generate a pseudorandom number w_temp = _val(left(_str(n_temp),5)); n_temp = w_temp * w_temp; // set the individual wheels wheels = right(_str(n_temp),3); wfirst = _val(left(wheels,1)); wsecond = _val(midstr(wheels,2,1)); wthird = _val(right(wheels,1)); // count winnings, if any if ( wfirst == wsecond ) winnings = wfirst + 1; if ( wfirst == wthird ) winnings = wthird + 1; if ( wsecond == wthird ) winnings = wsecond + 1; if (( wfirst == wsecond) && (wsecond == wthird)) winnings = 10 * (wfirst + 1); if (winnings > 0) wins = wins + 1; // display the spin results results = fruit[wfirst] + fruit[wsecond] + fruit[wthird]; MsgBox(results,"Jackpot",0); } function Count() { // add up the winning money and display it cash = cash + winnings; line1 = "You just won " + _chr(36) + _str(winnings) + "."; line2 = "You have " + _chr(36) + _str(cash) + " now."; line3 = "You've hit " + _str(wins) + " in " + _str(tries) + " spins."; fullline = line1 + "\r\n" + line2 + "\r\n" + line3; MsgBox(fullline,"Jackpot!",0); } function loseDisplay() { // add up the losing money and display it line1 = "You just lost $1."; line2 = "You have " + _chr(36) + _str(cash) + " now."; line3 = "You've hit " + _str(wins) + " in " + _str(tries) + " spins."; fullline = line1 + "\r\n" + line2 + "\r\n" + line3; MsgBox(fullline,"Jackpot!",0); }