目录
一. 设计目的 3
二.设计任务和要求 3
三.总体设计 4
四.设计实现 6
(1)最终实现结果: 6
(2)实现结果评价 7
五.详细设计 7
(1)pygame事件 7
(2) 鼠标事件 8
(3)轮询键盘 8
(4)游戏结束的处理 9
(5)游戏等级设置和难度设置 9
(6)游戏过程中的介绍 10
六.调试与测试 12
(1)异常处理 12
(2)调试 12
七.设计总结 12
本课程设计具体目的:
(1)为全面了解Python技术历史、现状与发展趋势的基础上,系统掌握Python基本概念、编程思想以及程序设计技术,具备熟练的Python编程技能和面向对象软件设计技术思想。
(2)通过总体框架到页面设计再到代码实现,了解Python设计的一般步骤,并熟练掌握Python的设计思想。
(3)本课题主要训练逻辑思维和Python语法,对代码编写由大到小,由总体到模块,掌握其基本逻辑,对以后的设计可以做到举一反三,进而形成逻辑思维。
二.设计任务和要求
课程设计教学任务和要求:
本课程设计主要任务是以Python为开发语言完成一个100~300行左右规模的程序项目开发。设计参考题目见附件1。
课程设计的基本要求是:在课程设计的各个阶段严格、规范地完成相关的文档,例如总体方案报告,详细设计报告、功能说明、数据结构说明、算法说明、程序设计框图、图例和源程序等。要求所写文档结构合理、内容完整、叙述清晰。程序源码要有详细注释,可读性好。更高要求是:有创意、系统界面美观。
本课程设计具体任务和要求:
(1)页面完美,逻辑清晰。
(2)代码编写在可读性高的情况下尽可能的简洁。
(3)可选用PyCharm,Python IDLE等开发平台以提高开发效率,通过资料查阅和学习尽可能掌握一种或多种集成开发环境。
(4)共同完成代码的衔接,游戏总体框架和逻辑的实现。分工编写课程设计报告,报告总共包括六大部分:设计目的、设计要求、总体设计、详细设计、调试与测试、设计总结。
# -*-coding:utf-8-*- s = '
#AoDaMiao Like Eating Fish
import sys, random, time, pygame
from pygame.locals import *
def print_text(font, x, y, text, color=(255,255,255)):
imgText = font.render(text, True, color)
screen.blit(imgText, (x,y))
#main program begins
pygame.init()
screen = pygame.display.set_mode((600,500))
pygame.display.set_caption("嗷大喵爱吃鱼!")
font1 = pygame.font.Font(None, 24)
font2 = pygame.font.Font(None, 18)
font3 = pygame.font.Font(None, 34)
pygame.mouse.set_visible(False)
white = 255,255,255
red = 220, 50, 50
yellow = 230,230,50
black = 0,0,0
cat=pygame.image.load("aodamiao_2.png")
width,height=cat.get_size()
pic=pygame.transform.scale(cat,(width,height))
fish=pygame.image.load("fish.png")
width,height=fish.get_size()
fish=pygame.transform.smoothscale(fish,(width//3,height//3))
init=pygame.image.load("init.png")
lives = 10
score = 0
clock_start = 0
game_over = 1
mouse_x = mouse_y = 0
Round =1
mine=0
mine_png=pygame.image.load("mine.png")
cat2=pygame.image.load("aodamiao_3.png")
flag=0
pos_x = 300
pos_y = 410-40
bomb_x = random.randint(0,500)
mine_x=random.randint(0,500)
bomb_y = -50
vel_y = 0.4
vel_yy=0.6
mine_y=-100
#无限循环
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
#sys.exit()
pygame.quit()
exit()
elif event.type == MOUSEMOTION:
mouse_x,mouse_y = event.pos
move_x,move_y = event.rel
elif event.type == MOUSEBUTTONUP:
if game_over:
game_over = False
lives = 10
score = 0
Round =1
vel_y=0.4
mine=0
flag=0
pic=cat
bomb_y = -50
keys = pygame.key.get_pressed()
if keys[K_ESCAPE]:
sys.exit()
screen.fill((0,0,100))
if game_over:
screen.blit(init,(60, 60))
print_text(font3, 200, 400,"Clicked To Play!")
print_text(font2, 310, 480,"Copyright@2015 developed by xiaoxiami")
else:
#等级设置
if score >300 and score <600:
Round=2
elif score >600 and score <900:
Round =3
elif score >900 and score <1200:
Round=4
elif score >1200 and score <1500:
Round =5
elif score >=1500:
Round =6
#难度设置
print_text(font1, 280, 0, "Round: " + str(Round))
if Round ==1:
vel_y=0.4
elif Round ==2:
vel_y=0.6
elif Round ==3:
vel_y=0.8
elif Round ==4:
vel_y=1.0
elif Round ==5:
vel_y=1.2
#mine number setting
#move the fish
bomb_y += vel_y
mine_y+=vel_yy