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


Python Visualizer.update_age方法代码示例

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


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

示例1: __init__

# 需要导入模块: from visualizer import Visualizer [as 别名]
# 或者: from visualizer.Visualizer import update_age [as 别名]
class Manager:
	"""Frame of options to manage a monster."""

	def __init__(self, name, master, total_var):
		self.root = LabelFrame(master, text = name)
		self.visualizer = Visualizer(name, self.root)
		self.monster = Monster(name)
		self.stats = Stat_Tracker()

		self.total_var = total_var
		self.total_var.set(total_var.get() + 1)

		self.visualizer.monster_image.grid(row = 0, column = 6, rowspan = 3)
		self.visualizer.mood_image.grid(row = 0, column = 7, rowspan = 3)

		# controls whether the button's perform their action, for use when
		# a monster is dead or a minigame is playing
		self.button_bool = True

		########## age ##################################
		self.age_label = Label(self.root, text = "Age:  ")
		self.age_label.grid(row = 0, column = 2)
		
		self.age_state = StringVar()
		self.update_age()
		Label(self.root, textvariable = self.age_state).grid(row = 0, column = 3)

		########### mood ############################################
		self.mood_label = Label(self.root, text = "Mood:  ")
		self.mood_label.grid(row = 0, column = 0)

		self.mood_state = StringVar()
		self.update_mood()
		Label(self.root, textvariable = self.mood_state).grid(row = 0, column = 1)

		######### hunger ############################################
		self.hunger_label = Label(self.root, text = "Hunger:  ")
		self.hunger_label.grid(row = 1, column = 0)

		self.hunger_state = StringVar()
		self.update_hunger()
		Label(self.root, textvariable = self.hunger_state).grid(row = 1, column = 1)

		self.hunger_button = Button(self.root, text = "Feed", command = self.feed)
		self.hunger_button.grid(row = 1, column = 2)

		######## sleepiness ############################################
		self.sleep_label = Label(self.root, text = "Sleepiness:  ")
		self.sleep_label.grid(row = 2, column = 0)

		self.sleep_state = StringVar()
		self.update_sleepiness()
		Label(self.root, textvariable = self.sleep_state).grid(row = 2, column = 1)

		self.sleep_button = Button(self.root, text = "Nap", command = self.nap)
		self.sleep_button.grid(row = 2, column = 2)

		######### boredom ############################################
		self.boredom_label = Label(self.root, text = "Boredom:  ")
		self.boredom_label.grid(row = 1, column = 3)

		self.boredom_state = StringVar()
		self.update_boredom()
		Label(self.root, textvariable = self.boredom_state).grid(row = 1, column = 4)

		self.boredom_button = Button(self.root, text = "Play", command = self.play)
		self.boredom_button.grid(row = 1, column = 5)

		######### dirtiness ############################################
		self.dirt_label = Label(self.root, text = "Dirtiness:  ")
		self.dirt_label.grid(row = 2, column = 3)

		self.dirt_state = StringVar()
		self.update_dirtiness()
		Label(self.root, textvariable = self.dirt_state).grid(row = 2, column = 4)

		self.dirt_button = Button(self.root, text = "Clean", command = self.clean)
		self.dirt_button.grid(row = 2, column = 5)
		
		self.root.pack()

	def update_hunger(self):
		"""Updates the hunger label by generating a string from the monster's hunger field."""
		value = self.monster.hunger	
		if value >= 2 * Monster.HUNGRY:
			text = "High"
		elif value >= Monster.HUNGRY:
			text = "Medium"
		else:
			text = "Low"
		self.hunger_state.set(text)

	def feed(self):
		"""Feeds the monster."""
		if self.button_bool:
			self.stats.update_stats("feed", self.monster.mood, self.monster.age)
			self.monster.feed()
			self.update_all()

	def update_sleepiness(self):
#.........这里部分代码省略.........
开发者ID:Cjreynol,项目名称:Python-Monster-Zoo,代码行数:103,代码来源:manager.py


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