Bootstrap

python植物大战僵尸源码教学

大家好,给大家分享一下一个有趣的事情,很多人还不知道这一点。下面详细解释一下。现在让我们来看看!

大家好,我是梦执,对梦执着。希望能和大家共同进步!

下面给大家带来python实现植物大战僵尸的的源码分享,只含有冒险模式python 安装后怎么用

游戏截图

d7481ff08c634f8684f4a3e0a2677a5e.png

75b735af0c924d02862c9143b89f1d01.png
87d3d56a25e546bb8dcb9e9285fb77cf.png

动态演示

3be67b68cae34dc2b12f56eafd0fec07.gif#pic_center

源码分享

state/tool.py

import os
import json
from abc import abstractmethod
import pygame as pg
from . import constants as c

class State():
    def __init__(self):
        self.start_time = 0.0
        self.current_time = 0.0
        self.done = False
        self.next = None
        self.persist = {}
    
    @abstractmethod
    def startup(self, current_time, persist):
        '''abstract method'''

    def cleanup(self):
        self.done = False
        return self.persist
    
    @abstractmethod
    def update(self, surface, keys, current_time):
        '''abstract method'''

class Control():
    def __init__(self):
        self.screen = pg.display.get_surface()
        self.done = False
        self.clock = pg.time.Clock()
        self.fps = 60
        self.keys = pg.key.get_pressed()
        self.mouse_pos = None
        self.mouse_click = [False, False]  # value:[left mouse click, right mouse click]
        self.current_time = 0.0
        self.state_dict = {}
        self.state_name = None
;