Skip to content

Instantly share code, notes, and snippets.

@Pyrocrisis
Created January 6, 2018 23:20
Show Gist options
  • Save Pyrocrisis/8438ea82deb0dcba36e4ccaa75a35d0a to your computer and use it in GitHub Desktop.
Save Pyrocrisis/8438ea82deb0dcba36e4ccaa75a35d0a to your computer and use it in GitHub Desktop.
import random, time, sys
class fruit():
#Creating variables at start of game
def __init__(self):
self.credit = 1.0
self.results = ["Cherry","Bell","Lemon","Orange","Star","Skull"]
self.play = True
self.choice = ""
self.lost = False
#Clears spin array and fills it with three randomly selected options from the results array, also reduces credit value
def roll(self):
self.spin = []
self.credit -= 0.2
self.credit = round(self.credit, 2)
waste = input("Press ENTER to spin")
for i in range(3):
self.spin.append(random.choice(self.results))
print(self.spin)
print("")
self.spin.sort()
self.again()
#Checks the results of spins and updates the players credit
def check(self):
if all(x == spin[0] for x in spin):
if spin[0] == "Bell":
print("You won £5 credit!")
self.credit += 5.0
elif spin[0] == "Skull":
player.lost = True
else:
print("You won £1 credit!")
self.credit += 1.0
elif ((spin[0] == spin[1]) or (spin[1] == spin[2])) and spin[1] != "Skull":
print("You won £0.5 credit!")
self.credit += 0.5
elif ((spin[0] == spin[1]) or (spin[1] == spin[2])) and spin[1] == "Skull":
print("You lose £1 credit!")
self.credit -= 1.0
else:
pass
#Checks if user wants to play again
def again(self):
if self.lost == False:
print("Credit: £" + str(self.credit))
self.choice = input("Do you want to play again? (yes/no) ").lower()
print("")
if self.choice == "no":
self.play = False
print("Thank you for playing!")
print("Your final credit was a total of: £" + str(self.credit) + "\n")
elif self.choice == "yes":
self.play = True
else:
print("Invalid input please try again.")
self.again()
else:
self.choice = input("You lost! Do you want to start again? (yes/no) ").lower()
print("")
if self.choice == "yes":
print("<--- New Game --->\n")
fruit.script()
else:
print("Thank you for playing!")
sys.exit()
#Method to make the game run
def script():
player = fruit()
print("Welcome to fruit machine!\n")
while player.play == True:
if player.credit >= 0.2:
player.roll()
else:
player.lost = True
print("You are out of credit!\n")
player.again()
fruit.script()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment