block_num=12
bspace = 2
space = 20
width = block_size * block_num + main_space * 2
height = header_height + block_size * block_num + main_space * 2 + (block_size+space) * 3
pygame.init()
screen = pygame.display.set_mode((width,height))
screencaption = pygame.display.set_caption(u'成语填空')
font = pygame.font.Font(u'syht.otf', int(block_size*0.8))
dray_gray = 50,50,50
white = 255,255,255
#textImage = font.render(u'你好', True, white)
class IdiomInfo(object):
def __init__(self,idiom):
self.idiom = idiom
self.dire = 0
self.word_arr = []
class WordInfo(object):
def __init__(self, word, i, j):
self.i = i
self.j = j
self.word = word
self.is_lock = True
self.state = -1
self.hide_index = -1
self.op_hide_index = -1
class Matrix(object):
rows = 0
cols = 0
data = []
def __init__(self, rows, cols, data=None):
self.rows = rows
self.cols = cols
if data is None: data = [None for i in range(rows * cols)] self.data = data
def set_val(self, x, y, val):
self.data[y * self.cols + x] = val
def get_val(self, x, y):
return self.data[y * self.cols + x]
def exist_val_four_around(self, x, y, ignore_set):
move_arr = [(-1,0),(1,0),(0,-1),(0,1)]
for dx,dy in move_arr:
tx = x + dx
ty = y + dy
if (tx,ty) in ignore_set: continue
if tx < 0 or tx >= self.cols or ty <0 or ty >= self.rows: continue
if self.data[ty * self.cols + tx]: return True
return False
def check_new_idiom(matrix, new_idiom, new_dire, word_info):
windex = new_idiom.index(word_info.word)
cx,cy = word_info.i, word_info.j
ignore_set = set([(cx,cy)])
new_idiom_word_arr=[] for i in range(-windex,-windex+len(new_idiom)):
if i==0:
new_idiom_word_arr.append(word_info)
else:
tx = cx+i if new_dire == 0 else cx
if tx < 0 or tx >= block_num: return None,None