命名 asciimatics 场景

问题描述

我正在努力制作一款有战斗力的游戏。为此,我需要遍历某个场景,直到玩家或怪物的健康值为 0 或更低。所以我有变量设置为在变量达到 0 后播放下一个场景(这是我想要循环的同一场景)。但问题是我不知道如何命名场景。这是我的代码

def whack(self,sound):
    global PL,KL,SL,BL
    x,y = self._path.next_pos()
    if self.overlaps(PLAYER,use_new_pos=True):
        PL += 1
        raise NextScene
    if self.overlaps(SMOLFUNGI,use_new_pos=True):
        SL -= 1
        raise NextScene('the scene that is looping')
    else:
        self._scene.add_effect(Print(
            self._screen,SpeechBubble(sound),y,x,clear=True,delete_count=50))
    if PL < 1:
        raise StopApplication
    if SL < 1:
        raise NextScene

# Scene 7.
path = Path()
path.jump_to(podium[0],podium[1])

effects = [
    Print(screen,Box(screen.width,screen.height,uni=screen.unicode_aware),start_frame=1),Print(screen,StaticRenderer(images=Grass),x=screen.width - 140,y=screen.height - 6,colour=Screen.COLOUR_WHITE),SMOLFUNGI,PLAYER,cross_hairs,]
scenes.append(Scene(effects,-1))

解决方法

它只是 Scene 对象上的一个参数。有关如何使用它们的说明,请阅读文档 (https://asciimatics.readthedocs.io/en/stable/widgets.html#exceptions) 中的相关部分。

关键示例如下。

# Given this scene list...
scenes = [
    Scene([ListView(screen,contacts)],-1,name="Main"),Scene([ContactView(screen,name="Edit Contact")
]
screen.play(scenes)

# You can use this code to move back to the first scene at any time...
raise NextScene("Main")