Last active
October 11, 2019 02:24
-
-
Save cacapon/400077e072e75bbb03fde2175c21888d to your computer and use it in GitHub Desktop.
出来る限り簡単にした連鎖処理のプログラムです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
from copy import deepcopy | |
from os import system | |
from time import sleep | |
# 配列の準備 | |
line = [] | |
stg = [] | |
for i in range(8): | |
line.append(i * 2 + 2) | |
line.append(i + 1) | |
line.append(i * 2 + 1) | |
stg.append(deepcopy(line)) | |
line.clear() | |
stg.reverse() | |
# loopを止めるためのフラグ | |
global loop_flg | |
loop_flg = True | |
def draw(): | |
#表示 | |
system('cls') | |
pprint(stg) | |
sleep(0.5) | |
def search_same_num(y=0): | |
# yがライン数と同じなら終了 | |
if y == len(stg): | |
return | |
# 隣の数字が自分と同じだったらその数を0にする | |
_remove_same_num(y, 0, 1) | |
# その隣の数字が自分と同じだったらその数を0にする | |
_remove_same_num(y, 1, 2) | |
# 下のラインへ | |
search_same_num(y=y+1) | |
def _remove_same_num(y, x1, x2): | |
# 二つの数字が0以外であり、かつ同じかチェック | |
# 同じだったら消す。 | |
global loop_flg | |
if stg[y][x1] == 0 or stg[y][x2] == 0: | |
return # 0だったらパス | |
if stg[y][x1] == stg[y][x2]: | |
loop_flg = True | |
stg[y][x1] = 0 | |
stg[y][x2] = 0 | |
def move_num(y=len(stg)-1): | |
# yが0なら終了 | |
if y == 0: | |
return | |
for x in range(3): | |
if stg[y][x] == 0: | |
#一個上のを落とす | |
stg[y][x] = stg[y - 1][x] | |
stg[y - 1][x] = 0 | |
move_num(y=y-1) | |
while (loop_flg): | |
loop_flg = False # 消す処理が発生するとTrueに戻る | |
# 表示 | |
draw() | |
# 自分と同じ数字が横にあったら0にする(0は除く) | |
search_same_num() | |
# 表示 | |
draw() | |
# 下が0の場合は下にずらす | |
move_num() | |
# 表示 | |
draw() | |
print('連鎖が終了しました') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment