代码:
# 拼图 from sys import exit from random import shuffle # 游戏胜利 def victory(): print(‘‘‘ * * * * * * 6 6 6 * *victory* * !!!!! * * * * * *‘‘‘) # 定义 main def main(): boxs = [‘ ‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘] shuffle(boxs) while True: boxs_num = boxs print(‘‘‘ * * * * * * %s %s %s * * %s %s %s * * %s %s %s * * * * * *‘‘‘ % tuple(boxs_num)) ins = input(‘请输入要移动的数字, (0 退出游戏) \> ‘) if ins == ‘0‘: exit() kong_index = boxs_num.index(‘ ‘) num_index = boxs_num.index(ins) if (kong_index - num_index) in (-1,1,3,-3): boxs_num[num_index],boxs_num[kong_index] = boxs_num[kong_index],boxs_num[num_index] if boxs_num == [‘ ‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘] or boxs_num == [‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘ ‘]: victory() exit() # 调用main main()
时间: 2024-10-13 16:10:50