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


Python State.start_new方法代码示例

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


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

示例1: Application

# 需要导入模块: from models import State [as 别名]
# 或者: from models.State import start_new [as 别名]
class Application(Frame):

    """
    Application Main Class
    """

    def __init__(self, width=5, height=4):
        master = Tk()
        Frame.__init__(self, master)
        self.lock = False
        self.pack()
        self.width = width
        self.height = height
        self.master = master
        self.master.title('M N K %d %d %d' % (self.width, self.height, 4))
        self.master.resizable(width=FALSE, height=FALSE)
        self.master.geometry("%dx%d" %
                            (self.width * 100,
                             self.height * 100 + 100))
        self.generate_widgets()
        self.start()

    def start(self):
        """
        Start new Game with width, height
            Initial the State from the Game
            Build all the blocks one by one
            Pick weak robot as a default Robot
            Let the player play first as default
            Set the result label to 'Playing'
            Unlock the application
        """
        self.game = Game(self.width, self.height)
        self.state = State(self.game)
        # generate the blocks
        self.block = {}
        for k in self.state.board.keys():
            self.block[k] = Block(self, k)
        self.pick_weak_robot()
        self.player_first()
        self.result_label.config(text='Playing')
        self.lock = False

    def restart(self):
        """
        Restart the Game
            Reset the State
            Delete all painting on canvas
            Reset the result Label
            Unlock the application
        """
        self.state.start_new()
        for k in self.block.values():
            k.canvas.delete("all")
        self.result_label.config(text='Playing')
        self.lock = False

        if self.state.to_move == 'x':
            Robot(self, None).start()

    def pick_weak_robot(self):
        self.robot_level = 0
        self.btn_w.config(state='disabled')
        self.btn_m.config(state='normal')
        self.btn_s.config(state='normal')

    def pick_mid_robot(self):
        self.robot_level = 1
        self.btn_w.config(state='normal')
        self.btn_m.config(state='disabled')
        self.btn_s.config(state='normal')

    def pick_strong_robot(self):
        self.robot_level = 2
        self.btn_w.config(state='normal')
        self.btn_m.config(state='normal')
        self.btn_s.config(state='disabled')

    def player_first(self):
        self.btn_pf.config(state='disabled')
        self.btn_rf.config(state='normal')
        self.state = State(self.game, 'o')
        self.restart()

    def robot_first(self):
        self.btn_pf.config(state='normal')
        self.btn_rf.config(state='disabled')
        self.state = State(self.game, 'x')
        self.restart()

    def generate_widgets(self):
        # generate the buttons
        self.btn_pf = Button(
            self.master, text="PlayerFirst", command=self.player_first)
        self.btn_rf = Button(
            self.master, text="RobotFirst", command=self.robot_first)
        self.btn_w = Button(
            self.master, text="Weak", command=self.pick_weak_robot)
        self.btn_m = Button(
            self.master, text="Mid", command=self.pick_mid_robot)
#.........这里部分代码省略.........
开发者ID:BenThomas33,项目名称:practice,代码行数:103,代码来源:views.py


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