让我先说一下,我对编程非常非常新手。我已经做了大约一个星期,成功地制作了计算器和其他初学者的工具,并且一直在开发我的第一个真正的“项目”,这是一个基于文本的冒险游戏。目前我的问题是,我无法为自己设计一个非常简单的生命值系统,并希望得到您可能有的任何指针。
我已经多次重写了它的代码,但以下是我一直在使用的基本框架:
我已经多次重写了它的代码,但以下是我一直在使用的基本框架:
def healthSystem(enemy_atk = 0): # Called at the beginning of every game screen.
watermark() # A function that prints the game title and other things at the top of every screen
max_health = 10 # Player max health
no_health = 0 # Player dies at this threshold
modifier = enemy_atk # An enemy attack roll is taken from another function and stored here
current_health = max_health - modifier # Calculating the new health
print("+" * current_health) # Prints the new health to the screen, every 1 health is represented with a "+"
print()
这个程序非常简单,可以在第一个游戏屏幕上工作。然而,当你进入下一个游戏屏幕时,所有内容都会重新计算并且健康值会每次重新绘制到屏幕上,因此每个屏幕上的健康值都不同。
这需要调用类吗?我还没有使用过类,并且看到一些使用类的示例,但是我希望在这个项目中仅使用函数。谢谢大家的帮助。
def healthSystem(enemy_atk = 0, current_health=10):
,并在函数内部修改max_health=current_health
。无论在哪里调用这个函数,都要将当前的生命值作为参数传递给它。 - sahasrara62