我试图从另一个类中调用一个类中的函数。这是我的代码:
import os
class GameRoom():
msgLine1 = ""
msgLine2 = ""
msgLine3 = ""
msgLine4 = ""
msgLine5 = ""
def GameStatus(self):
while True:
os.system('cls')
print self.msgLine1
print self.msgLine2
print self.msgLine3
print self.msgLine4
print self.msgLine5 + "\n"
print "Do what?\n"
userDecision = raw_input()
if userDecision.upper() == "GO":
Player().Go()
break
else:
self.CycleMessages("That's not a valid choice!")
def CycleMessages(self,newMsg="error"):
self.msgLine5 = self.msgLine4
self.msgLine4 = self.msgLine3
self.msgLine3 = self.msgLine2
self.msgLine2 = self.msgLine1
self.msgLine1 = newMsg
class Player():
def Go(self):
GameRoom().CycleMessages("Player goes.")
GameRoom().GameStatus()
def main():
GameRoom().GameStatus()
if __name__ == '__main__':
main()
当我CycleMessages
通过自己打电话时,这些行填满了“这不是一个有效的选择!” 通常,就像他们应该的那样。当我CycleMessages
从Player
课堂上打电话时,所有的行都清除了,而不是显示“玩家去。”。“错误”也不显示。
我想要“玩家去”。当我打电话时出现Player().Go()
。我该怎么做呢?我很感激任何帮助!