1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import random from collections import namedtuple Point = namedtuple( 'Point' , 'X Y' ) Shape = namedtuple( 'Shape' , 'X Y Width Height' ) Block = namedtuple( 'Block' , 'template start_pos end_pos name next' ) # S形方块 S_BLOCK = [Block([ '.OO' , 'OO.' , '...' ], Point( 0 , 0 ), Point( 2 , 1 ), 'S' , 1 ), Block([ 'O..' , 'OO.' , '.O.' ], Point( 0 , 0 ), Point( 1 , 2 ), 'S' , 0 )] # Z形方块 Z_BLOCK = [Block([ 'OO.' , '.OO' , '...' ], Point( 0 , 0 ), Point( 2 , 1 ), 'Z' , 1 ), Block([ '.O.' , 'OO.' , 'O..' ], Point( 0 , 0 ), Point( 1 , 2 ), 'Z' , 0 )] # I型方块 I_BLOCK = [Block([ '.O..' , '.O..' , '.O..' , '.O..' ], Point( 1 , 0 ), Point( 1 , 3 ), 'I' , 1 ), Block([ '....' , '....' , 'OOOO' , '....' ], Point( 0 , 2 ), Point( 3 , 2 ), 'I' , 0 )] # O型方块 O_BLOCK = [Block([ 'OO' , 'OO' ], Point( 0 , 0 ), Point( 1 , 1 ), 'O' , 0 )] # J型方块 J_BLOCK = [Block([ 'O..' , 'OOO' , '...' ], Point( 0 , 0 ), Point( 2 , 1 ), 'J' , 1 ), Block([ '.OO' , '.O.' , '.O.' ], Point( 1 , 0 ), Point( 2 , 2 ), 'J' , 2 ), Block([ '...' , 'OOO' , '..O' ], Point( 0 , 1 ), Point( 2 , 2 ), 'J' , 3 ), Block([ '.O.' , '.O.' , 'OO.' ], Point( 0 , 0 ), Point( 1 , 2 ), 'J' , 0 )] # L型方块 L_BLOCK = [Block([ '..O' , 'OOO' , '...' ], Point( 0 , 0 ), Point( 2 , 1 ), 'L' , 1 ), Block([ '.O.' , '.O.' , '.OO' ], Point( 1 , 0 ), Point( 2 , 2 ), 'L' , 2 ), Block([ '...' , 'OOO' , 'O..' ], Point( 0 , 1 ), Point( 2 , 2 ), 'L' , 3 ), Block([ 'OO.' , '.O.' , '.O.' ], Point( 0 , 0 ), Point( 1 , 2 ), 'L' , 0 )] # T型方块 T_BLOCK = [Block([ '.O.' , 'OOO' ,
|