Update 'minesweeper.py'

This commit is contained in:
MTBBK 2022-10-02 14:59:49 +03:00
parent afeda8f4ed
commit c8b3ddc7f4

View file

@ -22,6 +22,7 @@ from qiskit.visualization import *
from ibm_quantum_widgets import * from ibm_quantum_widgets import *
def rastgele(): def rastgele():
# Loading your IBM Quantum account(s) # Loading your IBM Quantum account(s)
print('Libraries imported successfully!') print('Libraries imported successfully!')
@ -1111,6 +1112,9 @@ def rastgele():
pygame.init() pygame.init()
img = pygame.image.load('sankey.jpg')
pygame.display.set_icon(img)
white = (255, 255, 255) white = (255, 255, 255)
gray = (208, 209, 217) gray = (208, 209, 217)
yellow = (255, 255, 102) yellow = (255, 255, 102)
@ -1132,23 +1136,6 @@ def rastgele():
pygame.init() pygame.init()
counter, text = 3, '3'.rjust(3)
pygame.time.set_timer(pygame.USEREVENT, 1000)
font = pygame.font.SysFont('Consolas', 30)
screen = pygame.display.set_mode((256, 256))
clock = pygame.time.Clock()
run = True
while run:
for e in pygame.event.get():
if e.type == pygame.USEREVENT:
counter -= 1
text = str(counter).rjust(3) if counter > 0 else 'boom!'
if e.type == pygame.QUIT:
run = False
screen.fill((255, 255, 255))
screen.blit(font.render(text, True, (0, 0, 0)), (92, 110))
pygame.display.flip()
clock.tick(60)
dis = pygame.display.set_mode((dis_width, dis_height)) dis = pygame.display.set_mode((dis_width, dis_height))
snake_block = 32 snake_block = 32
snake_speed = 10 snake_speed = 10
@ -1167,7 +1154,7 @@ def rastgele():
def our_snake(snake_block, snake_list): def our_snake(snake_block, snake_list):
for x in snake_list: for x in snake_list:
pygame.draw.rect(dis, red, [x[0], x[1], snake_block, snake_block]) pygame.draw.rect(dis, green, [x[0], x[1], snake_block, snake_block])
def message(msg, color): def message(msg, color):
@ -1194,10 +1181,8 @@ def rastgele():
foodx = round((xDegerX - snake_block) / 160.0) * 160.0 foodx = round((xDegerX - snake_block) / 160.0) * 160.0
foody = round((yDegerY - snake_block) / 160.0) * 160.0 foody = round((yDegerY - snake_block) / 160.0) * 160.0
pygame.display.flip() foodx1 = round((xDegerX - snake_block) / 160.0) * 160.0
pygame.event.pump() foody1 = round((yDegerY - snake_block) / 160.0) * 160.0
pygame.time.delay(1000) # 1 second == 1000 milliseconds
while not game_over: while not game_over:
@ -1234,24 +1219,29 @@ def rastgele():
#if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0: #if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
# game_close = True # game_close = True
x1 += x1_change x1 = x1+x1_change
y1 += y1_change y1 = y1+y1_change
arac = 0
if gercek_konumx < x1: if gercek_konumx < x1 and arac == 0:
x1_change = -snake_block x1_change = -snake_block
print("SOL") print("SOL")
elif gercek_konumx > x1: elif gercek_konumx > x1 and arac == 0:
x1_change = snake_block x1_change = snake_block
print("SAĞ") print("SAĞ")
if gercek_konumy < y1: else:
arac = 1
if gercek_konumy < y1 and arac == 1:
y1_change = -snake_block y1_change = -snake_block
print("AŞAĞI") print("AŞAĞI")
elif gercek_konumy > y1: elif gercek_konumy > y1 and arac == 1:
y1_change = snake_block y1_change = snake_block
print("YUKARI") print("YUKARI")
print("XXXX", x1) print("XXXX", x1)
print("YYYY", y1) print("YYYY", y1)
print("GERÇEK-X", gercek_konumx) print("GERÇEK-X", gercek_konumx)
@ -1288,7 +1278,7 @@ def rastgele():
pygame.draw.line(dis, (213, 50, 80), (xa,0),(xa,w)) pygame.draw.line(dis, (213, 50, 80), (xa,0),(xa,w))
pygame.draw.line(dis, (213, 50, 80), (0,ya),(w,ya)) pygame.draw.line(dis, (213, 50, 80), (0,ya),(w,ya))
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block]) pygame.draw.rect(dis, red, [foodx, foody, snake_block, snake_block])
snake_Head = [] snake_Head = []
snake_Head.append(x1) snake_Head.append(x1)
snake_Head.append(y1) snake_Head.append(y1)
@ -1309,6 +1299,7 @@ def rastgele():
foodx = round((xDegerX - snake_block) / 160.0) * 160.0 foodx = round((xDegerX - snake_block) / 160.0) * 160.0
foody = round((yDegerY - snake_block) / 160.0) * 160.0 foody = round((yDegerY - snake_block) / 160.0) * 160.0
Length_of_snake += 1 Length_of_snake += 1
pygame.draw.rect(dis, blue, [foodx1, foody1, snake_block, snake_block])
xgel = foodx + 100 xgel = foodx + 100
if pygame.key.get_pressed()[pygame.K_a]: if pygame.key.get_pressed()[pygame.K_a]: