资源简介
基于python的猜单词游戏,里面有海龟模块的调用,也有graphics做图形界面的例子,可以帮助你们学习游戏开发的基本思路以及部分模块的调用
代码片段和文件信息
# 1: Setup Your Python Program File project2.py
#
# Name:YAHUI SUN
# Program: Project #2
# Description: Guess Master 2.0 In this graphical veion of the game
# the player must still guess the letters in a random word selected
# from the words.txt file however in each round when a player correctly
# guesses all the characters in a word a new round begins and they have
# a new word to guess. Players earn points as they win each round
from graphics import *
import sys
from turtle import *
#### Util methods to reduce duplicated codes ####
# from graphics.graphics import Point Rectangle GraphWin Text Circle Polygon
def draw_text(win pt text color=‘black‘ size=16 style=‘normal‘):
text = Text(pt text)
text.setTextColor(color)
text.setstyle(style)
text.setSize(size)
text.draw(win)
return text
def draw_circle(win pt radius color):
circle = Circle(pt radius)
circle.setFill(color)
circle.draw(win)
return circle
def draw_rect(win x y width height color):
rect = Rectangle(Point(x y) Point(x + width y + height))
rect.setFill(color)
rect.draw(win)
return rect
def draw_poly(win x1 x2 x3 y1 y2 color):
‘‘‘Draw poly: (x1 y1) (x2y1) (x3 y2) (x3-(x2-x1) y2) ‘‘‘
poly = Polygon(Point(x1 y1) Point(x2 y1) Point(x3 y2) Point(x3 - x2 + x1 y2))
poly.setFill(color)
poly.draw(win)
return poly
def is_inside_rect(point rect):
if rect.p1.x < point.x < rect.p2.x:
if rect.p1.y < point.y < rect.p2.y:
return True
return False
def is_inside_circle(point circle):
center = circle.getCenter()
dx dy = center.getX() - point.getX() center.getY() - point.getY()
dist radius = dx * dx + dy * dy circle.getRadius()
return dist < radius * radius
# check for mouse clicks to the hints_rect
# Check for mouse clicks in the control panel
def control_mouse_check(ctrl_win new_rect quit_rect hints_rect):
click_point = ctrl_win.checkMouse()
if click_point is not None:
if is_inside_rect(click_point quit_rect):
return 0
elif is_inside_rect(click_point new_rect):
return 1
elif is_inside_rect(click_point hints_rect):
return 2
return 3
def draw_score(win score_text score):
if score_text is not None:
score_text.undraw()
return draw_text(win Point(250 20) ‘SCORE: ‘ + str(score) ‘black‘ 16 ‘normal‘)
def draw_secret_char(win i secret_word):
word_len = len(secret_word)
rect_width pt_y rect_list = 50 40 []
pt_x = 250 - word_len * rect_width / 2
pt_x += i * rect_width
draw_text(win Point(pt_x + rect_width / 2 pt_y + rect_width / 2) secret_word[i] ‘black‘ 16 ‘normal‘)
# 7: Win a Round
def win_the_game(game_win context):
# draw win the game
draw_text(game_win Point(250 250) ‘YOU WIN - BOILER UP!‘ ‘grey‘ 24 ‘bold‘)
draw_text(game_win Point(250 280) ‘Click to continue‘ ‘grey
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-12-07 17:08 单词游戏\
文件 14896 2019-12-07 17:06 单词游戏\project2(1)(1)(1)(1)(1)(2).py
文件 9001 2019-12-06 15:38 单词游戏\words.txt
相关资源
- LUTAI.Tools.IronPythonCheckTool
- 基于Python实现的Pagerank算法
- Python实现数据库
- 传智播客Python就业班2018.zip
- Python对爬取微博的评论进行jieba分词和
- python爬虫 破解js加密有道词典案列的
- python写的旅游网站源码
- 利用鸢尾花数据集画出P-R曲线 pytho
- pyHook-1.5.1-cp38-cp38-win_amd64.whl
- freesmallgames.zip
- python一加云相册批量爬虫
- 实战python利用线性回归来预测鲍鱼年
- 实战python线性回归
- RSA算法的纯Python实现源码
- 请求分页存储管理Python实现源代码+课
- python爬取100个百度百科页面信息
- python面试题大全
- python视频教程.txt
- python爬虫之豆瓣电影使用requests、lx
- 批量提取栅格影像
- 图像配准融合拼接Python.zip
- easygui一个python简单的gui库
- pycharm工程python调用OpenCV实现USB摄像头
- DEM数据三维可视化--python实现
- vae,autoencoderpython实现
- SRNN python代码实现
- ArcGIS Python常用脚本.docx
- Python找不到cl.exe等
- 自动扫雷系统+Python
- 基于标签的用户协同算法python
评论
共有 条评论