diff --git a/Kloski.py b/Kloski.py index 7ef7a89..5a0d2bf 100644 --- a/Kloski.py +++ b/Kloski.py @@ -10,10 +10,10 @@ description = """ 操作指南: - w: 向上移动白块 - s: 向下移动白块 - a: 向左移动白块 - d: 向右移动白块 + w: 向上移动可移动方块 + s: 向下移动可移动方块 + a: 向左移动可移动方块 + d: 向右移动可移动方块 q: 退出游戏 @@ -21,7 +21,7 @@ 点击“Play”即可开始游戏 游戏目标: - 移动白块,使所有方块回到正确位置,一起组成字母 + 移动方块,使所有方块回到正确位置,一起组成字母 """ print(description) diff --git a/digital_blocks.py b/digital_blocks.py index a164d1c..0c63371 100644 --- a/digital_blocks.py +++ b/digital_blocks.py @@ -41,6 +41,7 @@ def __init__(self, ai_settings, screen): self.null_digit_no_cache = None self.status_matrix = np.array(self.status).reshape((ai_settings.shape, ai_settings.shape)) + self.status_matrix_cache = None self.step = generate_step() @@ -48,6 +49,7 @@ def __init__(self, ai_settings, screen): # print(self.step) # print(self.swap) + def blitme(self): """在指定位置加载图片方块""" for i in range(self.ai_settings.shape): @@ -116,10 +118,12 @@ def break_order(self): operation = random.choice(operations) self.move(operation) cnt += 1 + self.status_cache = self.status[:] self.null_digit_no_cache = self.null_digit_no self.status_matrix_cache = self.status_matrix.copy() + def ans(self): with open(self.ai_settings.ans_file_path, 'r') as json_file: ans_dict = json.load(json_file) @@ -130,6 +134,8 @@ def ans(self): return ans_dict[status_str][::-1] def reset_stats(self): + self.status = self.status_cache[:] self.null_digit_no = self.null_digit_no_cache self.status_matrix = self.status_matrix_cache.copy() + diff --git a/game_functions.py b/game_functions.py index b7834bd..7b4b062 100644 --- a/game_functions.py +++ b/game_functions.py @@ -76,8 +76,8 @@ def check_keydown_event(stats, event, blocks): def check_swap(stats): stats.step += 1 - if stats.step == blocks.step: - blocks.swap_blocks() +# if stats.step == blocks.step: +# blocks.swap_blocks() if event.key == pygame.K_w: if blocks.move('w'): diff --git a/settings.py b/settings.py index e0a7814..f8675b3 100644 --- a/settings.py +++ b/settings.py @@ -14,7 +14,7 @@ def __init__(self): # 数字棋盘的形状和数字方块的大小 self.shape = 3 - self.db_size = 200 + self.db_size = 150 # 数字棋盘外白边的距离 self.margin = 50