Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 180446d121 | |||
| 9113d4b8c1 |
@@ -1,63 +0,0 @@
|
|||||||
from Wheel import Wheel
|
|
||||||
from random import random
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
class SlotMachine():
|
|
||||||
def __init__(self, screen_w=3, screen_h=3):
|
|
||||||
jackpot = 0
|
|
||||||
self.wheels=[]
|
|
||||||
for i in range(screen_w):
|
|
||||||
wheel = Wheel(size=screen_h)
|
|
||||||
self.wheels.append(wheel)
|
|
||||||
|
|
||||||
def spin(self, wSpins=1):
|
|
||||||
for _ in range(wSpins):
|
|
||||||
for wheel in self.wheels:
|
|
||||||
wheel.spin()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
string = ""
|
|
||||||
# Create an empty matrix with the sole purpose of transposing it
|
|
||||||
matrix = [[],[],[]]
|
|
||||||
|
|
||||||
for i, wheel in enumerate(self.wheels):
|
|
||||||
for icon in wheel.icons:
|
|
||||||
matrix[i].append(icon)
|
|
||||||
|
|
||||||
# Use Zip function to transpose unpacked matrix (*matrix unpacks it)
|
|
||||||
matrix = zip(*matrix)
|
|
||||||
|
|
||||||
for row in matrix:
|
|
||||||
for icon in row:
|
|
||||||
string += str(icon) + " "
|
|
||||||
string += "\n"
|
|
||||||
|
|
||||||
return string
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
machine = SlotMachine()
|
|
||||||
win = False
|
|
||||||
result = []
|
|
||||||
machine.spin(wSpins=3)
|
|
||||||
while win == False:
|
|
||||||
machine.spin()
|
|
||||||
result = machine.wheels
|
|
||||||
first_icon = result[0].icons[1]
|
|
||||||
|
|
||||||
if all(wheel.icons[1] == first_icon for wheel in result):
|
|
||||||
|
|
||||||
win = True
|
|
||||||
|
|
||||||
print(machine)
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
print("Woohoo!")
|
|
||||||
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import random as rand
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Wheel Class for implementing a wheel that spins in a poker machine
|
|
||||||
"""
|
|
||||||
class Wheel():
|
|
||||||
def __init__(self, size=3, num_icons = 3):
|
|
||||||
self.size=size
|
|
||||||
self.icons = list(range(size))
|
|
||||||
self.num_icons = num_icons
|
|
||||||
|
|
||||||
def spin(self, offset=1):
|
|
||||||
new_icons = list(range(self.size))
|
|
||||||
# Loop through each icon and move it one space up
|
|
||||||
# Uses modulus to loop final icon to first position
|
|
||||||
for i, icon in enumerate(self.icons):
|
|
||||||
new_icons[(i + offset) % len(new_icons)] = icon
|
|
||||||
|
|
||||||
# Randomise the first element
|
|
||||||
new_icons[0] = rand.randint(0, self.num_icons - 1)
|
|
||||||
|
|
||||||
self.icons = new_icons
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
string = ""
|
|
||||||
for icon in self.icons:
|
|
||||||
# Print wheel out with spaces between items
|
|
||||||
string += str(icon) + " "
|
|
||||||
return string
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# wheel = Wheel()
|
|
||||||
# print(wheel)
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user