slots

commit bf183af69ca89632ddcac471861aa2ce7e0aa27e

tree

parents:
0ef89d84ef1393b248b67a4265902246dd28b8e7
c9b7def1b6e61bb5186dff55edb1022da82e0115

Nick Mykins <nick@nick-mykins.local>

2012-09-27T12:55:14-04:00

Merge branch 'master' of https://github.com/nmyk/slots

diff --git a/.reels.py.swp b/.reels.py.swp
new file mode 100644
index 0000000000000000000000000000000000000000..93eaddd1ce648ea2edc61f178634ed867def174c
Binary files /dev/null and b/.reels.py.swp differ
diff --git a/cli.py b/cli.py
new file mode 100755
index 0000000000000000000000000000000000000000..2724fba5e3232a16914c8828aa6cd4674fc37c65
--- /dev/null
+++ b/cli.py
@@ -0,0 +1,53 @@
+import sys
+import os
+import machine
+
+def CLI(slotMachine):
+	playerInput = raw_input('Command: ')
+	parsedCommands = playerInput.split()
+	if len(parsedCommands) > 0:
+		if parsedCommands[0] == 'bet':
+			if len(parsedCommands) ==2:
+				slotMachine.changeBet(int(parsedCommands[1]))
+			else:
+				print 'The current bet is $' + str(slotMachine.bet) + '.'
+		elif parsedCommands[0] == 'balance':
+			slotMachine.printBalance()
+		elif parsedCommands[0] == 'add':
+			slotMachine.addMoney(int(parsedCommands[1]))
+		elif parsedCommands[0] == 'quit':
+			sys.exit(0)
+		elif parsedCommands[0] == 'help':
+			os.system('clear')
+			printHelp()
+		else:
+			os.system('clear')
+			print 'Invalid command. Type "help" for options.'
+	else:
+		slotMachine.gamble()
+
+def printHelp():
+	print 'Commands:\n bet (#)\n balance\n help\n quit\n Press enter without issuing a command to pull the crank!'
+	print """
+	Combination                        Payout multiplier 
+	----------------------------------------------------
+	PINEAPPLE PINEAPPLE PINEAPPLE            500
+	WATERMELON WATERMELON WATERMELON         250
+	ORANGE ORANGE ORANGE                      80
+	WATERMELON WATERMELON *any*               35
+	ORANGE WATERMELON *any*                   15
+	CHERRY CHERRY CHERRY                      10
+	LEMON LEMON LEMON                          8 
+	CHERRY CHERRY *any*                        5
+	LEMON LEMON *any*                          2     
+
+"""
+
+def gameIntro():
+	print """
+    	
+	
+                  SLOTS! v1.0
+            developed by Nick Mykins	
+
+"""
diff --git a/machine.py b/machine.py
new file mode 100755
index 0000000000000000000000000000000000000000..9162c28bd7786cb4a8ead104393169ee4bff3ad4
--- /dev/null
+++ b/machine.py
@@ -0,0 +1,47 @@
+import sys
+import os
+import random
+import reels 
+
+class Machine:
+	def __init__(self,bal,coin):
+		self.balance = bal
+		self.bet = coin
+	def printBalance(self):
+		if self.balance > 0:
+			print 'You have $' + str(self.balance) + ". Don't spend it all in one place."
+	def addMoney(self, amt):
+		self.balance += amt
+	def changeBet(self, bet):
+		if bet <= self.balance:
+			self.bet = bet
+			print 'Bet changed to $' + str(bet) + "."
+		else:
+			print "You can't bet more money than is in the machine!"
+	def gamble(self):
+		if self.balance <= 0:
+			self.isBroke()
+		else:
+			reelA = int(random.random()*100)
+			reelB = int(random.random()*100)
+			reelC = int(random.random()*100)
+		
+			win = reels.spin(reelA, reelB, reelC)
+		
+			self.balance += self.bet * (win - 1)
+			if win > 0:
+				print "Woo! Woo! You won $" + str(win*self.bet) + "!\n"
+				self.printBalance()
+			else:
+				print "Meh. Try again!\n"
+				self.printBalance()
+		if self.bet > self.balance > 0:
+			print "Your wager now exceeds your balance. "
+			self.changeBet(self.balance)
+	def isBroke(self):
+		print 'You have no more money! Get outta here!'
+		sys.exit(0)
+		
+
+		
+
diff --git a/reels.py b/reels.py
new file mode 100755
index 0000000000000000000000000000000000000000..960c5588db3fe371f35a88547345aa5c359d65ee
--- /dev/null
+++ b/reels.py
@@ -0,0 +1,61 @@
+import time
+
+# By changing the "pictures" on the reel, you can make the slot machine whatever theme you want. For example, reel = ['CHAT','CHIEN','ARBRE','MAISON','VILLE','MERDE'] has a French theme.
+
+reel = ['LEMON','CHERRY','ORANGE','WATERMELON','PINEAPPLE','GARBAGE']
+
+def spin(A,B,C):
+	reelPics = ['','','']
+	reelList = [A,B,C]
+	payout = 0
+
+# The probabilities of getting the six pictures are 30%, 25%, 15%, 10%, 5%, and 15%, respectively.
+	for i in range(0,3):
+		if reelList[i] < 5:
+			reelPics[i] = reel[4]
+		elif 5 <= reelList[i] < 15:
+			reelPics[i] = reel[3]
+		elif 15 <= reelList[i] < 30:
+			reelPics[i] = reel[2]
+		elif 30 <= reelList[i] < 55:
+			reelPics[i] = reel[1]
+		elif 55 <= reelList[i] < 85:
+			reelPics[i] = reel[0]
+		elif reelList[i] > 85:
+			reelPics[i] = reel[5]
+    # Pause in between pictures for suspense!
+	print 20*' ' + reelPics[0]
+	time.sleep(.4)
+	print 20*' ' + reelPics[1]
+	time.sleep(.4)
+	print 20*' ' + reelPics[2] + '\n'
+	time.sleep(.2)
+	
+	# Various payout schemes. Edit these to your heart's content.
+	if reelPics == [reel[4],reel[4],reel[4]]:
+		payout = 500
+	elif reelPics == [reel[3],reel[3],reel[3]]:
+		payout = 250
+	elif reelPics == [reel[2],reel[2],reel[2]]:
+		payout = 80
+	elif reelPics[0] == reelPics[1] == reel[3] and reelPics[2] != reel[3]:
+		payout = 35
+	elif reelPics[0] == reel[2] and reelPics[1] == reel[3]:
+		payout = 15
+	elif reelPics == [reel[1],reel[1],reel[1]]:
+		payout = 10
+	elif reelPics == [reel[0],reel[0],reel[0]]:
+		payout = 8
+#	elif reelPics[0] == reel[4] and reelPics[2] != reel[4]:
+#		payout = 20
+	elif reelPics[0] == reelPics[1] == reel[1] and reelPics[2] != reel[1]:
+		payout = 5
+#	elif reelPics[0] == reel[3] and reelPics[2] != reel[3]:
+#		payout = 10
+#	elif reelPics[0] == reel[2] and reelPics[2] != reel[2]:
+#		payout = 5
+#	elif reelPics[0] == reel[1] and reelPics[1] != reel[1] and reelPics[2] != reel[1]:
+#		payout = 1
+	elif reelPics[0] == reelPics[1] == reel[0] and reelPics[2] != reel[0]:
+		payout = 2
+	return payout
diff --git a/slots.py b/slots.py
new file mode 100755
index 0000000000000000000000000000000000000000..389fce9c5d548b4cc7e674b1818f46ff219fcab7
--- /dev/null
+++ b/slots.py
@@ -0,0 +1,20 @@
+import cli
+import reels
+import machine
+import os
+
+def main():
+	os.system('clear')
+	slotMachine = machine.Machine(50,1)
+	cli.gameIntro()
+	cli.printHelp()
+	slotMachine.printBalance()
+	while True:
+		if slotMachine.balance > 0:
+			cli.CLI(slotMachine)
+		else:
+			slotMachine.isBroke()
+
+if __name__ == '__main__':
+	main()
+