资源简介
python3.5.2版本的2048小游戏,基于wxpython开发的GUI,解压后有.exe执行文件可以打开直接开始游戏,具体源代码请进我的主页查找~
代码片段和文件信息
# -*- coding:utf-8 -*-
import wx
import random
import copy
import math
class Myframe(wx.frame):
def __init__(selfparent id title):#初始化,随机产生两个2
global image
image=[i for i in range(16)]
tmp = wx.Image(“2048/0.png“wx.BITMAP_TYPE_PNG)
image[0] = tmp.ConvertToBitmap()
for i in range(116):
tmp = wx.Image(“2048/%s.png“%(2**i)wx.BITMAP_TYPE_PNG)
image[i]=tmp.ConvertToBitmap()
global scoremtr_stkscr_stkmaxfs
self.maxfs=2048
wx.frame.__init__(self parentid title size=(8701030))
tmp = wx.Image(“2048/background.png“wx.BITMAP_TYPE_PNG)
bjtp=tmp.ConvertToBitmap()
self.bj=wx.StaticBitmap(parent=self bitmap=bjtppos=(00)size=(8701030))
#self.panel=wx.Panel(selfpos=(00)size=(500700))
#a=wx.StaticText(parent=self.bjlabel=‘分数:‘pos=(610300))
self.fenshu=wx.StaticText(parent=self.bjlabel=‘0‘pos=(670257)style=wx.ALIGN_CENTRE)
self.fenshu.SetFont( wx.Font( 20 70 90 90 False “张海山草泥马体“ ) )
self.okbtn=wx.Button(parent=self.bjlabel=‘开始‘pos=(95760))
self.okbtn.SetFont( wx.Font( 12 70 90 90 False “张海山草泥马体“ ) )
self.okbtn.Bind(wx.EVT_BUTTONself.kaishi)
self.okbtn.Bind(wx.EVT_KEY_DOWNself.move)
self.fhbtn=wx.Button(parent=self.bjlabel=‘返回‘pos=(275760))
self.fhbtn.SetFont( wx.Font( 12 70 90 90 False “张海山草泥马体“ ) )
self.fhbtn.Bind(wx.EVT_BUTTONself.fanhui)
self.fhbtn.Bind(wx.EVT_KEY_DOWNself.move)
self.bj.text = [[0 for i in range(4)] for j in range(4)]#按钮
self.bj.huaban = [[0 for i in range(4)] for j in range(4)]#画板
#self.guize=wx.Panel(parent=selfpos=(5000)size=(350700))
#tmp = wx.Image(“2048/rule.png“wx.BITMAP_TYPE_PNG)
#rule=tmp.ConvertToBitmap()
#wx.StaticBitmap(parent=self.guize bitmap=rulepos=(00))
for i in range(4):
for j in range(4):
self.bj.text[i][j]=wx.Button(parent=self.bjlabel=‘0‘pos=(111*i+25111*j+300)size=(109109))
self.bj.huaban[i][j]=wx.StaticBitmap(parent=self.bj.text[i][j] bitmap=image[0])
self.bj.text[i][j].Bind(wx.EVT_KEY_DOWNself.move)
score=0
mtr_stk = [] # for back
scr_stk = []
scr_stk.append(0)
amp=[[0 for i in range(4)] for j in range(4)]
ran_pos = random.sample(range(16) 2)
#a=wx.StaticBitmap(parent=self.panel.text[int(ran_pos[0]/4)][int(ran_pos[0]%4)] bitmap=image[1])#加‘2’图片
self.bj.huaban[int(ran_pos[0]/4)][int(ran_pos[0]%4)].SetBitmap(image[1])
#wx.StaticBitmap(parent=self.panel.text[int(ran_pos[1]/4)][int(ran_pos[1]%4)] bitmap=image[1])#加‘2’图片
self.bj.huaban[int(ran_pos[1]/4)][int(ran_pos[1]%4)].SetBitmap(image[1])
self.bj.text[int(ran_pos[0]/4)][int(ran_pos[0]%4)] .SetLabel(‘2‘)
self.bj.text[int(ra
- 上一篇:机器学习-python处理UCI鲍鱼数据集.rar
- 下一篇:使用单目摄像头测量距离
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论