|
1 | | -center = function(s,n) |
2 | | - h = floor((n - s.len)/2) |
3 | | - s = " " * h + s + " " * n |
4 | | - return s[:n] |
5 | | -end function |
| 1 | +print " "*30 + "Slots" |
| 2 | +print " "*15 + "Creative Computing Morristown New Jersey" |
| 3 | +print; print; print |
6 | 4 |
|
7 | | -Machine = {"symbols": ["Bar", "Bell", "Orange", "Lemon", "Plum ", "Cherry"]} |
8 | | -Machine.money = 0 |
9 | | -Machine.bet = 0 |
10 | | -Machine.playing = true |
11 | | -Machine.reels = [0,0,0] |
12 | | -Machine.results = null |
| 5 | +// PRODUCED BY FRED MIRABELLE AND BOB HARPER ON JAN 29, 1973 |
| 6 | +// IT SIMULATES THE SLOT MACHINE. |
| 7 | +// (Ported to MiniScript by Joe Strout on Oct 04, 2023) |
13 | 8 |
|
14 | | -Machine.reelsSpin = function(n, msg, row) |
15 | | - env = [1,.95,.9,.85,.25,.2,.15,.1,.05,0] |
16 | | - bell = new Sound |
17 | | - bell.init .1, 800, env, Sound.sineWave |
18 | | - for i in range(1,2) |
19 | | - s1 = new Sound |
20 | | - s1.init .2, i * 800 + 800, env, Sound.sineWave |
21 | | - bell.mix(s1, 1 / (2 ^ i)) |
22 | | - end for |
23 | | - for i in range(1,n) |
24 | | - bell.play |
25 | | - ix = 0 |
26 | | - while bell.isPlaying |
27 | | - text.row = row |
28 | | - ix = (ix + 1) % self.symbols.len |
29 | | - print msg + center(self.symbols[ix],8) |
30 | | - end while |
31 | | - end for |
32 | | -end function |
| 9 | +print "You are in the H&M casino,in front of one of our" |
| 10 | +print "one-arm bandits. Bet from $1 to $100." |
| 11 | +print "To pull the arm, punch the return key after making your bet." |
33 | 12 |
|
34 | | -Machine.makeBet = function() |
35 | | - while true |
36 | | - bet = floor(input("Your bet? ").val) |
37 | | - if bet > 100 then |
38 | | - print "House limits are $100" |
39 | | - else if bet < 1 then |
40 | | - print "Minimum bet is $1" |
41 | | - else |
42 | | - break |
43 | | - end if |
44 | | - end while |
45 | | - Machine.bet = bet |
46 | | -end function |
| 13 | +symbols = ["BAR", "BELL", "ORANGE", "LEMON", "PLUM", "CHERRY"] |
47 | 14 |
|
48 | | -Machine.pullHandle = function |
49 | | - if text.row < 3 then |
50 | | - print; print |
51 | | - text.row = text.row + 2 |
| 15 | + |
| 16 | +winTriple = function(symbol, bet) |
| 17 | + if symbol == "BAR" then |
| 18 | + print "***JACKPOT***" |
| 19 | + globals.profit += 101 * bet |
| 20 | + else |
| 21 | + print "**TOP DOLLAR**" |
| 22 | + globals.profit += 11 * bet |
52 | 23 | end if |
53 | | - row = text.row |
54 | | - msg = "" |
55 | | - for i in range(0,2) |
56 | | - self.reelsSpin(5 + 5 * (i==0), msg, row) |
57 | | - wait .1 |
58 | | - symIx = floor(rnd * self.symbols.len) |
59 | | - msg += center(self.symbols[symIx],9) |
60 | | - self.reels[i] = symIx |
61 | | - text.row = row |
62 | | - print msg |
63 | | - end for |
| 24 | + print "You won!" |
64 | 25 | end function |
65 | 26 |
|
66 | | -Machine.winnings = function |
67 | | - bet = Machine.bet |
68 | | - barIdx = self.symbols.indexOf("Bar") |
69 | | - numBars = 0 |
70 | | - multiples = 0 |
71 | | - for i in range(0,2) |
72 | | - numBars += (self.reels[i] == barIdx) |
73 | | - multiples += (self.reels[i] == self.reels[(i + 1) % 3]) |
74 | | - end for |
75 | | - |
76 | | - if numBars == 3 then return {"won": bet * 101, "msg": "***Jackpot***"} |
77 | | - if numBars == 2 then return {"won": bet * 6, "msg": "*Double Bar*"} |
78 | | - if multiples == 3 then return {"won": bet * 11, "msg": "**Top Dollar**"} |
79 | | - if multiples == 1 then return {"won": bet * 3, "msg": "Double!!"} |
80 | | - return {"won": -bet, "msg": "You lost."} |
| 27 | +winDouble = function(symbol, bet) |
| 28 | + if symbol == "BAR" then |
| 29 | + print "*DOUBLE BAR*" |
| 30 | + globals.profit += 6 * bet |
| 31 | + else |
| 32 | + print "Double!" |
| 33 | + globals.profit += 3 * bet |
| 34 | + end if |
| 35 | + print "You won!" |
81 | 36 | end function |
82 | 37 |
|
83 | | -Machine.results = function |
84 | | - result = Machine.winnings |
85 | | - self.money += result.won |
86 | | - print result.msg |
87 | | - if result.won > 0 then |
88 | | - print "You Won!!" |
89 | | - end if |
90 | | - print "Your standings are $" + self.money |
91 | | - return |
92 | | -end function |
| 38 | +lose = function(bet) |
| 39 | + print "You lost." |
| 40 | + globals.profit -= bet |
| 41 | +end function |
93 | 42 |
|
94 | | -Machine.playAgain = function |
95 | | - ans = input("Again? ") + " " |
96 | | - self.playing = (ans[0].lower == "y") |
97 | | - if self.playing then return |
98 | | - print |
99 | | - if self.money < 0 then |
100 | | - print "Pay up! Please leave your money on the terminal." |
101 | | - else if self.money == 0 then |
102 | | - print "Hey, you broke even." |
| 43 | +calcWinLoss = function(spun, bet) |
| 44 | + if spun[0] == spun[1] then |
| 45 | + if spun[0] == spun[2] then |
| 46 | + winTriple spun[0], bet |
| 47 | + else |
| 48 | + winDouble spun[0], bet |
| 49 | + end if |
| 50 | + else if spun[0] == spun[2] then |
| 51 | + winDouble spun[0], bet |
| 52 | + else if spun[1] == spun[2] then |
| 53 | + winDouble spun[1], bet |
103 | 54 | else |
104 | | - print "Collect your winnings from the H&M cashier." |
| 55 | + lose bet |
105 | 56 | end if |
106 | 57 | end function |
107 | 58 |
|
108 | | -clear |
109 | | -print " " * 30 + "Slots" |
110 | | -print " " * 15 + "Creative Computing Morristown, New Jersey" |
111 | | -print;print;print |
112 | | -print "You are in the H&M Casino, in front of one of our" |
113 | | -print "one-arm bandits. Bet from $1 to $100." |
114 | | -print "to pull the arm, punch the return key after making your bet." |
| 59 | +ringBells = function(qty=5) |
| 60 | + // I believe all the obnoxious beeping was to slow down the game |
| 61 | + // and build suspense as each "wheel" appears. Our version: |
| 62 | + wait 0.1 |
| 63 | + for i in range(1, qty) |
| 64 | + print char(7), "" |
| 65 | + wait 0.05 |
| 66 | + end for |
| 67 | +end function |
115 | 68 |
|
116 | | -print |
117 | | -while Machine.playing |
118 | | - Machine.makeBet |
| 69 | +// Main program |
| 70 | +profit = 0 |
| 71 | +while true |
119 | 72 | print |
120 | | - Machine.pullHandle |
| 73 | + |
| 74 | + // Get bet |
| 75 | + while true |
| 76 | + bet = input("Your bet? ").val |
| 77 | + if 1 <= bet <= 100 then break |
| 78 | + if bet < 1 then print "Minimum bet is $1" else print "House limits are $100" |
| 79 | + end while |
| 80 | + |
| 81 | + // Spin 3 wheels (randomly picking a symbol for each one) |
| 82 | + spun = [] |
| 83 | + spun.push symbols[rnd * symbols.len] |
| 84 | + spun.push symbols[rnd * symbols.len] |
| 85 | + spun.push symbols[rnd * symbols.len] |
121 | 86 | print |
122 | | - Machine.results |
123 | | - Machine.playAgain |
| 87 | + ringBells 10; print spun[0], " " |
| 88 | + ringBells 5; print spun[1], " " |
| 89 | + ringBells 5; print spun[2] |
124 | 90 | print |
| 91 | + |
| 92 | + // Calculate and display win/loss |
| 93 | + wait 0.5 |
| 94 | + calcWinLoss spun, bet |
| 95 | + |
| 96 | + // Show new state, and maybe play again |
| 97 | + print "Your standings are $ " + profit |
| 98 | + yn = input("Again? ").lower + " " |
| 99 | + if yn[0] != "y" then break |
125 | 100 | end while |
| 101 | + |
| 102 | +if profit == 0 then |
| 103 | + print "Hey, you broke even." |
| 104 | +else if profit > 0 then |
| 105 | + print "Collect your winnings from the H&M cashier." |
| 106 | +else |
| 107 | + print "Pay up! Please leave your money on the terminal." |
| 108 | +end if |
0 commit comments