Skip to content

Instantly share code, notes, and snippets.

@ccc-larc
ccc-larc / tetris-tkinter.py
Created August 26, 2012 07:40 — forked from anonymous/tetris-tkinter.py
Hack!Python Tetris
# -*- coding=utf8 -*-
import sys,random
from Tkinter import *
score,bw,bh,H,W=0,10,20,30,30
blk = {0xf:"red",0x2e:"#0f0",0x27:"blue",0x47:"#ff0",0x66:"#0ff",0xC6:"#38f",0x6C:"#f0f"}
board = [ [0xf if j==bh else 0]*bw+[0xf]*2 for j in range(bh+2+1) ]
new_piece = lambda pc: ( [((z>>2)+1,z&3) for z in range(16) if (pc>>z)&1], 3, -2, pc )
collide=lambda piece,px,py: [1 for (i,j) in piece if board[j+py][i+px]] #是否碰撞
piece, px, py, pc = new_piece(random.choice(blk.keys())) # 第一個piece
def tick(e=None):