From 0bd26a1bd055dd09ca3b23c4694ab39744cc11b5 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 6 Nov 2020 21:15:09 +0100 Subject: [PATCH] Linting --- dungeonbattle/display/display.py | 12 ++++++++---- dungeonbattle/display/mapdisplay.py | 18 ++++++++--------- dungeonbattle/display/statsdisplay.py | 28 +++++++++++++++++++++------ dungeonbattle/entities/player.py | 19 +++++++++--------- dungeonbattle/interfaces.py | 8 +++++--- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index b0ced92..c21db74 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -1,21 +1,25 @@ import curses +from typing import Any + from .mapdisplay import MapDisplay from .texturepack import TexturePack +from ..game import Game class Display: - def __init__(self, game, screen): + def __init__(self, game: Game, screen: Any): self.screen = screen self.game = game lines = curses.LINES if screen else 4 cols = curses.COLS * 4 // 5 if screen else 4 self.map_display = MapDisplay(game.m, TexturePack.get_pack( - game.settings.TEXTURE_PACK), + game.settings.TEXTURE_PACK + ), lines, cols, screen is not None) - def refresh(self): + def refresh(self) -> None: self.map_display.update_pad() - def display(self, y, x): + def display(self, y: int, x: int) -> None: self.map_display.display(y, x) diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index 03cf092..3a03290 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -16,21 +16,21 @@ class MapDisplay: if init_pad: self.pad = curses.newpad(m.height, m.width + 1) - def update_pad(self): + def update_pad(self) -> None: self.pad.addstr(0, 0, self.map.draw_string(self.pack)) for e in self.map.entities: self.pad.addstr(e.y, e.x, self.pack.PLAYER) - def display(self, y, x): - deltay, deltax = (self.height // 2) + 1, (self.width //2) + 1 - pminrow, pmincol = y-deltay, x-deltax + def display(self, y: int, x: int) -> None: + deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1 + pminrow, pmincol = y - deltay, x - deltax sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0) deltay, deltax = self.height - deltay, self.width - deltax - smaxrow = self.map.height - (y + deltay) + self.height -1 - smaxrow = min(smaxrow, self.height-1) - smaxcol = self.map.width - (x + deltax) + self.width -1 - smaxcol = min(smaxcol, self.width-1) - pminrow = max(0, min(self.map.height, pminrow)) + smaxrow = self.map.height - (y + deltay) + self.height - 1 + smaxrow = min(smaxrow, self.height - 1) + smaxcol = self.map.width - (x + deltax) + self.width - 1 + smaxcol = min(smaxcol, self.width - 1) + pminrow = max(0, min(self.map.height, pminrow)) pmincol = max(0, min(self.map.width, pmincol)) self.pad.clear() self.update_pad() diff --git a/dungeonbattle/display/statsdisplay.py b/dungeonbattle/display/statsdisplay.py index 6dc0b11..4ae7ab8 100644 --- a/dungeonbattle/display/statsdisplay.py +++ b/dungeonbattle/display/statsdisplay.py @@ -1,15 +1,31 @@ import curses +from dungeonbattle.entities.player import Player + + class StatsDisplay: - def __init__(self, player, height, width, topleftx, toplefty) : + def __init__(self, player: Player, height: int, width: int, + topleftx: int, toplefty: int): self.width = width self.height = height + self.topleftx = topleftx + self.toplefty = toplefty + self.player = player self.pad = curses.newpad(height, width) - def update_pad(self) : - string = "Player -- LVL {} EXP {}/{} HP {}/{}\nStats : STR {} INT {} CHR {} DEX {} CON {}".format(player.level, player.currentXP, player.maxXP, player.health, player.maxhealth, player.strength, player.intelligence, player.charisma, player.dexterity, player.constitution) + + def update_pad(self) -> None: + string = "Player -- LVL {} EXP {}/{} HP {}/{}\n" \ + "Stats : STR {} INT {} CHR {} DEX {} CON {}"\ + .format(self.player.level, self.player.current_xp, + self.player.max_xp, self.player.health, + self.player.maxhealth, self.player.strength, + self.player.intelligence, self.player.charisma, + self.player.dexterity, self.player.constitution) self.pad.addstr(0, 0, string) - def refresh(self) : + + def refresh(self) -> None: self.pad.clear() self.update_pad() - self.pad.refresh(0, 0, toplefty, topleftx, heigth+toplefty, width+topleftx) - + self.pad.refresh(0, 0, self.toplefty, self.topleftx, + self.heigth + self.toplefty, + self.width + self.topleftx) diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index 9a95150..c4fe6b8 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -17,14 +17,15 @@ class Player(FightingEntity): def move_right(self) -> bool: return self.check_move(self.y, self.x + 1, True) - currentXP: int - maxXP: int + current_xp: int + max_xp: int - def level_up(self): - if currentXP>maxXP : - self.level+=1 - currentXP = 0 - maxXP = self.level*10 - def addXP(self, xp) : - currentXP+=xp + def level_up(self) -> None: + if self.current_xp > self.max_xp: + self.level += 1 + self.current_xp = 0 + self.max_xp = self.level * 10 + + def add_xp(self, xp: int) -> None: + self.current_xp += xp self.level_up() diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 2459149..bbcd25e 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -12,8 +12,10 @@ class Map: width: int height: int tiles: list - currentx : int #coordinates of the point that should be on the topleft corner of the screen - currenty : int + # coordinates of the point that should be + # on the topleft corner of the screen + currentx: int + currenty: int def __init__(self, width: int, height: int, tiles: list): self.width = width @@ -88,7 +90,7 @@ class Tile(Enum): class Entity: y: int x: int - name : str + name: str map: Map def __init__(self):