用python写一个回合制小游戏
时间: 2023-05-19 13:06:08 浏览: 87
好的,我可以为您提供一个简单的回合制小游戏的代码,您可以在Python中使用它:
```
import random
player_health = 100
enemy_health = 100
while player_health > 0 and enemy_health > 0:
print("Player health:", player_health)
print("Enemy health:", enemy_health)
print("1. Attack")
print("2. Heal")
choice = input("Enter your choice: ")
if choice == "1":
damage = random.randint(10, 20)
enemy_health -= damage
print("You attacked and dealt", damage, "damage!")
elif choice == "2":
heal = random.randint(10, 20)
player_health += heal
print("You healed and gained", heal, "health!")
else:
print("Invalid choice!")
continue
enemy_damage = random.randint(5, 15)
player_health -= enemy_damage
print("The enemy attacked and dealt", enemy_damage, "damage!")
if player_health > 0:
print("You won!")
else:
print("You lost!")
```
这个小游戏有两个角色,玩家和敌人,每个角色都有100点生命值。在每个回合中,玩家可以选择攻击或治疗。攻击会造成10到20点伤害,治疗会恢复10到20点生命值。敌人会在每个回合中攻击玩家,造成5到15点伤害。游戏将继续进行,直到玩家或敌人的生命值降至零。如果玩家生存下来,他将获胜,否则他将失败。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)