缺少1个需要位置参数棋盘游戏

时间:2017-01-16 22:01:58

标签: python-3.x user-interface

我正在尝试为我的连接四个桌面游戏创建GUI代码但是错误仍在继续,我不知道如何纠正。有人可以帮忙吗?错误: TypeError: init ()缺少1个必需的位置参数:' buttns_list'

代码:

def __init__(self):


    self.mw = tkinter.Tk()
    self.mw.title = ("Connect Four")

    self.rows = 6
    self.cols = 7
    self.buttons_2d_list = []
    for i in range (self.rows):
        self.rows = ['']*self.cols
        self.buttons_2d_list.append(self.rows)

    self.gboard = ConnectFourBoard()
    p1 = HumanPlayer("X")
    p2 = ComputerPlayer("O", self.buttns_list)

    self.players_1st = (p1, p2)
    self.currnt_player_index = 0
    self.winner = False

def clicked_btn(self, x, y):

    p = self.players_1st[self.currnt_player_index]

    button = self.buttons_2d_list[x][y]
    if button["text"] == "":
        button["text"] = p.get_player_symbol()

        self.gboard.MakeMove(x, y, p.get_player_symbol())

        winner = self.gboard.CheckForWin()

        is_full = self.gboard.FullBoard()

        if winner == True:

            win_message = ("Player %s is the winner!" %p.get_player_symbol())
            messagebox.showinfo("Winner Info", win_messge)
            self.mw.destroy()
            exit()

        elif is_full == True:
            messagebox.showinfo("Winner Info", "The game is a draw")
            self.mw.destroy()
            exit()
        else:
            pass

        if self.currnt_player_index == 1:
            self.currnt_player_index = 0
        else:
            self.currnt_player_index += 1

        p = self.players_1st[self.currnt_player_index]
        p.play()



import random

class ComputerPlayer(播放器):

def __init__(self, letter, buttns_list):
    Player.__init__(self, letter)
    self.buttons_2d_list = buttns_list

def play(self):
    pass

1 个答案:

答案 0 :(得分:1)

我不清楚其他代码到底应该传递给你的是什么,但你的 init 要求你有一封信,而你有一封buttns_list,你不应该这样做T:

def __init__(self, letter, buttns_list):

所以错误来自这一行:

p2 = ComputerPlayer("O")

或者:

1)如果您的ComputerPlayer类需要,则传入buttns_list

p2 = ComputerPlayer("O", self.buttons_2d_list)` # in GameGUI init

2)如果错误地添加它,请摆脱它:

class ComputerPlayer(Player):

    def __init__(self, letter):
        Player.__init__(self, letter)