From fa4f9834a2891c8aa2feb84b1d4eef22ddecc37d Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 4 Oct 2025 01:33:55 -0400 Subject: [PATCH] Restarting the game works better. --- main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index b0d72ff..3a64f66 100644 --- a/main.go +++ b/main.go @@ -49,12 +49,20 @@ type Game struct { enemies map[Position]*Enemy } -func (game *Game) DrawStatus(msg string) { - for x, cell := range msg { - game.screen.SetContent(x, game.height, cell, nil, tcell.StyleDefault) +func (game *Game) DrawText(x int, y int, text string) { + for i, cell := range text { + game.screen.SetContent(x+i, y, cell, nil, tcell.StyleDefault) } } +func (game *Game) DrawStatus() { + game.DrawText(0, game.height, game.status) + + hp := fmt.Sprintf("HP: %d", game.player.hp) + + game.DrawText(game.width - len(hp), game.height, hp) +} + func (game *Game) Status(msg string) { game.status = msg } @@ -112,7 +120,7 @@ func (game *Game) Render() { game.DrawEntity('G', pos, tcell.ColorRed) } - game.DrawStatus(game.status) + game.DrawStatus() game.screen.Show() } @@ -491,16 +499,13 @@ func (game *Game) AddRooms(dead_ends []Position, size int) { func (game *Game) MakeMap() []Position { game.FillMap(game.level, '#') - game.Status("FIRST MAZE") dead_ends := game.HuntAndKill() game.FillMap(game.level, '#') game.AddRooms(dead_ends, game.height / 8) - game.Status("SECOND MAZE") dead_ends = game.HuntAndKill() - game.Status("FINISHED") return dead_ends } @@ -517,6 +522,7 @@ func (game *Game) Restart() { game.player.hp = 20 game.player.pos = Position{1,1} game.screen.Clear() + clear(game.enemies) } func main() {