-
Notifications
You must be signed in to change notification settings - Fork 0
/
Casino.py
131 lines (101 loc) · 4.61 KB
/
Casino.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import random
import sys
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QPalette, QBrush, QImage, QFont, QIntValidator
from PyQt5.QtWidgets import QMainWindow, QPushButton, QLabel, QLineEdit, QApplication
class PyQtLayout(QMainWindow):
def __init__(self):
self.credit = 10000
self.random_value = 0
super().__init__()
self.red_buttons = list()
self.black_buttons = list()
self.InitializeUI()
def InitializeUI(self):
window_size = QSize(1100, 600)
palette = QPalette()
self.setFixedSize(window_size)
self.setWindowTitle('Casino')
palette.setBrush(QPalette.Window, QBrush(QImage('background.jpg').scaled(window_size)))
self.setPalette(palette)
self.displayGUI()
self.show()
def displayGUI(self):
self.displayUser()
self.displayCasino()
def displayCasino(self):
counter = 1
button_size = 40
self.button_list = list()
range_buttons = list()
self.button_list.append(QPushButton('0', self)) # 0 button
self.button_list[0].setFixedSize(button_size, 3 * button_size)
self.button_list[0].setStyleSheet("background-color : green")
self.button_list[0].move(button_size, button_size)
self.button_list[0].clicked.connect(self.rouletteStart)
for i in range(0, 12):
for j in range(0, 3):
self.button_list.append(QPushButton(str(counter), self))
self.button_list[counter].move(button_size * 2 + button_size * i, button_size + button_size * j)
self.button_list[counter].setFixedSize(button_size, button_size)
self.button_list[counter].clicked.connect(self.rouletteStart)
counter += 1
self.rouletteColor(1, 10, 1)
self.rouletteColor(11, 18, 0)
self.rouletteColor(19, 28, 1)
self.rouletteColor(29, 36, 0)
self.rbutton_names = list(['1 to 18', 'Even', 'Red', 'Black', 'Odd', '19 to 36'])
for i in range(0, 6):
range_buttons.append(QPushButton(self.rbutton_names[i], self))
range_buttons[i].setFixedSize(button_size * 2, button_size)
range_buttons[i].move(button_size * 2 + button_size * i * 2, button_size * 4)
range_buttons[i].setStyleSheet("background-color: transparent; border: 2px solid")
range_buttons[i].clicked.connect(self.rouletteStart)
def displayUser(self):
self.credit_counter = QLabel('Credits: ' + str(self.credit) + '\nBet:', self)
self.credit_counter.setFixedSize(1000, 65)
self.credit_counter.move(40, 400)
self.credit_counter.setStyleSheet("color: white")
self.credit_counter.setFont(QFont('Arial', 20))
self.bet_input = QLineEdit(self)
self.bet_input.setValidator(QIntValidator())
self.bet_input.resize(100, 22)
self.bet_input.move(130, 440)
self.roulette_number = QLabel(str(self.random_value), self)
self.roulette_number.setFont(QFont('Arial', 50))
self.roulette_number.move(700, 40)
self.roulette_number.setFixedSize(200, 60)
def rouletteColor(self, start, end, shift):
for i in range(start, end + 1):
if (i + shift) % 2 == 0:
self.button_list[i].setStyleSheet("background-color : red")
self.red_buttons.append(i)
else:
self.button_list[i].setStyleSheet("background-color: #333333; color: white;")
self.black_buttons.append(i)
def rouletteStart(self):
button = self.sender()
button_name = button.text()
bet = self.bet_input.text()
rbutton_func = list([set(range(1, 19)), set(range(2, 37, 2)), set(self.red_buttons), set(self.black_buttons),
set(range(1, 37, 2)), set(range(19, 37))])
if button_name in self.rbutton_names:
num = rbutton_func[self.rbutton_names.index(button_name)]
win = int(bet)
else:
num = set([int(button_name)])
win = 5 * int(bet)
if not self.bet_input.text().isdigit() or int(bet) <= 0 or self.credit < int(bet):
self.roulette_number.setText('Error')
return
self.random_value = random.randint(0, 36)
bet = int(bet)
if self.random_value in num:
self.credit += win
else:
self.credit -= bet
self.credit_counter.setText('Credits: ' + str(self.credit) + '\nBet:')
self.roulette_number.setText(str(self.random_value) + str())
app = QApplication(sys.argv)
win = PyQtLayout()
sys.exit(app.exec_())