Compare commits
7 Commits
180446d121
...
Pokies
| Author | SHA1 | Date | |
|---|---|---|---|
| 41f5f8e2b8 | |||
| e544b505f5 | |||
| 4122817fae | |||
| c6ee83e51a | |||
| 13eb629a16 | |||
| 543b57603e | |||
| a5d86f822c |
63
src/py/slots/Slots.py
Normal file
63
src/py/slots/Slots.py
Normal file
@@ -0,0 +1,63 @@
|
||||
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()
|
||||
40
src/py/slots/Wheel.py
Normal file
40
src/py/slots/Wheel.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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()
|
||||
BIN
src/py/slots/__pycache__/Wheel.cpython-313.pyc
Normal file
BIN
src/py/slots/__pycache__/Wheel.cpython-313.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user