From 65d390af57e20f41de2a5f3253f778c5de82a3c3 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 2 Oct 2025 10:33:26 -0400 Subject: [PATCH] Cleaned up the code some after debugging for a while. --- Makefile | 3 +++ main.go | 35 +++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e53d913..255e0bb 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ build: go build . + +run: build + ./gorogue diff --git a/main.go b/main.go index 9d08123..6b20b1c 100644 --- a/main.go +++ b/main.go @@ -50,9 +50,7 @@ func (game *Game) Render() { } game.Text(game.status) - game.screen.SetContent(game.player.x, game.player.y, '@', comb, tcell.StyleDefault) - game.screen.Show() } @@ -112,9 +110,7 @@ func MakeGame() (*Game) { err = game.screen.Init() if err != nil { log.Fatal(err) } - - game.player.x = 1 - game.player.y = 1 + game.player = Position{1,1} return &game } @@ -124,7 +120,7 @@ func compass(x int, y int, offset int) []Position { Position{x, y - offset}, Position{x, y + offset}, Position{x + offset, y}, - Position{x - offset, y}, + Position{ x - offset, y}, } } @@ -160,28 +156,32 @@ func (game *Game) NeighborWalls(pos Position) []Position { return result } -func (game *Game) FindCoord() []Position { +func (game *Game) FindCoord(on *Position, found *Position) bool { for y := 1; y < game.height ; y += 2 { for x := 1; x < game.width ; x += 2 { if game.level[y][x] != WALL { continue } - found := game.Neighbors(Position{x, y}) + neighbors := game.Neighbors(Position{x, y}) - for _, pos := range found { + for _, pos := range neighbors { if game.level[pos.y][pos.x] == SPACE { - return []Position{Position{x, y}, pos} + *on = Position{x, y} + *found = pos + return true } } } } - return nil + return false } func (game *Game) HuntAndKill() []Position { on := Position{1, 1} + found := Position{1,1} + dead_ends := make([]Position, 0) for { @@ -190,23 +190,26 @@ func (game *Game) HuntAndKill() []Position { if len(neighbors) == 0 { dead_ends = append(dead_ends, on) - next_guess := game.FindCoord() - if next_guess == nil { break } - - on = next_guess[0] - found := next_guess[1] + if !game.FindCoord(&on, &found) { + break + } game.level[on.y][on.x] = SPACE + row := (on.y + found.y) / 2 col := (on.x + found.x) / 2 game.level[row][col] = SPACE } else { rand_neighbor := rand.Int() % len(neighbors) nb := neighbors[rand_neighbor] + game.level[nb.y][nb.x] = SPACE + row := (nb.y + on.y) / 2 col := (nb.x + on.x) / 2 + game.level[row][col] = SPACE + on = nb } }