Add method updating console on player interaction in Ui and fix bar updating

This commit is contained in:
Michał Czekański 2020-04-06 13:20:04 +02:00
parent 156f9977e0
commit 178115cc4d

View File

@ -62,23 +62,17 @@ class Ui():
screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h), screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h),
font=self.font) font=self.font)
def updateBasedOnPlayerStats(self, statistics: Statistics): def updateConsoleBasedOnPlayerStats(self, statistics: Statistics):
consoleLines = [] consoleLines = ["Health: " + str(statistics.hp), "Hunger: " + str(statistics.hunger),
"Stamina: " + str(statistics.stamina), "Thirst: " + str(statistics.thirst)]
self.healthBar.updateFill(statistics.hp)
consoleLines.append("Health: " + str(statistics.hp))
self.hungerBar.updateFill(statistics.hunger)
consoleLines.append("Hunger: " + str(statistics.hunger))
self.staminaBar.updateFill(statistics.stamina)
consoleLines.append("Stamina: " + str(statistics.stamina))
self.thirstBar.updateFill(statistics.thirst)
consoleLines.append("Thirst: " + str(statistics.thirst))
self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines)
def updateBarsBasedOnPlayerStats(self, statistics: Statistics):
self.healthBar.updateFill(statistics.hp)
self.hungerBar.updateFill(statistics.hunger)
self.staminaBar.updateFill(statistics.stamina)
self.thirstBar.updateFill(statistics.thirst)
def updateBasedOnPygameEvent(self, event: pygame.event): def updateBasedOnPygameEvent(self, event: pygame.event):
if event.type == pygame.MOUSEBUTTONDOWN: if event.type == pygame.MOUSEBUTTONDOWN:
console = self.console console = self.console
@ -89,7 +83,11 @@ class Ui():
def updateOnPlayerPickup(self, playerStats, pickedObject): def updateOnPlayerPickup(self, playerStats, pickedObject):
self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"])
self.updateBasedOnPlayerStats(playerStats) self.updateConsoleBasedOnPlayerStats(playerStats)
def updateOnPlayerInteraction(self, playerStats, interactedObject):
self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Player interacted with " + str(interactedObject.id) + ":"])
self.updateConsoleBasedOnPlayerStats(playerStats)
def updateTime(self): def updateTime(self):
self.timerTextView.changeText(self.timer.getPrettyTime()) self.timerTextView.changeText(self.timer.getPrettyTime())