当前位置: 首页>>代码示例>>Python>>正文


Python Match.player_add方法代码示例

本文整理汇总了Python中match.Match.player_add方法的典型用法代码示例。如果您正苦于以下问题:Python Match.player_add方法的具体用法?Python Match.player_add怎么用?Python Match.player_add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在match.Match的用法示例。


在下文中一共展示了Match.player_add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: My_Boggle

# 需要导入模块: from match import Match [as 别名]
# 或者: from match.Match import player_add [as 别名]

#.........这里部分代码省略.........
            except:
                pass
        else:
            self._time_label.configure(text="%d" % self.remaining)
            self.remaining = self.remaining - 1
            self.after(1000, self.countdown)

    # function used to place the dice pictures to the display
    def add_dice_start(self):
        file_path = self.file
        for row in self._game.board:
            for letter in row:
                file = file_path + letter.lower() + '.gif'
                image = tk.PhotoImage(file=file)
                self.dice_start.append(image)

    def add_dice(self):
        for i in range(0, self._game.size ** 2):
            label = tk.Label(self._dice_frame, image=self.dice_start[i],
                             bd=1, bg="black")
            self.d_labels.append(label)

    # fn that defines the quit button
    def add_quit(self):
        quit_button = tk.Button(self._quit_frame, text='Quit',
                                command=self.quit)
        self._quit.append(quit_button)

    # fn used to place all the frames
    def start_game(self):
        # Top
        self._p1_score_frame.grid(row=1, column=10)
        self._cmp_score_frame.grid(row=1, column=0)
        # far left
        self._computer_text.grid(row=3, column=1)
        self._guess1_frame.grid(row=5, column=0)
        # middle
        self._dice_frame.grid(row=5, column=5)
        # right
        self._guess2_frame.grid(row=5, column=10)
        self._user_text.grid(row=1, column=1)
        # guess box
        self._user_frame.grid(row=10, column=5)
        # bottom middle
        self._quit_frame.grid(row=11, column=5)
        self._time_frame.grid(row=0, column=5)
        for i, button in enumerate(self._quit):
            button.grid(row=0, column=i)
        row = 0
        col = 0
        for i, label in enumerate(self.d_labels):
            if i % self._game.size == 0:
                row += 1
                col = 0
            label.grid(row=row, column=col)
            col += 1
        self.focus_set()

    # fn used by computer and player to add to the list of taken words
    def add_taken(self):
        words = self._game.valid
        if words:
            word = choice(self._game.valid)
            alt_word = choice(self._game.valid)
            if (self._game.difficulty == 1):
                if self._game.score(alt_word) < self._game.score(word):
                    word = alt_word
                    # easy setting assign the lesser value word
            if (self._game.difficulty == 2):
                if self._game.score(alt_word) > self._game.score(word):
                    word = alt_word
                    # easy setting assign the greater value word
            if self._game.player_add(self._game.player2, word):
                self.score_cmp.set(self._game.player2.get_score())
                word += '\n'
                self.insert_word(self._computer_text, word)
                self._computer_text.see(tk.END)
                # foe_tracker will hold ID of after fn
                self.foe_tracker = self.after(self.turn_delay, self.add_taken)
        else:
            self.remaining = 0
            return

    # fn used to collect user guesses
    def input(self):
        user_label = tk.Label(self._user_frame, text="Enter Guess:")
        user_label.grid()
        self.user_box.bind('<Return>', self.get_input)
        self.user_box.grid(row=0, column=1)

    # fn used to process user guesses
    def get_input(self, event):
        _ = event
        word = self.user_box.get()
        word = word.upper()
        self.user_box.delete(first=0, last=tk.END)
        if self._game.player_add(self._game.player1, word):
            word += '\n'
            self.insert_word(self._user_text, word)
            self.score_p1.set(self._game.player1.get_score())
开发者ID:Ragnok,项目名称:boggle,代码行数:104,代码来源:gui.py


注:本文中的match.Match.player_add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。