aboutMe.py (view raw)
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 132 |
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QTextBrowser, QVBoxLayout
import sys
from PyQt6.QtGui import QIcon
import random
from pyperclip import copy
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Minesweeper About Me")
self.setWindowIcon(QIcon("banan.jpg"))
self.setGeometry(500,300,400,300)
stylesheet = (
'background-color:rgb(29, 29, 38); color:rgb(179, 179, 212)'
)
self.setStyleSheet(stylesheet)
self.create()
def create(self):
self.tb = QTextBrowser(self)
self.btn = QPushButton('generate new field', self)
self.btn.clicked.connect(self.generate)
vbox = QVBoxLayout(self)
vbox.addWidget(self.tb)
vbox.addWidget(self.btn)
self.setLayout(vbox)
self.show()
self.generate()
def generate(self):
field = [[],[],[],[]]
for i in range(0, 4):
for j in range(0, 4):
if random.randint(0,100) < 26:
field[i].append(-1)
else:
field[i].append(0)
for i in range(0, 4):
for j in range(0, 4):
if field[i][j] != -1:
if j != 3:
if field[i][j+1] == -1:
field[i][j] = field[i][j] + 1
if j != 0:
if field[i][j-1] == -1:
field[i][j] = field[i][j] + 1
if i != 0:
if field[i-1][j] == -1:
field[i][j] = field[i][j] + 1
if j != 0:
if field[i-1][j-1] == -1:
field[i][j] = field[i][j] + 1
if j != 3:
if field[i-1][j+1] == -1:
field[i][j] = field[i][j] + 1
if i != 3:
if field[i+1][j] == -1:
field[i][j] = field[i][j] + 1
if j != 0:
if field[i+1][j-1] == -1:
field[i][j] = field[i][j] + 1
if j != 3:
if field[i+1][j+1] == -1:
field[i][j] = field[i][j] + 1
self.fieldd = field
self.visualize()
def visualize(self):
self.tb.clear()
field = ''
for i in range(0, len(self.fieldd)):
for j in self.fieldd[i]:
if j == -1:
field = field + '💣'
if j == 0:
field = field + '0 '
if j == 1:
field = field + '1️ '
if j == 2:
field = field + '2️ '
if j == 3:
field = field + '3️ '
if j == 4:
field = field + '4️ '
if j == 5:
field = field + '5️ '
if j == 6:
field = field + '6️ '
if j == 7:
field = field + '7️ '
if j == 8:
field = field + '8️ '
field = field + '\n'
text = ''
for i in range(0, len(self.fieldd)):
for j in self.fieldd[i]:
if j == -1:
text = text + '||:bomb:||'
if j == 0:
text = text + '||:zero:||'
if j == 1:
text = text + '||:one:||'
if j == 2:
text = text + '||:two:||'
if j == 3:
text = text + '||:three:||'
if j == 4:
text = text + '||:four:||'
if j == 5:
text = text + '||:five:||'
if j == 6:
text = text + '||:six:||'
if j == 7:
text = text + '||:seven:||'
if j == 8:
text = text + '||:eight:||'
text = text + '\n'
copy(text)
self.tb.append(field)
app = QApplication([])
window = Window()
window.show()
sys.exit(app.exec())
|