我正在编写一个程序,它是石头剪刀布游戏变体的模拟游戏。在我的主函数中,我正在输出一个接口,然后尝试调用其中定义的一个方法,该方法充当 switch 语句。我得到:“makeSel() 缺少 1 个必需的位置参数:'self'” TypeErrors 我已经在网上搜索了任何提示,但找不到任何有帮助的提示。我试图将“makeSel()”更改为“Main.makeSel()”,但它只是让我知道 main 是未定义的。
class Main:
def makeSel(self):
selection = input()
if(selection == 1):
return StupidBot('StupidBot')
elif(selection == 2):
return RandomBot('RandomBot')
elif(selection == 3):
return IterativeBot('IterativeBot')
elif(selection == 4):
return LastPlayBot('LastPlayBot')
elif(selection == 5):
return MyBot('MyBot')
elif(selection == 6):
return HumanPlayer('HumanPlayer')
else:
print('Invalid selection, please try again. Enter 1, 2, 3, 4, 5, or 6')
makeSel()
print('')
print('Welcome to my Rock-Paper-Scissors-Lizard-Spock game!')
print('')
print('Please select two players, enter 1, 2, 3, 4, 5, or 6')
print(' (1) -> StupidBot')
print(' (2) -> RandomBot')
print(' (3) -> IterativeBot')
print(' (4) -> LastPlayBot')
print(' (5) -> MyBot')
print(' (6) -> HumanPlayer')
p1 = makeSel()
p2 = makeSel()
我希望有人能够对我遇到的问题有所了解。