Make day 15 viz prettier
This commit is contained in:
parent
6acee8422d
commit
1c227f6906
1 changed files with 12 additions and 16 deletions
|
@ -14,7 +14,7 @@ class Elf:
|
|||
self.targeted = False
|
||||
|
||||
def __repr__(self):
|
||||
return "E"
|
||||
return "\033[32mE\033[0m"
|
||||
|
||||
|
||||
class Goblin:
|
||||
|
@ -28,7 +28,7 @@ class Goblin:
|
|||
self.targeted = False
|
||||
|
||||
def __repr__(self):
|
||||
return "G"
|
||||
return "\033[31mG\033[0m"
|
||||
|
||||
|
||||
Elf.enemy = Goblin
|
||||
|
@ -41,7 +41,7 @@ class Wall:
|
|||
self.targeted = False
|
||||
|
||||
def __repr__(self):
|
||||
return "#"
|
||||
return "\u2588"
|
||||
|
||||
|
||||
class Empty:
|
||||
|
@ -51,7 +51,7 @@ class Empty:
|
|||
self.targeted = False
|
||||
|
||||
def __repr__(self):
|
||||
return "." if not self.targeted else "\033[33m?\033[0m"
|
||||
return " " if not self.targeted else "\033[33m?\033[0m"
|
||||
|
||||
|
||||
NEIGHBORS = [(0, -1), (-1, 0), (1, 0), (0, 1)]
|
||||
|
@ -121,10 +121,6 @@ def find_closest(field, pos, targets):
|
|||
|
||||
|
||||
def move(field, x, y, value):
|
||||
for row in field:
|
||||
for col in row:
|
||||
col.targeted = False
|
||||
|
||||
targets = []
|
||||
for tx, ty in value.enemy.locations:
|
||||
targets.extend([(tx + dx, ty + dy) for dx, dy in NEIGHBORS])
|
||||
|
@ -132,9 +128,6 @@ def move(field, x, y, value):
|
|||
if not targets:
|
||||
raise StopIteration
|
||||
|
||||
for tx, ty in targets:
|
||||
field[ty][tx].targeted = True
|
||||
|
||||
closest = find_closest(field, (x, y), targets)
|
||||
# print_field(field, highlight=(x, y), path=closest)
|
||||
# time.sleep(0.3)
|
||||
|
@ -176,8 +169,9 @@ def attack(field, x, y, value):
|
|||
|
||||
|
||||
def print_field(field, steps=None, highlight=None, path=None):
|
||||
if steps is not None:
|
||||
print(f"round={steps}")
|
||||
print("\033[2J\033[;HElf attack power:", Elf.power)
|
||||
# if steps is not None:
|
||||
# print(f"round={steps}")
|
||||
for y, row in enumerate(field):
|
||||
units = []
|
||||
for x, value in enumerate(row):
|
||||
|
@ -194,10 +188,11 @@ def print_field(field, steps=None, highlight=None, path=None):
|
|||
etc = sorted(units, key=lambda unit: (str(unit), unit.health))
|
||||
print(" ", ", ".join(f"{x}({x.health})" for x in etc))
|
||||
print()
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
def step(field, steps):
|
||||
# print_field(field, steps)
|
||||
print_field(field, steps)
|
||||
seen_units = set()
|
||||
for y, row in enumerate(field):
|
||||
for x, value in enumerate(row):
|
||||
|
@ -235,8 +230,9 @@ def main():
|
|||
while True:
|
||||
main()
|
||||
if Elf.deaths == 0:
|
||||
print("yay")
|
||||
print("No elves died! :D")
|
||||
break
|
||||
|
||||
Elf.power += 1
|
||||
print("oh no :(, trying", Elf.power)
|
||||
print(f"{Elf.deaths} elves died, trying power={Elf.power}")
|
||||
time.sleep(4)
|
||||
|
|
Loading…
Reference in a new issue