#2048 用python实现
import random
import math
import os
global score
score = 0
def start():#开始
a = [[0 for i in range(4)] for i in range(4)] #构造一个4*4的列表
i = random.randint(0,3)
j = random.randint(0,3)
p2 = random.random()
if p2>0.9: a[i][j] = 4 #有0.9几率出现2
else: a[i][j] = 2
display(a)
def display(a):
os.system('cls')
global score
if (notlose):
print('现在你的分数:',score)
for i in range(4):
for j in range(4):
print("%6s" % a[i][j] , end = '')
print()
action = input('请输入移动方向。输入wsad分别表示上下左右。请注意调成小写模式。')
move(action,a)
else:
print('没有可以用的数字。游戏结束。你得了',score,'分')
def move(action,a):
if action == 'w':
up(a)
elif action == 's':