游戏介绍: 你是一名探险家,正在探索远古文明的遗迹。你需要解决谜题和战胜敌人,以获取宝藏和知识。
游戏规则:
- 游戏地图是一个迷宫,你需要移动角色来探索地图。
- 地图上有门、陷阱、宝藏和敌人。
- 你可以使用指令来移动角色,例如north(北), south(南), east(东), west(西)。
- 遇到敌人时,你可以选择战斗或逃跑。战斗需要一定的技能和健康值。
- 解决谜题可以解开某些门并获得宝藏。
- 游戏有时间限制,如果时间到了,游戏结束。
代码:
import random
# 游戏地图
map = [[1, 0, 0, 0, 0],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 0, 0, 0, 2]]
# 角色的初始位置
player_pos = (0, 0)
# 游戏时间限制
time_limit = 60
# 角色的健康值
health = 100
# 游戏是否结束的标志
game_over = False
# 移动角色
def move(direction):
global player_pos, health
if direction == "north":
new_pos = (player_pos[0] - 1, player_pos[1])
elif direction == "south":
new_pos = (player_pos[0] + 1, player_pos[1])
elif direction == "east":
new_pos = (player_pos[0], player_pos[1] + 1)
elif direction == "west":
new_pos = (player_pos[0], player_pos[1] - 1)
else:
print("无效的移动方向")
return
# 检查移动是否有效
if new_pos[0] >= 0 and new_pos[0] < len(map) and new_pos[1] >= 0 and new_pos[1] < len(map[0]):
player_pos = new_pos
# 检查目标位置是否有敌人
if map[player_pos[0]][player_pos[1]] == 1:
# 进行战斗
fight()
# 检查目标位置是否有宝藏
elif map[player_pos[0]][player_pos[1]] == 2:
# 获得宝藏
get_treasure()
else:
print("无效的移动")
# 战斗
def fight():
global health
# 模拟战斗
enemy_hp = random.randint(50, 100)
while health > 0 and enemy_hp > 0:
player_damage = random.randint(10, 20)
enemy_damage = random.randint(5, 15)
enemy_hp -= player_damage
health -= enemy_damage
# 判断战斗结果
if health <= 0:
print("你被敌人击败了,游戏结束。")
end_game()
else:
print("你战胜了敌人,继续探索吧。")
# 获得宝藏
def get_treasure():
print("恭喜你找到了宝藏,游戏胜利!")
end_game()
# 游戏结束
def end_game():
global game_over
game_over = True
# 游戏开始
def play_game():
global time_limit
print("游戏开始!你有{}分钟的时间来探索远古文明的遗迹。".format(time_limit))
while not game_over and time_limit > 0:
print("你当前的位置:{}".format(player_pos))
print("你的健康值:{}".format(health))
command = input("请输入移动方向:")
move(command.lower())
time_limit -= 1
if time_limit <= 0:
print("时间已经用尽,游戏结束。")
# 开始游戏
play_game()