squirrel-battle/dungeonbattle/display/statsdisplay.py

46 lines
1.6 KiB
Python
Raw Normal View History

2020-11-06 18:53:27 +00:00
import curses
2020-11-08 22:05:06 +00:00
from typing import Any
2020-11-06 18:53:27 +00:00
2020-11-08 22:05:06 +00:00
from dungeonbattle.display.display import Display
2020-11-06 20:15:09 +00:00
from dungeonbattle.entities.player import Player
2020-11-08 22:05:06 +00:00
class StatsDisplay(Display):
def __init__(self, screen: Any, player: Player, height: int, width: int,
2020-11-06 20:15:09 +00:00
topleftx: int, toplefty: int):
2020-11-08 22:05:06 +00:00
super().__init__(screen)
self.width = width
self.height = height
2020-11-06 20:15:09 +00:00
self.topleftx = topleftx
self.toplefty = toplefty
self.player = player
2020-11-08 22:40:03 +00:00
self.pad = self.newpad(height, width)
2020-11-06 20:15:09 +00:00
def update_pad(self) -> None:
2020-11-07 14:00:24 +00:00
string = ""
2020-11-08 21:48:50 +00:00
for i in range(self.width - 1):
2020-11-07 14:00:24 +00:00
string = string + "-"
string = string
self.pad.addstr(0, 0, string)
string2 = "Player -- LVL {} EXP {}/{} HP {}/{}"\
2020-11-06 20:15:09 +00:00
.format(self.player.level, self.player.current_xp,
self.player.max_xp, self.player.health,
2020-11-07 14:00:24 +00:00
self.player.maxhealth)
2020-11-08 21:48:50 +00:00
for i in range(self.width - len(string2) - 1):
2020-11-07 14:00:24 +00:00
string2 = string2 + " "
self.pad.addstr(1, 0, string2)
string3 = "Stats : STR {} INT {} CHR {} DEX {} CON {}"\
.format(self.player.strength,
2020-11-06 20:15:09 +00:00
self.player.intelligence, self.player.charisma,
self.player.dexterity, self.player.constitution)
2020-11-08 21:48:50 +00:00
for i in range(self.width - len(string3) - 1):
2020-11-07 14:00:24 +00:00
string3 = string3 + " "
2020-11-08 21:48:50 +00:00
self.pad.addstr(2, 0, string3)
2020-11-06 20:15:09 +00:00
def refresh(self) -> None:
self.pad.clear()
self.update_pad()
2020-11-06 20:15:09 +00:00
self.pad.refresh(0, 0, self.toplefty, self.topleftx,
2020-11-08 21:48:50 +00:00
2 + self.toplefty,
self.width + self.topleftx)