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
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
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
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