聊时编写的一个python小游戏 需要pygame模块
聊时编写的一个python小游戏 需要pygame模块,练习使用。
1. [代码][Python]代码
import sys import pygame import math from pygame.locals import * pygame.init() screen = pygame.display.set_mode((600,500)) pygame.display.set_caption("hahsdhf") myfont = pygame.font.Font(None, 60) color = 200,80,60 width = 4 x = 300 y = 250 radius = 200 position = x-radius, y-radius, radius*2, radius*2 piece1 = False piece2 = False piece3 = False piece4 = False while True: for evevt in pygame.event.get(): if evevt.type == QUIT: sys.exit() elif evevt.type == KEYUP: if evevt.key == pygame.K_ESCAPE: sys.exit() elif evevt.key == pygame.K_1: piece1 = True elif evevt.key == pygame.K_2: piece2 = True elif evevt.key == pygame.K_3: piece3 = True elif evevt.key == pygame.K_4: piece4 = True # clean the screen screen.fill((0,0,200)) # draw the four number textImage1 = myfont.render("1", True, color) screen.blit(textImage1, (x+radius/2-20, y-radius/2)) textImage2 = myfont.render("2", True, color) screen.blit(textImage2, (x-radius/2, y-radius/2)) textImage3 = myfont.render("3", True, color) screen.blit(textImage3, (x-radius/2, y+radius/2-20)) textImage4 = myfont.render("4", True, color) screen.blit(textImage4, (x+radius/2-20, y+radius/2-20)) # should the pieces be down if piece1: start_angle = math.radians(0) end_angle = math.radians(90) pygame.draw.arc(screen, color, position, start_angle, end_angle, width) pygame.draw.line(screen, color, (x,y), (x,y-radius), width) pygame.draw.line(screen, color, (x,y), (x+radius,y), width) if piece2: start_angle = math.radians(90) end_angle = math.radians(180) pygame.draw.arc(screen, color, position, start_angle, end_angle, width) pygame.draw.line(screen, color, (x,y), (x,y-radius), width) pygame.draw.line(screen, color, (x,y), (x-radius,y), width) if piece3: start_angle = math.radians(180) end_angle = math.radians(270) pygame.draw.arc(screen, color, position, start_angle, end_angle, width) pygame.draw.line(screen, color, (x,y), (x-radius,y), width) pygame.draw.line(screen, color, (x,y), (x,y+radius), width) if piece4: start_angle = math.radians(270) end_angle = math.radians(360) pygame.draw.arc(screen, color, position, start_angle, end_angle, width) pygame.draw.line(screen, color, (x,y), (x,y+radius), width) pygame.draw.line(screen, color, (x,y), (x+radius,y), width) # is the pie finished? if piece1 and piece2 and piece3 and piece4: color = 0,250,0 pygame.display.update()
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/game/g471.html
相关文章 Recommend
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • pycharm编辑器‘�û�δ��这种乱码,需要转码还
- • 要做跨平台客户端的软件,用哪种编程语言最适合
- • tornado连接数据库报NameError是编码不对吗
- • Flask-WTF在编辑一个记录的时候,下拉菜单如何同
- • python编码cherrypy库文件乱码
- • 《python核心编程》复数取余的问题
- • python邮件乱码 smtp模块文本编码问题
- • Python编程用户发贴cookie id等问题求解
- • linux + python2 + zsh, unicode编码显示异常
我要分享到:
上一篇:没有了
下一篇:pyhton麻将胡牌听牌判断
下一篇:pyhton麻将胡牌听牌判断
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • pyhton麻将胡牌听牌判断
- • 聊时编写的一个python小游戏 需要pygame模块
- • 下载游戏IP座标等信息的python方法
- • 基于web.py框架带提示的猜数字游戏
- • 益智盒子问题python的解决方法
- • 模拟经营的python小游戏
- • Python编写的点灯小游戏代码
- • python猜数字游戏快速求解解决方案
- • 用Python语言打印杨辉三角形方法示例
- • Python方法生成华容道所有开局
图文精华 RECOMMEND
-
益智盒子问题python的解决方法
-
模拟经营的python小游戏
-
用Python语言打印杨辉三角形方法示
-
Python方法生成华容道所有开局
-
Python编写的俄罗斯方块游戏案例源
-
Python实现自动扫雷游戏的方法源码
热点文章 HOT
- Python实现自动扫雷游戏的方法源码
- 模拟经营的python小游戏
- 用Python语言打印杨辉三角形方法示例
- Python方法生成华容道所有开局
- Python 井字棋三连棋游戏代码
- Python方法解扑克牌24点游戏代码
- 看看python是如何解决三赌徒问题的
- 下载游戏IP座标等信息的python方法