Added machine spinning
This commit is contained in:
@@ -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)
|
||||
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()
|
||||
@@ -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__":
|
||||
|
||||
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