-
Notifications
You must be signed in to change notification settings - Fork 0
/
level_info.py
77 lines (62 loc) · 2.03 KB
/
level_info.py
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
# 9×9 10顆
# 16×16 40顆地
# 30×16 99顆地雷
import random
class LevleInfo():
EAZY = 1
NORMAL = 2
HARD = 3
def new_table(self, level):
self.__cal_bomb_table(level)
self.__cal_bomb_arround_for_dispaly_table()
def get_bomb_table(self):
return self.__bomb_table
def get_diplay_table(self):
return self.__display_table
def get_level_list(self):
level_list = []
level_1 = [10,10,9,9]
level_2 = [40,40,16,16]
level_3 = [99,99,30,16]
level_list.append([])
level_list.append(level_1)
level_list.append(level_2)
level_list.append(level_3)
return level_list
def __cal_bomb_arround_for_dispaly_table(self):
col = len(self.__bomb_table)
row = len(self.__bomb_table[0])
self.__display_table = [[0 for x in range(row)] for y in range(col)]
for x in range(col):
for y in range(row):
if self.__bomb_table[x][y] == 1:
if x - 1 >= 0 and y - 1 >= 0 : self.__display_table[x-1][y-1] += 1
if y - 1 >= 0 : self.__display_table[x][y-1] += 1
if x + 1 < col and y - 1 >= 0 : self.__display_table[x+1][y-1] += 1
if x - 1 >= 0 : self.__display_table[x-1][y] += 1
if x + 1 < col : self.__display_table[x+1][y] += 1
if x - 1 >= 0 and y + 1 < row : self.__display_table[x-1][y+1] += 1
if y + 1 < row : self.__display_table[x][y+1] += 1
if x + 1 < col and y + 1 < row : self.__display_table[x+1][y+1] += 1
def __cal_bomb_table(self,level):
if level == self.EAZY:
self.__bomb_table = [[0 for x in range(9)] for y in range(9)]
num = random.sample(range(81), 10)
for i in num:
x = i % 9
y = i / 9
self.__bomb_table[x][int(y)] = 1
elif level == self.NORMAL:
self.__bomb_table = [[0 for x in range(16)] for y in range(16)]
num = random.sample(range(256), 40)
for i in num:
x = i % 16
y = i / 16
self.__bomb_table[x][int(y)] = 1
elif level == self.HARD:
self.__bomb_table = [[0 for x in range(16)] for y in range(30)]
num = random.sample(range(480), 99)
for i in num:
x = i % 30
y = i / 30
self.__bomb_table[x][int(y)] = 1