Code:
# Jigsaw Puzzle from sys import exitfrom random import shuffle# game Victory def Victory (): print ("' * * * * ** 6 6 6 **victory* * !!!!! ** * * * * ") # definition maindef 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 (' Please enter the number to be moved, (0 exit game) \> ') 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 () # call Mainmain ()
This article is from the "Wool Linux Road" blog, please be sure to keep this source http://maoxian.blog.51cto.com/4227070/1893683
Learning Python: Example 3. Terminal Edition jigsaw puzzle game