本文整理匯總了Python中graphics.Graphics.play方法的典型用法代碼示例。如果您正苦於以下問題:Python Graphics.play方法的具體用法?Python Graphics.play怎麽用?Python Graphics.play使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graphics.Graphics
的用法示例。
在下文中一共展示了Graphics.play方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from graphics import Graphics [as 別名]
# 或者: from graphics.Graphics import play [as 別名]
class Hangman:
'''
This class provides the context for the
graphics and logic modules, as well as
handling input, menus, events and
resources.
The original intent was to let it serve
as a model-view controller, where Logic
represented the model and Graphics the
main view.
'''
def __init__(self):
'''
Initializes window, canvas, gameplay options and menus,
loads resources (settings, images, dictionaries)
and sets up debugging.
'''
# Window
self.size = Size(650, 650)
self.root = self.createWindow(self.size)
self.icon = self.loadIcon('icon.png')
# Internal settings
self.validState = False # Not ready to accept guesses
self.DEBUG = tk.BooleanVar(value=False) # Print debug messages
self.VERBOSE = tk.BooleanVar(value=True) # Print verbose debug messages
# Logging
self.messages = []
self.logger = Logger('Hangman')
# Resources
self.dictData = self.loadDictionaries('data/dicts/dictionaries.json')
self.dictNames = [name for name in self.dictData.keys()]
self.flags = self.loadFlags()
# Gameplay settings
self.restartDelay = 1500 # Delay before new round begins (ms)
self.revealWhenLost = False # Reveal the word when the game is lost
# TODO: Save reference to current dict (?)
self.DICT = tk.StringVar(value=choice(self.dictNames)) # Select random dictionary
self.characterSet = self.dictData[self.DICT.get()]['characters'] # TODO: Make this dictionary-dependent
# Menus
self.menubar = self.createMenus()
# Events
self.bindEvents()
# Game play
self.graphics = Graphics(self.root, *self.size, characterSet=self.characterSet) # Renderer
self.logic = Logic(self.graphics.chances) # Logic
self.wordFeed = self.createWordFeed(self.DICT.get()) # Provides a stream of words and hints
self.chances = self.graphics.chances # Initial number of chances for each round
self.word = None # Initialized later on
self.hint = None # Initialized later on
# Audio
self.effects = self.loadAudio()
def play(self):
''' Starts the game '''
self.restart()
self.root.mainloop()
def createWindow(self, size):
''' As per the title '''
root = tk.Tk()
root.resizable(width=False, height=False)
root.title('Hangman')
return root
def createMenus(self):
''' As per the title '''
# TODO: Nested dict or JSON menu definition (?)
# TODO: Desperately needs a clean-up (...)
menubar = tk.Menu(self.root)
# New game
menubar.add_command(label='New', command=self.restart)
#.........這裏部分代碼省略.........