-
Notifications
You must be signed in to change notification settings - Fork 0
/
slotmachine.py
68 lines (57 loc) · 3.49 KB
/
slotmachine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pygame
import random
from pygclasses import Images, Fonts
class SlotMachine:
def __init__(self, width, height, title):
self.screen_size = (width, height)
self.game_title = title
pygame.mixer.set_num_channels(2)
#self.win = pygame.mixer.Sound("sounds/win.wav")
self.spin_snd = pygame.mixer.Sound("sounds/spin_snd.ogg")
self.spinning_snd = pygame.mixer.Sound("sounds/spinning_snd.ogg")
self.screen = pygame.display.set_mode(self.screen_size) # you can set FULLSCREEN, as second paremeter
# Start and background logo via 25 & demas
self.startimage = Images("images/logo.png", [width/2, height/2])
self.demas_logo = Images("./images/demas_logo.png", [width / 2, height / 2])
self.eric_font = Fonts("./fonts/font.ttf", "HOLA ERIC : )", 70, (0, 0, 0), (width / 2, height / 2))
# Confetti image
self.confeti_image = Images("./images/confeti2.png",[width / 2, height / 2])
#Load and resize background
self.background = Images("images/logo.png", [1000, 525], (200, 200))
# List of images for the slots
self.ice_cream_list = []
self.ice_cream_list.append(Images("images/img.png", [(width/2)+350, height/2], (100, 100)))
self.ice_cream_list.append(Images("images/img1.png", [(width/2)+350, height/2], (100, 100)))
self.ice_cream_list.append(Images("images/img2.png", [(width / 2) + 350, height / 2], (100, 100)))
self.ice_cream_list.append(Images("images/img3.png", [(width / 2) + 350, height / 2], (100, 100)))
self.ice_cream_list.append(Images("images/img4.png", [(width / 2) + 350, height / 2], (100, 100)))
self.ice_cream_list.append(Images("images/img5.png", [(width / 2) + 350, height / 2], (100, 100)))
#Machine image
self.machine = Images("images/machine.png", ((width/2), height/2), (width, height))
# Fonts
self.play_font = Fonts("./fonts/font.ttf", "JUGAR", 200, (0, 0, 0), (width/2, height/2))
self.enter_font = Fonts("./fonts/font.ttf", "Presiona ENTER", 70, (0, 0, 0), (width / 2, height // 1.5))
self.one_font = Fonts("./fonts/font.ttf", "Mas suerte la próxima :(", 70, (0, 0, 0), (width / 2, height / 2))
self.two_font = Fonts("./fonts/font.ttf", "Acertaste dos. faltó poco.", 70, (0, 0, 0), (width / 2, height / 2))
self.three_font = Fonts("./fonts/font.ttf", "GANASTE! Felicitaciones", 70, (0, 0, 0), (width / 2, height / 2))
# Results of spinning
self.results = [None, None, None]
def get_spin(self, difficult=5):
""" This method is used to choice the result of the spins """
for i in range(3):
# This allow us set the difficult of the game.
# For example, if "difficult = 1" you always win.
# Becouse the result will always be self.images[0]
spinned_result = random.randint(0, difficult)
if spinned_result in range(0):
self.results[i] = self.ice_cream_list[0]
elif spinned_result in range(1, 2):
self.results[i] = self.ice_cream_list[1]
elif spinned_result in range(2, 3):
self.results[i] = self.ice_cream_list[2]
elif spinned_result in range(3, 4):
self.results[i] = self.ice_cream_list[3]
elif spinned_result in range(4, 5):
self.results[i] = self.ice_cream_list[4]
elif spinned_result in range(5, 6):
self.results[i] = self.ice_cream_list[5]