Display message if we are dead

This commit is contained in:
Yohann D'ANELLO 2020-11-11 01:17:00 +01:00
parent 6e8cfdcb1a
commit 56ba9d186e
2 changed files with 11 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import curses
from .display import Display
from dungeonbattle.entities.player import Player
@ -9,6 +11,7 @@ class StatsDisplay(Display):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pad = self.newpad(self.rows, self.cols)
self.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
def update_player(self, p: Player) -> None:
self.player = p
@ -32,10 +35,13 @@ class StatsDisplay(Display):
for _ in range(self.width - len(string3) - 1):
string3 = string3 + " "
self.pad.addstr(2, 0, string3)
if self.player.dead:
self.pad.addstr(3, 0, "YOU ARE DEAD",
curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT
| self.color_pair(3))
def display(self) -> None:
self.pad.clear()
self.update_pad()
self.pad.refresh(0, 0, self.y, self.x,
2 + self.y,
self.width + self.x)
3 + self.y, self.width + self.x)

View File

@ -50,6 +50,9 @@ class Player(FightingEntity):
the player fights this entity.
It rewards some XP if it is dead.
"""
# Don't move if we are dead
if self.dead:
return False
for entity in self.map.entities:
if entity.y == y and entity.x == x and \
isinstance(entity, FightingEntity):