Skip to content

Commit

Permalink
Merge pull request #14 from Zoz4/master
Browse files Browse the repository at this point in the history
Cancel force swap
  • Loading branch information
Tomspiano authored Oct 19, 2020
2 parents 49e6d83 + a90e160 commit 8a8cbd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Kloski.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

description = """
操作指南:
w: 向上移动白块
s: 向下移动白块
a: 向左移动白块
d: 向右移动白块
w: 向上移动可移动方块
s: 向下移动可移动方块
a: 向左移动可移动方块
d: 向右移动可移动方块
q: 退出游戏
如何开始:
点击“Play”即可开始游戏
游戏目标:
移动白块,使所有方块回到正确位置,一起组成字母
移动方块,使所有方块回到正确位置,一起组成字母
"""
print(description)

Expand Down
6 changes: 6 additions & 0 deletions digital_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ 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()
self.swap = generate_swap()
# print(self.step)
# print(self.swap)


def blitme(self):
"""在指定位置加载图片方块"""
for i in range(self.ai_settings.shape):
Expand Down Expand Up @@ -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)
Expand All @@ -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()

4 changes: 2 additions & 2 deletions game_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):

# 数字棋盘的形状和数字方块的大小
self.shape = 3
self.db_size = 200
self.db_size = 150
# 数字棋盘外白边的距离
self.margin = 50

Expand Down

0 comments on commit 8a8cbd6

Please sign in to comment.