forked from lzjun567/python_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pygame | ||
import sys | ||
|
||
import sys | ||
import pygame | ||
|
||
# 小五义 http://www.cnblogs.com/xiaowuyi | ||
import pygame, sys | ||
|
||
pygame.init() | ||
|
||
|
||
class Temp(pygame.sprite.Sprite): | ||
def __init__(self, color, initial_position): | ||
pygame.sprite.Sprite.__init__(self) | ||
self.image = pygame.Surface([30, 30]) | ||
self.image.fill(color) | ||
self.rect = self.image.get_rect() | ||
self.rect.topleft = initial_position | ||
|
||
|
||
screen = pygame.display.set_mode([640, 480]) | ||
screen.fill([255, 255, 255]) | ||
b = Temp([255, 0, 0], [150, 100]) | ||
screen.blit(b.image, b.rect) | ||
pygame.display.update() | ||
while True: | ||
for event in pygame.event.get(): | ||
if event.type == pygame.QUIT: | ||
sys.exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
基本要求 | ||
|
||
1. 掌握 Python 语言的基本语法规则。 | ||
2. 掌握不少于 2 个基本的 Python 标准库。 | ||
3. 掌握不少于 2 个 Python 第三方库,掌握获取并安装第三方库的方法。 | ||
4. 能够阅读和分析 Python 程序。 | ||
5. 熟练使用 IDLE 开发环境,能够将脚本程序转变为可执行程序。 | ||
6. 了解 Python 计算生态在以下方面(不限于)的主要第三方库名称:网络爬虫、数据分析、数 | ||
据可视化、机器学习、Web 开发等。 | ||
|
||
考试内容 | ||
|
||
一、 Python 语言基本语法元素 | ||
1. 程序的基本语法元素:程序的格式框架、缩进、注释、变量、命名、保留字、数据类型、赋值 | ||
语句、引用。 | ||
2. 基本输入输出函数:input()、evel()、print()。 | ||
3. 源程序的书写风格。 | ||
4. Python 语言的特点。 | ||
|
||
二、 基本数据类型 | ||
|
||
1. 数字类型:整数类型、浮点数类型和复数类型。 | ||
2. 数字类型的运算:数值运算操作符、数值运算函数。 | ||
3. 字符串类型及格式化:索引、切片、基本的 format()格式化方法。 | ||
4. 字符串类型的操作:字符串操作符、处理函数和处理方法。 | ||
5. 类型判断和类型间转换。 | ||
|
||
三、 程序的控制结构 | ||
|
||
1. 程序的三种控制结构。 | ||
2. 程序的分支结构:单分支结构、二分支结构、多分支结构。 | ||
3. 程序的循环结构:遍历循环、无限循环、break 和 continue 循环控制。 | ||
4. 程序的异常处理:try-except。 | ||
|
||
四、 函数和代码复用 | ||
|
||
1. 函数的定义和使用。 | ||
2. 函数的参数传递:可选参数传递、参数名称传递、函数的返回值。 | ||
3. 变量的作用域:局部变量和全局变量。 | ||
|
||
五、 组合数据类型 | ||
|
||
1. 组合数据类型的基本概念。 | ||
2. 列表类型:定义、索引、切片。 | ||
3. 列表类型的操作:列表的操作函数、列表的操作方法。 | ||
4. 字典类型:定义、索引。 | ||
5. 字典类型的操作:字典的操作函数、字典的操作方法。 | ||
|
||
六、 文件和数据格式化 | ||
|
||
1. 文件的使用:文件打开、读写和关闭。 | ||
2. 数据组织的维度:一维数据和二维数据。 | ||
3. 一维数据的处理:表示、存储和处理。 | ||
4. 二维数据的处理:表示、存储和处理。 | ||
5. 采用 CSV 格式对一二维数据文件的读写。 | ||
|
||
七、 Python 计算生态 | ||
|
||
1. 标准库:turtle 库(必选)、random 库(必选) 、time 库(可选)。 | ||
2. 基本的 Python 内置函数。 | ||
3. 第三方库的获取和安装。 | ||
3. 脚本程序转变为可执行程序的第三方库:pyinstaller 库(必选)。 | ||
4. 第三方库:jieba 库(必选)、wordcloud 库(可选)。 | ||
5. 更广泛的 Python 计算生态,只要求了解第三方库的名称,不限于以下领域:网络爬虫、数 | ||
据分析、文本处理、数据可视化、用户图形界面、机器学习、Web 开发、游戏开发等。 | ||
|
||
考试方式 | ||
|
||
上机考试,考试时长 120 分钟,满分 100 分。 | ||
1. 题型及分值 | ||
单项选择题 40 分(含公共基础知识部分 10 分)。 | ||
操作题 60 分(包括基本编程题和综合编程题)。 | ||
2. 考试环境 | ||
windows7 操作系统,建议 Python 3.4.2 至 Python 3.5.3 版本,IDLE 开发环境。 | ||
|
||
|
||
https://blog.csdn.net/u014044812/article/details/88642003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,9 @@ | ||
import pygame, sys, time, random | ||
from pygame.locals import * | ||
|
||
# 定义颜色变量 | ||
redColour = pygame.Color(255, 0, 0) | ||
blackColour = pygame.Color(0, 0, 0) | ||
whiteColour = pygame.Color(255, 255, 255) | ||
greyColour = pygame.Color(150, 150, 150) | ||
|
||
|
||
def gameOver(playSurface, score): | ||
gameOverFont = pygame.font.SysFont('arial.ttf', 54) | ||
gameOverSurf = gameOverFont.render('Game Over!', True, greyColour) | ||
gameOverRect = gameOverSurf.get_rect() | ||
gameOverRect.midtop = (300, 10) | ||
playSurface.blit(gameOverSurf, gameOverRect) | ||
scoreFont = pygame.font.SysFont('arial.ttf', 54) | ||
scoreSurf = scoreFont.render('Score:' + str(score), True, greyColour) | ||
scoreRect = scoreSurf.get_rect() | ||
scoreRect.midtop = (300, 50) | ||
playSurface.blit(scoreSurf, scoreRect) | ||
pygame.display.flip() | ||
time.sleep(5) | ||
pygame.quit() | ||
sys.exit() | ||
|
||
|
||
def main(): | ||
# 初始化pygame | ||
pygame.init() | ||
fpsClock = pygame.time.Clock() | ||
# 创建pygame显示层 | ||
playSurface = pygame.display.set_mode((600, 460)) | ||
pygame.display.set_caption('Snake Game') | ||
# 初始化变量 | ||
snakePosition = [100, 100] # 贪吃蛇 蛇头的位置 | ||
snakeSegments = [[100, 100]] # 贪吃蛇 蛇的身体,初始为一个单位 | ||
raspberryPosition = [300, 300] # 树莓的初始位置 | ||
raspberrySpawned = 1 # 树莓的个数为1 | ||
direction = 'right' # 初始方向为右 | ||
changeDirection = direction | ||
score = 0 # 初始得分 | ||
while True: | ||
# 检测例如按键等pygame事件 | ||
for event in pygame.event.get(): | ||
if event.type == QUIT: | ||
pygame.quit() | ||
sys.exit() | ||
elif event.type == KEYDOWN: | ||
# 判断键盘事件 | ||
if event.key == K_RIGHT or event.key == ord('d'): | ||
changeDirection = 'right' | ||
if event.key == K_LEFT or event.key == ord('a'): | ||
changeDirection = 'left' | ||
if event.key == K_UP or event.key == ord('w'): | ||
changeDirection = 'up' | ||
if event.key == K_DOWN or event.key == ord('s'): | ||
changeDirection = 'down' | ||
if event.key == K_ESCAPE: | ||
pygame.event.post(pygame.event.Event(QUIT)) | ||
# 判断是否输入了反方向 | ||
if changeDirection == 'right' and not direction == 'left': | ||
direction = changeDirection | ||
if changeDirection == 'left' and not direction == 'right': | ||
direction = changeDirection | ||
if changeDirection == 'up' and not direction == 'down': | ||
direction = changeDirection | ||
if changeDirection == 'down' and not direction == 'up': | ||
direction = changeDirection | ||
# 根据方向移动蛇头的坐标 | ||
if direction == 'right': | ||
snakePosition[0] += 20 | ||
if direction == 'left': | ||
snakePosition[0] -= 20 | ||
if direction == 'up': | ||
snakePosition[1] -= 20 | ||
if direction == 'down': | ||
snakePosition[1] += 20 | ||
# 增加蛇的长度 | ||
snakeSegments.insert(0, list(snakePosition)) | ||
# 判断是否吃掉了树莓 | ||
if snakePosition[0] == raspberryPosition[0] and snakePosition[1] == raspberryPosition[1]: | ||
raspberrySpawned = 0 | ||
else: | ||
snakeSegments.pop() | ||
# 如果吃掉树莓,则重新生成树莓 | ||
if raspberrySpawned == 0: | ||
x = random.randrange(1, 30) | ||
y = random.randrange(1, 23) | ||
raspberryPosition = [int(x * 20), int(y * 20)] | ||
raspberrySpawned = 1 | ||
score += 1 | ||
# 绘制pygame显示层 | ||
playSurface.fill(blackColour) | ||
for position in snakeSegments: | ||
pygame.draw.rect(playSurface, whiteColour, Rect(position[0], position[1], 20, 20)) | ||
pygame.draw.rect(playSurface, redColour, Rect(raspberryPosition[0], raspberryPosition[1], 20, 20)) | ||
# 刷新pygame显示层 | ||
pygame.display.flip() | ||
# 判断是否死亡 | ||
if snakePosition[0] > 600 or snakePosition[0] < 0: | ||
gameOver(playSurface, score) | ||
if snakePosition[1] > 460 or snakePosition[1] < 0: | ||
gameOver(playSurface, score) | ||
for snakeBody in snakeSegments[1:]: | ||
if snakePosition[0] == snakeBody[0] and snakePosition[1] == snakeBody[1]: | ||
gameOver(playSurface, score) | ||
# 控制游戏速度 | ||
fpsClock.tick(5) | ||
|
||
def xx(): | ||
pass | ||
|
||
if __name__ == "__main__": | ||
main() | ||
# main() | ||
xx(1,2) |
Binary file added
BIN
+1.92 MB
...d2f6d61782f3830302f312a333862794a79465841505941696c50415a53425a51772e676966.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.