The first day of game development for the python version of "The Sheep and the Sheep"

Practical Teaching Course of Small Python Project "The Sheep and the Sheep"

1. Project development outline (primary)

Version 1.0: Basic Development

class

content

technology

first day

Base game map data

process oriented

the next day

mouse click and move

object oriented

third day

eliminate

Design Pattern: Singleton Pattern

fourth day

full game

Architecture: Model-View-ViewModel

fifth day

multi-layered blocks

data structure

(Computer PubMed Data Structure Course)

sixth day

multi-layered blocks

data structure

(Computer PubMed Data Structure Course)

2. Project development outline (intermediate, advanced)

Version 2.0: Game props

Technique: Design Patterns

Version 3.0: The stand-alone version is changed to an online multiplayer online game

Technology: Network programming, multiplayer battle

Version 4.0: JS rewritten, release applet

Version 5.0: Android programming, Apple ios programming, release APP

Version 6.0: Small programs, APPs, access to advertising alliances, and earn money by charging fees!

Version 7.0: Game props, access to payment interface, charge for props!

Version 8.0: Advanced implementation of multi-layer overlapping blocks

First day function description:

    The map data is drawn, including spaces.

First day screenshot:

Version 1.0, the first day source code:

import pygame

import random



#导入exit方法

from sys import exit



#定义函数

#  当用户点击关闭,关闭窗口

def handleEvent():

    global events

    for e in pygame.event.get():

        if e.type==pygame.QUIT:

            pygame.quit()

            sys.exit()

            

#地图初始化 2023.7.5 lyy

def gameMapInit():

    for i in range(9):

        for j in range(7):

            # 0 无效值;    1-6 有效值

            matrix[i][j]=random.randint(0, 6)



#- ---------------------------------------------------- main



#初始化pygame

pygame.init()



back=pygame.image.load('images/background.png')

cardBox=pygame.image.load('images/box.png')



c1=pygame.image.load('images/card1.png')

c2=pygame.image.load('images/card2.png')

c3=pygame.image.load('images/card3.png')

c4=pygame.image.load('images/card4.png')

c5=pygame.image.load('images/card5.png')

c6=pygame.image.load('images/card6.png')



cardAll=[c1,c2,c3,c4,c5,c6]



#设置窗口大小

canvas=pygame.display.set_mode((400,700))



#数据 MVVM模式

# 纯数据  MODEL

matrix = [[0 for i in range(8)] for i in range(10)]



#设置窗口标题

pygame.display.set_caption('羊了个羊')



gameMapInit()



print(matrix)





#循环语句

#重复绘制画面,重复检测用户是否点击了关闭按钮

while True:

    #绘制背景

    canvas.blit(back,(0,0))

    #绘制卡牌空槽

    canvas.blit(cardBox,(20,550))

    #循环语句 输出多行多列图片

    x=25

    y=50

    for i in range(9):

        x=25

        for j in range(7):

                    card_id= matrix[i][j]

                    if card_id!=0:

                        canvas.blit(cardAll[ card_id-1 ],(x,y))

                    x=x+50

        y=y+50

    #调用函数,当用户点击关闭,关闭窗口

    handleEvent()

    #刷新画面

    pygame.display.update()

    

Guess you like

Origin blog.csdn.net/weixin_42644456/article/details/132166370