diff --git a/src/py/slots/Slots.py b/src/py/slots/Slots.py index c4279e8..c71df0a 100644 --- a/src/py/slots/Slots.py +++ b/src/py/slots/Slots.py @@ -1,9 +1,34 @@ from Wheel import Wheel +from random import random class SlotMachine(): def __init__(self, screen_w=3, screen_h=3): jackpot = 0 - wheels=[] + self.wheels=[] for i in range(screen_w): wheel = Wheel(size=screen_h) - wheels.append(wheel) \ No newline at end of file + self.wheels.append(wheel) + + def spin(self, wSpins=3, randomness=0.5): + for _ in range(wSpins): + for wheel in self.wheels: + if random() >= randomness: + wheel.spin() + + + def __str__(self): + string = "" + for wheel in self.wheels: + string += str(wheel) + "\n" + return string + + +def main(): + # machine = SlotMachine() + # print(machine) + # machine.spin(randomness=1) + # print(machine) + pass + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/py/slots/Wheel.py b/src/py/slots/Wheel.py index d34fdf0..d2c9772 100644 --- a/src/py/slots/Wheel.py +++ b/src/py/slots/Wheel.py @@ -1,21 +1,32 @@ +""" +Wheel Class for implementing a wheel that spins in a poker machine +""" class Wheel(): def __init__(self, size=3): self.size=size self.icons = list(range(size)) - def roll(self, offset=1): + 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 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(size=10) - print(wheel.icons) - wheel.roll(offset=3) - print(wheel.icons) + # wheel = Wheel() + # print(wheel) + pass if __name__ == "__main__": diff --git a/src/py/slots/__pycache__/Wheel.cpython-313.pyc b/src/py/slots/__pycache__/Wheel.cpython-313.pyc new file mode 100644 index 0000000..532b4f4 Binary files /dev/null and b/src/py/slots/__pycache__/Wheel.cpython-313.pyc differ