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


Python Graphics.play方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:SwiftsNamesake,项目名称:Hangman,代码行数:103,代码来源:main.py


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