Restarting the game works better.

master
Zed A. Shaw 5 days ago
parent e609673dee
commit fa4f9834a2
  1. 20
      main.go

@ -49,12 +49,20 @@ type Game struct {
enemies map[Position]*Enemy enemies map[Position]*Enemy
} }
func (game *Game) DrawStatus(msg string) { func (game *Game) DrawText(x int, y int, text string) {
for x, cell := range msg { for i, cell := range text {
game.screen.SetContent(x, game.height, cell, nil, tcell.StyleDefault) 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) { func (game *Game) Status(msg string) {
game.status = msg game.status = msg
} }
@ -112,7 +120,7 @@ func (game *Game) Render() {
game.DrawEntity('G', pos, tcell.ColorRed) game.DrawEntity('G', pos, tcell.ColorRed)
} }
game.DrawStatus(game.status) game.DrawStatus()
game.screen.Show() game.screen.Show()
} }
@ -491,16 +499,13 @@ func (game *Game) AddRooms(dead_ends []Position, size int) {
func (game *Game) MakeMap() []Position { func (game *Game) MakeMap() []Position {
game.FillMap(game.level, '#') game.FillMap(game.level, '#')
game.Status("FIRST MAZE")
dead_ends := game.HuntAndKill() dead_ends := game.HuntAndKill()
game.FillMap(game.level, '#') game.FillMap(game.level, '#')
game.AddRooms(dead_ends, game.height / 8) game.AddRooms(dead_ends, game.height / 8)
game.Status("SECOND MAZE")
dead_ends = game.HuntAndKill() dead_ends = game.HuntAndKill()
game.Status("FINISHED")
return dead_ends return dead_ends
} }
@ -517,6 +522,7 @@ func (game *Game) Restart() {
game.player.hp = 20 game.player.hp = 20
game.player.pos = Position{1,1} game.player.pos = Position{1,1}
game.screen.Clear() game.screen.Clear()
clear(game.enemies)
} }
func main() { func main() {

Loading…
Cancel
Save