#coding:utf-8
from Tkinter import *
import random
import tkMessageBox
root = Tk(className = "2048")
root.geometry("320x360")
str_data=[]
B_list = []
frame2 = Frame(root,borderwidth = 10)
dic_color
=
{0:'GhostWhite',
2:'AliceBlue',
4:'LightCyan',
8:'Khaki',16:'SandyBrown',
32:'Goldenrod',64:'Orange',128:'Maroon',256:'Tomato',512:'OrangeRed',1024:'FireBrick',2048:'Re
d'}
list_data=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
left=0
up=1
right=2
down=3
derection_index=[
[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]],
[[0,4,8,12],[1,5,9,13],[2,6,10,14],[3,7,11,15]],
[[3,2,1,0],[7,6,5,4],[11,10,9,8],[15,14,13,12]],
[[12,8,4,0],[13,9,5,1],[14,10,6,2],[15,11,7,3]]
]
for i in range(16):
str_data.append(StringVar())
B_list.append(Button(frame2,
width=4,
height=2,
textvariable
=
str_data[i]
,font
=
("Courier 20 bold roman"),bg=dic_color[0]))
B_list[i].grid(row=i/4,column=i%4)
def CanMove(derection, index):
for i in range(1, 4):
if
list_data[derection_index[derection][index][i]]
==
list_data[derection_index[derection][index][i-1]]:
return True
if
list_data[derection_index[derection][index][i]]
!=
0
and
list_data[derection_index[derection][index][i-1]] == 0:
return True
return False
def DealSpace(derection, index):
for i in [3,2,1]:
if list_data[derection_index[derection][index][i]] == 0:
continue