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
}
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() {

Loading…
Cancel
Save