Fueren
Hectopat
- Katılım
- 23 Aralık 2023
- Mesajlar
- 2.051
- Makaleler
- 2
- Çözümler
- 36
Daha fazla
- Cinsiyet
- Erkek
- Meslek
- YKS Öğrencisi
Kod:
import pygame, sys, random
colors = [(172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101),
(179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94),
(172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101),
(179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94),
(172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101),
(179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94),
(172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101),
(179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94), (179, 214, 101), (172, 208, 94)]
coordinates = [(0,0), (75,0), (150,0), (225,0), (300,0), (375,0), (450,0), (525,0),
(0,75), (75,75), (150,75), (225,75), (300,75), (375,75), (450,75), (525,75),
(0,150), (75,150), (150,150), (225,150), (300,150), (375,150), (450,150), (525,150),
(0,225), (75,225), (150,225), (225,225), (300,225), (375,225), (450,225), (525,225),
(0,300), (75,300), (150,300), (225,300), (300,300), (375,300), (450,300), (525,300),
(0,375), (75,375), (150,375), (225,375), (300,375), (375,375), (450,375), (525,375),
(0,450), (75,450), (150,450), (225,450), (300,450), (375,450), (450,450), (525,450),
(0,525), (75,525), (150,525), (225,525), (300,525), (375,525), (450,525), (525,525)]
def destroyMine():
global i
mousepos = pygame.mouse.get_pos()
mousex = mousepos[0] // 75
mousey = mousepos[1] // 75
tile_index = mousey * 8 + mousex
if len(pressed) == 0:
placeMines(10, coordinates[tile_index])
pressed.append(coordinates[tile_index])
surf.fill((223, 195, 163))
screen.blit(surf, coordinates[tile_index])
else:
if coordinates[tile_index] in mines:
pygame.quit()
sys.exit()
elif coordinates[tile_index] not in pressed:
surf.fill((223, 195, 163))
screen.blit(surf, coordinates[tile_index])
pressed.append(coordinates[tile_index])
i = 1
checkEmptyTiles(coordinates[tile_index])
def checkEmptyTiles(coord):
#Edges
if (coord[0] + (i*75), coord[1]) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] + (i*75), coord[1]))
pressed.append((coord[0] + (i*75), coord[1]))
if (coord[0] - (i*75), coord[1]) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1]))
pressed.append((coord[0] - (i*75), coord[1]))
if (coord[0], coord[1] + (i*75)) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0], coord[1] + (i*75)))
pressed.append((coord[0], coord[1] + (i*75)))
if (coord[0], coord[1] - (i*75)) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0], coord[1] - (i*75)))
pressed.append((coord[0], coord[1] - (i*75)))
#Corners
if (coord[0] + (i*75), coord[1] + (i*75)) in mines:
pass
if (coord[0] + (i*75), coord[1] - (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] + (i*75), coord[1] - (i*75)))
pressed.append((coord[0] + (i*75), coord[1] - (i*75)))
if (coord[0] - (i*75), coord[1] + (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1] + (i*75)))
pressed.append((coord[0] - (i*75), coord[1] + (i*75)))
if (coord[0] - (i*75), coord[1] - (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1] - (i*75)))
pressed.append((coord[0] - (i*75), coord[1] - (i*75)))
def drawTiles(i):
global rect, surf
surf = pygame.surface.Surface((75,75))
surf.fill(colors[i])
rect = surf.get_rect(topleft = coordinates[i])
screen.blit(surf,rect)
def placeMines(mineNum, pressedTile):
global mines
mines = []
i = 0
while i != mineNum:
randcord = random.randrange(0,63)
if coordinates[randcord] != pressedTile:
if coordinates[randcord] not in mines:
mines.append(coordinates[randcord])
surf.fill((214, 109, 111))
screen.blit(surf, coordinates[randcord])
else:
randcord = random.randrange(0,63)
else:
randcord = random.randrange(0,63)
i += 1
print(mines)
pygame.init()
screen = pygame.display.set_mode((600,600))
pygame.display.set_caption("Minesweeper")
clock = pygame.time.Clock()
gameState = "play"
i1 = 0
#Assets
bgsurf = pygame.image.load("assets/minesweeperbg.png")
bgrect = bgsurf.get_rect()
pressed = []
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pressed()[0]:
destroyMine()
elif pygame.mouse.get_pressed()[2]:
pass
#Draw Board
while i1 != 64:
drawTiles(i1)
i1 += 1
#Blits
if gameState == "play":
#screen.blit(bgsurf, bgrect)
pass
#Update
pygame.display.update()
clock.tick(60)
Bu kodda
checkEmptyTiles
fonksiyonunu istediğim gibi çalıştıramıyorum. Fonksiyon:
Kod:
def checkEmptyTiles(coord):
#Edges
if (coord[0] + (i*75), coord[1]) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] + (i*75), coord[1]))
pressed.append((coord[0] + (i*75), coord[1]))
if (coord[0] - (i*75), coord[1]) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1]))
pressed.append((coord[0] - (i*75), coord[1]))
if (coord[0], coord[1] + (i*75)) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0], coord[1] + (i*75)))
pressed.append((coord[0], coord[1] + (i*75)))
if (coord[0], coord[1] - (i*75)) not in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0], coord[1] - (i*75)))
pressed.append((coord[0], coord[1] - (i*75)))
#Corners
if (coord[0] + (i*75), coord[1] + (i*75)) in mines:
pass
if (coord[0] + (i*75), coord[1] - (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] + (i*75), coord[1] - (i*75)))
pressed.append((coord[0] + (i*75), coord[1] - (i*75)))
if (coord[0] - (i*75), coord[1] + (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1] + (i*75)))
pressed.append((coord[0] - (i*75), coord[1] + (i*75)))
if (coord[0] - (i*75), coord[1] - (i*75)) in mines:
surf.fill((223, 195, 163))
screen.blit(surf, (coord[0] - (i*75), coord[1] - (i*75)))
pressed.append((coord[0] - (i*75), coord[1] - (i*75)))
İstediğim şey sağına, soluna, üstüne ve altına bakarak boş olan karoların koordinatına bir kare eklemesi. Çaprazına da bakacak fakat çaprazı boş olsa bile orayı doldurmayacak. Bir karo çevresinde çalışsada ben bunun boş karoların yanındaki boş karolarıda doldurmak istiyorum. Ta ki yanındaki veya çaprazındaki mayın çıkıncaya kadar. Oradan sonrası için fikrim var fakat burada tıkandım diyebilirim. ChatGPT'ye sorduğumda bu koddan da kötü ve çalışmayan bir kod verdi.
Son düzenleme: