pygame2048小游戏源码
# coding:utf-8
import pygame, random
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((1050, 500))
fontText = pygame.font.SysFont("dengxian", 50)
pygame.display.set_caption("2048")
row = 6
col = 6
print("游戏说明\n通过键盘上下左右控制数字移动,\n如果一行或者一列内有相同的两个数字则合成.\n每次按下会随机生成数字\n点击ok按钮开始游戏.")
def showText(text, pos, color=(0, 0, 0)):
screen.blit(fontText.render(text, True, color), pos)
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
if event.type == KEYDOWN:
key = event.key
if key == K_UP:
moveUp(map)
if key == K_DOWN:
moveDown(map)
if key == K_LEFT:
moveLeft(map)
if key == K_RIGHT:
moveRight(map)