我正在开发一个应用程序,它使用一组变量从电报中读取消息输入,然后与用户一起开始游戏.所以我创建了一个代表游戏实例的类,每次聊天可以创建一个游戏:
class Battle:
def __init__(self, mainchat):
self.mainchat = mainchat
print('Instance of battle started on chat %s' % self.mainchat)
pcount = 0
team1 = []
team2 = []
p1 = ()
p2 = ()
p1score = 0
p2score = 0
battlechoicep1 = -1
battlechoicep2 = -1
Run Code Online (Sandbox Code Playgroud)
所以,一旦我收到消息,我就会根据用户输入启动一个战斗实例,例如
battle = Battle(chat_id)
battle.p1 = 'Paul'
battle.battlechoicep1 = 4
...
Run Code Online (Sandbox Code Playgroud)
这种方式现在一直很好,但每次我想重置战斗时,我都会通过一个函数执行此操作:
battle.pcount = 0
battle.team1 = []
battle.team2 = []
battle.p1 = ()
battle.p2 = ()
battle.p1score = 0
battle.p2score = 0
battle.battlechoicep1 = …Run Code Online (Sandbox Code Playgroud) python ×1