예제 #1
0
    def strategy(self, score, opp_score):
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) + ' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(
            name(self.who), result)
        self.switch()
        return result
예제 #2
0
    def strategy(self, score, opp_score):
        """Стратегия с GUI-хуком. Эта стратегия передаётся в функцию play модуля
        hog. Стратегия ожидает ввода числа бросков, его проверки и возврат этого
        числа. Игровая информация также обновляется.

        score     — очки игрока
        opp_score — очки противника
        """
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = 'Ходит {0}. Число костей:'.format(name(self.who))
        status = self.status_label.text
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} использовал {} костей (кость).'.format(name(self.who),
                                                               result)
        self.switch()
        return result
예제 #3
0
    def strategy(self, score, opp_score):
        """A strategy with a hook to the GUI. This strategy gets
        passed into the PLAY function from the HOG module. At its
        core, the strategy waits until a number of rolls has been
        verified, then returns that number. Game information is
        updated as well.

        score     -- player's score
        opp_score -- opponent's score
        """
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) + ' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(
            name(self.who), result)
        self.switch()
        return result
예제 #4
0
파일: hog_gui.py 프로젝트: yujianyu/CS61A
    def strategy(self, score, opp_score):
        """A strategy with a hook to the GUI. This strategy gets
        passed into the PLAY function from the HOG module. At its
        core, the strategy waits until a number of rolls has been
        verified, then returns that number. Game information is
        updated as well.

        score     -- player's score
        opp_score -- opponent's score
        """
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) +' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(name(self.who),
                                                               result)
        self.switch()
        return result