개발/Python

Python PyQt5 를 이용 하여 카지노 룰렛 시뮬레이터 만들기

핫펍co 2019. 11. 11. 20:40

사용 방법입니다. 룰렛을 해보셨다면 쉽게 이해 하실 거에요.

제가 카지노 가서 자주 배팅하는 방법을 python 으로 구현 해 보았습니다.

카지노 룰렛 python 구현

 

아래 소스를 복사 해서

casino.py 파일을 만들고 cmd 창에서 python casino.py 실행 하여 해보세요.

실행 파일을 만들고 싶으시면 pyinstaller 를 사용 하시면 됩니다.

pyinstaller -w -F casino.py

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QLineEdit, QMessageBox
from random import randint

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setupUI()

    def setupUI(self):
        self.setWindowTitle("Roulette")

		# 나온 숫자 label
        self.number = QLabel(self)
        self.number.setText('0')
        self.number.move(30, 15)

		# 보유 금액 label
        self.tmoney = QLabel(self)
        self.tmoney.setText('1000')
        self.tmoney.move(30, 40)
        
        # 배팅 구역 edit
        self.bet = QLineEdit(self)
        self.bet.resize(30, 20)
        self.bet.move(70, 45)

		# 배팅 금액 edit
        self.mn = QLineEdit(self)
        self.mn.setText('100')
        self.mn.resize(30, 20)
        self.mn.move(70, 20)

		# 게임 시작 버튼
        btn1 = QPushButton("Start", self)
        btn1.resize(50,20)
        btn1.move(55,70)
        btn1.clicked.connect(self.btn1_clicked)        

		# 초기화 버튼
        btn2 = QPushButton("Init", self)
        btn2.resize(30,20)
        btn2.move(20,70)
        btn2.clicked.connect(self.btn2_clicked) 

    def btn1_clicked(self):
        a = randint(0,36)
        b = self.mn.text()
        c = self.bet.text()
        t = self.tmoney.text()

        if not b:
            self.number.setText(str(a))
            pass
        elif int(t) - (int(b) * 2) < 0:
            QMessageBox.about(self, "error", "no money")
            pass
        elif not a:
            tm = int(t) - (int(b) * 2)
            self.tmoney.setText(str(tm))
            self.number.setText(str(a))
        else:
            if a > 0 and 13 > a and int(c) == 1:
                tm = int(t) - (int(b) * 2)
                self.tmoney.setText(str(tm))
                self.number.setText(str(a))
            elif a > 12 and 25 > a and int(c) == 2:
                tm = int(t) - (int(b) * 2)
                self.tmoney.setText(str(tm))
                self.number.setText(str(a))
            elif a > 24 and int(c) == 3:
                tm = int(t) - (int(b) * 2)
                self.tmoney.setText(str(tm))
                self.number.setText(str(a))
            else:
                tm = int(t) + int(b)
                self.tmoney.setText(str(tm))
                self.number.setText(str(a))

    def btn2_clicked(self):
        self.tmoney.setText('1000')

if __name__ == "__main__":
    app = QApplication(sys.argv)
    mywindow = MyWindow()
    mywindow.show()
    app.exec_()