Skip to content

Instantly share code, notes, and snippets.

@horstjens
Last active June 10, 2023 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horstjens/b21a578e7d57c045d285f14b4c550c5d to your computer and use it in GitHub Desktop.
Save horstjens/b21a578e7d57c045d285f14b4c550c5d to your computer and use it in GitHub Desktop.
import os
import time
text_schlüssel = """
"""
text_türe = """
"""
text_wand = """
_______ __ __ _______ ______ _______ _______
| _ || | | || _ | | | | _ || |
| |_| || | | || |_| | | _ || |_| || _____|
| || |_| || | | | | || || |_____
| || || | | |_| || ||_____ |
| _ || || _ | | || _ | _____| |
|__| |__||_______||__| |__| |______| |__| |__||_______|
_ _ _______ ______ _______ ___ __ _ _______
| | _ | || _ || _ | | || | | | | || |
| || || || |_| || | || | ___|| | | |_| || ___|
| || || |_|| | |___ | | | || |___
| || || __ | | ___|| | | _ || ___|
| _ || _ || | || | |___ | | | | | || |___
|__| |__||__| |__||___| || |_______||___| |_| |__||_______|
_ _ _______ __ _ ______ __
| | _ | || _ || | | || | | |
| || || || |_| || |_| || _ | | |
| || || || | | | | |
| || || _ || |_| | |__|
| _ || _ || | | || | __
|__| |__||__| |__||_| |__||______| |__|
"""
dungeon1 = """
############################################
#..................................|.✪.|..>#
#.......§..........................#...#####
#..................€€..............#########
######.....................................#
#€€§€|.....................................#
############################################
"""
dungeon2 = """
##################################################
#.........................................<......#
#................................................#
#................................................#
#................................................#
#................................................#
#................................................#
#................................................#
#................................................#
#................................................#
#................................................#
##################################################
"""
hero = "@"
keys = 0
gold = 0
hero_hp = 100
hx, hy = 1,1
level = 1
dungeons = [None,]
command_text = ""
for d in (dungeon1, dungeon2):
dungeon = [list(line) for line in d.splitlines()
if len(line) >0]
dungeons.append(dungeon)
text = ""
while hero_hp > 0:
if len(command_text) > 0:
time.sleep(1)
os.system("clear")
dungeon = dungeons[level]
for y, line in enumerate(dungeon):
for x, char in enumerate(line):
if x == hx and y == hy:
print(hero, end="")
else:
print(char, end="")
print()
print(text)
status = f"hp: {hero_hp} §: {keys} €: {gold} level: {level} "
while len(command_text.strip()) == 0:
command_text = input(status + ">>>")
text = ""
dx, dy = 0, 0
if command_text.lower() in ("exit","quit","bye"):
break
elif command_text.lower() == "down":
if dungeon[hy][hx] == ">":
level += 1
else:
text += "find a stair to descend"
elif command_text.lower() == "up":
if dungeon[hy][hx] == "<":
level -= 1
else:
text += "find a stair to ascend"
else:
command = command_text[0]
command_text = command_text[1:]
if command == "a":
dx = -1
if command == "d":
dx = 1
if command == "w":
dy = -1
if command == "s":
dy = 1
# ----- prüfen ----
if dungeon[hy+dy][hx+dx] == "#":
print(text_wand)
input("press ENTER")
text += "Ouch, you hit a wall."
hero_hp -= 1
dx, dy = 0, 0
# ---- door ? ----
if dungeon[hy+dy][hx+dx] == "|":
if keys > 0:
text += "You open the door using up one key. "
keys -= 1
dungeon[hy+dy][hx+dx] = "."
dx, dy = 0, 0
else:
text += "Ouch, you hit a door"
hero_hp -= 1
dx, dy = 0, 0
#------ händler ? ------
if dungeon[hy+dy][hx+dx] == "✪":
dx, dy = 0, 0
text += "You find a trader. "
if gold >= 5:
text += "The trader sells you a key"
gold -= 5
keys += 1
else:
text += "Bring me 5 gold for a key"
# -----------------------
hx += dx
hy += dy
# ---- pick up items ----
tile = dungeon[hy][hx]
if tile == "§":
text += "You find a key."
keys += 1
dungeon[hy][hx] = "."
if tile == "€":
text += "You find gold!"
gold += 1
dungeon[hy][hx] = "."
if tile == ">":
text += "type 'down' to decend the stairs"
if tile == "<":
text += "type 'up' to ascend the stairs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment