Reworked graphics to make it more modular
This commit is contained in:
@ -1,45 +1,43 @@
|
||||
from typing import Any
|
||||
from .display import Display
|
||||
import curses
|
||||
|
||||
from dungeonbattle.entities.player import Player
|
||||
|
||||
|
||||
class StatsDisplay():
|
||||
class StatsDisplay(Display):
|
||||
player: Player
|
||||
|
||||
def __init__(self, height: int, width: int,
|
||||
toplefty: int, topleftx: int):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.topleftx = topleftx
|
||||
self.toplefty = toplefty
|
||||
|
||||
self.pad = curses.newpad(height, width)
|
||||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
self.pad = self.newpad(self.rows, self.cols)
|
||||
|
||||
def update_player(self, p: Player):
|
||||
self.player = p
|
||||
|
||||
def update_pad(self) -> None:
|
||||
string = ""
|
||||
for i in range(self.width - 1):
|
||||
for _ in range(self.width - 1):
|
||||
string = string + "-"
|
||||
self.pad.addstr(0, 0, string)
|
||||
string2 = "Player -- LVL {} EXP {}/{} HP {}/{}"\
|
||||
.format(self.player.level, self.player.current_xp,
|
||||
self.player.max_xp, self.player.health,
|
||||
self.player.maxhealth)
|
||||
for i in range(self.width - len(string2) - 1):
|
||||
for _ in range(self.width - len(string2) - 1):
|
||||
string2 = string2 + " "
|
||||
self.pad.addstr(1, 0, string2)
|
||||
string3 = "Stats : STR {} INT {} CHR {} DEX {} CON {}"\
|
||||
.format(self.player.strength,
|
||||
self.player.intelligence, self.player.charisma,
|
||||
self.player.dexterity, self.player.constitution)
|
||||
for i in range(self.width - len(string3) - 1):
|
||||
for _ in range(self.width - len(string3) - 1):
|
||||
string3 = string3 + " "
|
||||
self.pad.addstr(2, 0, string3)
|
||||
|
||||
def refresh(self, p : Player) -> None:
|
||||
self.player = p
|
||||
def display(self) -> None:
|
||||
self.pad.clear()
|
||||
self.update_pad()
|
||||
self.pad.refresh(0, 0, self.toplefty, self.topleftx,
|
||||
2 + self.toplefty,
|
||||
self.width + self.topleftx)
|
||||
self.pad.refresh(0, 0, self.y, self.x,
|
||||
2 + self.y,
|
||||
self.width + self.x)
|
||||
|
Reference in New Issue
Block a user