Design of eating game based on Python

Contents
1. Design purpose 3
2. Design tasks and requirements 3
III. Overall Design 4
Four. Design realization 6
(1) Final realization result: 6
(2) Realization result evaluation 7
V. Detailed design 7
(1) pygame event 7
(2) mouse event 8
(3) polling keyboard 8
(4) game end processing 9 (
5) game level setting and difficulty setting 9
(6) introduction during the game 10
six .Debugging and Testing 12
(1) Exception Handling 12
(2) Debugging 12
VII. Design Summary 12
The specific purpose of this course design:
(1) On the basis of a comprehensive understanding of the history, current situation and development trend of Python technology, systematically master the basic concepts of Python, Programming thinking and programming technology, with proficient Python programming skills and object-oriented software design technical thinking.
(2) Understand the general steps of Python design through the overall framework to page design and then to code implementation, and master the design ideas of Python proficiently.
(3) This topic mainly trains logical thinking and Python grammar, masters the basic logic of code writing from big to small, from overall to module, and can draw inferences about future designs to form logical thinking.
two. Design tasks and requirements
Course design teaching tasks and requirements:
The main task of this course design is to use Python as the development language to complete the development of a program project with a scale of about 100~300 lines. Refer to Appendix 1 for design reference topics.
The basic requirement of course design is to strictly and standardly complete relevant documents at each stage of course design, such as overall plan report, detailed design report, function description, data structure description, algorithm description, program design block diagram, legend and source program, etc. . It is required that the written document has a reasonable structure, complete content, and clear description. The source code of the program should have detailed comments, and the readability is good. Higher requirements are: creative, beautiful system interface.
The specific tasks and requirements of this course design:
(1) The page is perfect and the logic is clear.
(2) Code writing should be as concise as possible with high readability.
(3) You can choose development platforms such as PyCharm and Python IDLE to improve development efficiency, and master one or more integrated development environments as much as possible through data review and learning.
(4) Jointly complete the connection of the code, the realization of the overall framework and logic of the game. The division of labor writes the course design report, which includes six parts in total: design purpose, design requirements, overall design, detailed design, debugging and testing, and design summary.

# -*-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

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/newlw/article/details/130698922