本文整理汇总了Python中engine.Engine.change_turn方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.change_turn方法的具体用法?Python Engine.change_turn怎么用?Python Engine.change_turn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.change_turn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_turn
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import change_turn [as 别名]
def test_change_turn(self):
game = Engine()
turn = game.turn
game.change_turn()
new_turn = game.turn
self.assertTrue(all(map(isinstance, (turn, new_turn), (Player2Piece, Player1Piece))))
示例2: __init__
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import change_turn [as 别名]
class Application:
"""GUI of the game."""
def __init__(self):
"""Initialize the window and the GUI elements."""
self.game = False
self.show_valid_positions = False
self.window = Tk()
self.window.title("MonOthello")
self.window.wm_maxsize(width="400", height="400")
self.window.wm_minsize(width="400", height="400")
self.create_elements()
self.window.mainloop()
def create_elements(self):
self.create_menu()
self.create_board()
self.create_options()
def create_menu(self):
menu = Menu(self.window)
game = Menu(menu, tearoff=0)
game.add_command(label="New", command=self.create_game, underline=0)
game.add_command(label="Quit", command=self.bye, underline=0)
menu.add_cascade(label="Game", menu=game, underline=0)
settings = Menu(menu, tearoff=0)
settings.add_checkbutton(label="Show valid positions",
variable=self.show_valid_positions,
command=self.toggle_show_valid_positions,
underline=0)
menu.add_cascade(label="Settings", menu=settings, underline=0)
help = Menu(menu, tearoff=0)
help.add_command(label="About", command=self.show_credits, underline=0)
menu.add_cascade(label="Help", menu=help, underline=0)
self.window.config(menu=menu)
def create_board(self):
self.score = Label(self.window)
self.score.pack()
self.board = dict()
back = Frame(self.window)
back.pack(fill=BOTH, expand=1)
for row in range(8):
frame = Frame(back)
frame.pack(fill=BOTH, expand=1)
for column in range(8):
button = Button(frame,
state=DISABLED,
command=lambda position=(row, column): self.play(position))
button["bg"] = "gray"
button.pack(side=LEFT, fill=BOTH, expand=1)
self.board.update({(row, column): button})
def create_options(self):
pass_turn = Button(self.window, text="Pass", command=self.pass_turn)
pass_turn.pack(side=RIGHT)
self.status = Label(self.window)
self.update_status("Welcome to MonOthello!")
self.status.pack(side=LEFT)
def create_game(self):
message="Are you sure you want to restart?"
if self.game and \
not tkMessageBox.askyesno(title="New", message=message):
return
self.game = Engine()
self.update_board()
message = "Let's play! Now it's the %s's turn." % (self.game.turn.name,)
self.update_status(message)
def toggle_show_valid_positions(self):
self.show_valid_positions = not self.show_valid_positions
if self.game:
self.update_board()
def pass_turn(self):
if not self.game:
return
self.game.change_turn()
self.update_board()
message = "%s's turn." % (self.game.turn.name,)
self.update_status(message)
def show_credits(self):
message = "MonOthello\nv.: 1.0"
tkMessageBox.showinfo(title="About", message=message)
def bye(self):
if tkMessageBox.askyesno(title="Quit", message="Really quit?"):
#.........这里部分代码省略.........