slots

commit 5712149e97621bca4abcb0f4720e70c7df9ed1e5

tree

parent:
d099036b7862244f8eeb15e60933938024d5285b

Nick Mykins <nick.mykins@gmail.com>

2014-10-19T12:59:33-04:00

make things look nicer

diff --git a/cli.py b/cli.py
index 2724fba5e3232a16914c8828aa6cd4674fc37c65..11e71ad2e67cf60572b8cbfa2813d262b25b1e1b 100755
--- a/cli.py
+++ b/cli.py
@@ -2,52 +2,52 @@ 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 CLI(slot_machine):
+    player_input = raw_input('Command: ')
+    parsed_commands = player_input.split()
+    if len(parsed_commands) > 0:
+        if parsed_commands[0] == 'bet':
+            if len(parsed_commands) ==2:
+                slot_machine.change_bet(int(parsed_commands[1]))
+            else:
+                print 'The current bet is $' + str(slot_machine.bet) + '.'
+        elif parsed_commands[0] == 'balance':
+            slot_machine.print_balance()
+        elif parsed_commands[0] == 'add':
+            slot_machine.add_money(int(parsed_commands[1]))
+        elif parsed_commands[0] == 'quit':
+            sys.exit(0)
+        elif parsed_commands[0] == 'help':
+            os.system('clear')
+            print_help()
+        else:
+            os.system('clear')
+            print 'Invalid command. Type "help" for options.'
+    else:
+        slot_machine.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 print_help():
+    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 """
-    	
-	
+def game_intro():
+    print """
+        
+    
                   SLOTS! v1.0
-            developed by Nick Mykins	
+            developed by Nick Mykins    
 
 """
diff --git a/machine.py b/machine.py
index 6388d79be3c5dc3a6bacce991d3f0e214dc1a18d..17079207e8e77f0f9555cbcc4c69865a62c0a66a 100755
--- a/machine.py
+++ b/machine.py
@@ -3,37 +3,42 @@ import os
 import reels 
 
 class Machine:
+
 	def __init__(self,bal,coin):
 		self.balance = bal
 		self.bet = coin
-	def printBalance(self):
+
+	def print_balance(self):
 		if self.balance > 0:
 			print 'You have $' + str(self.balance) + ". Don't spend it all in one place."
-	def addMoney(self, amt):
+
+	def add_money(self, amt):
 		self.balance += amt
-	def changeBet(self, bet):
+
+	def change_bet(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()
+			self.is_broke()
 		else:
 			win = reels.spin()
-		
 			self.balance += self.bet * (win - 1)
 			if win > 0:
 				print "Woo! Woo! You won $" + str(win*self.bet) + "!\n"
-				self.printBalance()
+				self.print_balance()
 			else:
 				print "Meh. Try again!\n"
-				self.printBalance()
+				self.print_balance()
 		if self.bet > self.balance > 0:
 			print "Your wager now exceeds your balance. "
-			self.changeBet(self.balance)
-	def isBroke(self):
+			self.change_bet(self.balance)
+			
+	def is_broke(self):
 		print 'You have no more money! Get outta here!'
 		sys.exit(0)
 		
diff --git a/reel.yaml b/reel.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..81fad71988cc5fa9865f62567c71855978033792
--- /dev/null
+++ b/reel.yaml
@@ -0,0 +1,8 @@
+---
+- LEMON
+- CHERRY
+- ORANGE
+- WATERMELON
+- PINEAPPLE
+- GARBAGE
+...
\ No newline at end of file
diff --git a/reels.py b/reels.py
index a5cc69cb75345a7ac0533a67e4d7351ba3e46714..e1cf61eb186b89f7890d1a170f5ab8f83ee00961 100755
--- a/reels.py
+++ b/reels.py
@@ -1,15 +1,15 @@
 import time
 from random import randint
+import yaml
 
-# 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']
+with file('reel.yaml', 'r') as reel_file:
+    reel = yaml.load(reel_file)['']
+print reel
 
 def spin():
     n = 3
     payout = 0
 
-# The probabilities of getting the six pictures are 30%, 25%, 15%, 10%, 5%, and 15%, respectively.
     def convert(m):
         if        m <=  5: return reel[4]
         elif  5 < m <= 15: return reel[3]
@@ -18,32 +18,32 @@         elif 30 < m <= 55: return reel[1]
         elif 55 < m <= 85: return reel[0]
         elif 85 < m      : return reel[5]
 
-    reelPics = [convert(randint(1,100)) for i in xrange(n)]
+    reel_pics = [convert(randint(1,100)) for i in xrange(n)]
     # Pause in between pictures for suspense!
-    print 20*' ' + reelPics[0]
+    print 20*' ' + reel_pics[0]
     time.sleep(.4)
-    print 20*' ' + reelPics[1]
+    print 20*' ' + reel_pics[1]
     time.sleep(.4)
-    print 20*' ' + reelPics[2] + '\n'
+    print 20*' ' + reel_pics[2] + '\n'
     time.sleep(.2)
-	
     # Various payout schemes. Edit these to your heart's content.
-    if reelPics == [reel[4],reel[4],reel[4]]:
+    # TODO: big refactor
+    if reel_pics == [reel[4],reel[4],reel[4]]:
         payout = 500
-    elif reelPics == [reel[3],reel[3],reel[3]]:
+    elif reel_pics == [reel[3],reel[3],reel[3]]:
         payout = 250
-    elif reelPics == [reel[2],reel[2],reel[2]]:
+    elif reel_pics == [reel[2],reel[2],reel[2]]:
         payout = 80
-    elif reelPics[0] == reelPics[1] == reel[3] and reelPics[2] != reel[3]:
+    elif reel_pics[0] == reel_pics[1] == reel[3] and reel_pics[2] != reel[3]:
         payout = 35
-    elif reelPics[0] == reel[2] and reelPics[1] == reel[3]:
+    elif reel_pics[0] == reel[2] and reel_pics[1] == reel[3]:
         payout = 15
-    elif reelPics == [reel[1],reel[1],reel[1]]:
+    elif reel_pics == [reel[1],reel[1],reel[1]]:
         payout = 10
-    elif reelPics == [reel[0],reel[0],reel[0]]:
+    elif reel_pics == [reel[0],reel[0],reel[0]]:
         payout = 8
-    elif reelPics[0] == reelPics[1] == reel[1] and reelPics[2] != reel[1]:
+    elif reel_pics[0] == reel_pics[1] == reel[1] and reel_pics[2] != reel[1]:
         payout = 5
-    elif reelPics[0] == reelPics[1] == reel[0] and reelPics[2] != reel[0]:
+    elif reel_pics[0] == reel_pics[1] == reel[0] and reel_pics[2] != reel[0]:
         payout = 2
     return payout
diff --git a/slots.py b/slots.py
index 389fce9c5d548b4cc7e674b1818f46ff219fcab7..2cb773ea2bc275e0b6547357ee3d4eb99470c01a 100755
--- a/slots.py
+++ b/slots.py
@@ -3,17 +3,19 @@ import reels
 import machine
 import os
 
+
 def main():
 	os.system('clear')
-	slotMachine = machine.Machine(50,1)
-	cli.gameIntro()
-	cli.printHelp()
-	slotMachine.printBalance()
+	slot_machine = machine.Machine(50,1)
+	cli.game_intro()
+	cli.print_help()
+	slot_machine.print_balance()
 	while True:
-		if slotMachine.balance > 0:
-			cli.CLI(slotMachine)
+		if slot_machine.balance > 0:
+			cli.CLI(slot_machine)
 		else:
-			slotMachine.isBroke()
+			slot_machine.is_broke()
+
 
 if __name__ == '__main__':
 	main()