-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneration.py
More file actions
38 lines (32 loc) · 1.31 KB
/
generation.py
File metadata and controls
38 lines (32 loc) · 1.31 KB
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
import random
from globalVal import *
from utils import checkInsideLength
def generateBombs():
count = random.randint(8,13)
for i in range(count):
while True:
y = random.randint(0,CELLCOUNT - 1)
x = random.randint(0,CELLCOUNT - 1)
if cells[x][y].cellHiddenState != 1: # not being a bomb
cells[x][y].cellHiddenState = 1
break
def updateAdjBombs():
for y in range(CELLCOUNT):
for x in range(CELLCOUNT):
checkAdjBombs((x,y))
def checkAdjBombs(currentCellPos):
cellWithOffset(currentCellPos, 1, 0)
cellWithOffset(currentCellPos, -1, 0)
cellWithOffset(currentCellPos, 0, 1)
cellWithOffset(currentCellPos, 0, -1)
cellWithOffset(currentCellPos, 1, 1)
cellWithOffset(currentCellPos, 1, -1)
cellWithOffset(currentCellPos, -1, 1)
cellWithOffset(currentCellPos, -1, -1)
def cellWithOffset(currentCellPos, offX, offY):
if not checkInsideLength(currentCellPos[0] + offX, currentCellPos[1] + offY, CELLCOUNT):
return
# add to the adj count incase if the state of the adj cell is a bomb
adjCell = cells[currentCellPos[0] + offX][currentCellPos[1] + offY]
if adjCell.cellHiddenState == 1: # the adj cell is a bomb
cells[currentCellPos[0]][currentCellPos[1]].adjBombCount += 1