资源简介
基于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
相关资源
- 二级考试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获取硬件信息
评论
共有 条评论