生命计数器不断复位

时间:2019-12-26 22:14:17

标签: python python-3.x pygame

我最近进入pygame,遇到了麻烦。我的生活计数器在我的程序中不起作用。

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-12-26 21:56:42 GMT; 12min ago
     Docs: https://httpd.apache.org/docs/2.4/
  Process: 23065 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 23083 (apache2)
    Tasks: 6 (limit: 4915)
   Memory: 10.2M
   CGroup: /system.slice/apache2.service
           ├─23083 /usr/sbin/apache2 -k start
           ├─23092 /usr/sbin/apache2 -k start
           ├─23093 /usr/sbin/apache2 -k start
           ├─23095 /usr/sbin/apache2 -k start
           ├─23096 /usr/sbin/apache2 -k start
           └─23098 /usr/sbin/apache2 -k start

Dec 26 21:56:42 arcm-server systemd[1]: Starting The Apache HTTP Server...
Dec 26 21:56:42 arcm-server systemd[1]: Started The Apache HTTP Server.

我有一条陈述,当玩家死亡时,生命计数器减少一。但是,寿命计数器似乎已重置为3(原始量)。我必须更改些什么来固定寿命计数器?谢谢!

2 个答案:

答案 0 :(得分:0)

玩家死亡时,您致电dead()

dead()呼叫message_display()

message_display()再次调用__init__()(即使它已经在运行)。

__init__()的开头是myLives = 3

如果您不希望玩家死亡时将变量重置为3,则不要继续调用__init__,因为该函数的开头始终会将myLives重置为3。

答案 1 :(得分:0)

dead()调用message_display(),它再次调用您的 init ()。在每个 init ()调用中,您都再次设置myLives = 3。