Rename movement/world methods to idiomatic Go; remove all gotos
Refactor step 4. Renames (C breadcrumbs kept in doc comments): doMove→moveHero, beTrapped→springTrap, rndmove→randomStep, doRooms→digRooms, doPassages→digPassages, doMaze→digMaze, chgStr→changeStrength, doRun→startRun, moveStuff→finishMove, turnref→turnRefresh, moveMonst→moveMonster, doChase→chaseStep, setOldch→setOldChar, cansee→canSee, roomin→roomIn, runto→runTo, conn→connectRooms, putpass→putPassage, passnum→numberPassages, numpass→numberPassage, rndPos→randomPos, rndRoom→randomRoom, treasRoom→treasureRoom, accntMaze→accountMaze. All goto/label flows are gone: moveHero uses a retry loop with the PASSGO corner logic extracted into passageTurn; dispatch re-dispatches via a loop; chaseStep re-checks via a loop; saveGame uses a labeled prompt loop. Control flow and RNG call order are unchanged; suite green.
This commit is contained in:
@@ -2,8 +2,8 @@ package game
|
||||
|
||||
// passages.c — draw the connecting passages.
|
||||
|
||||
// doPassages draws all the passages on a level (passages.c do_passages).
|
||||
func (g *RogueGame) doPassages() {
|
||||
// digPassages draws all the passages on a level (passages.c do_passages).
|
||||
func (g *RogueGame) digPassages() {
|
||||
var (
|
||||
isconn [MaxRooms][MaxRooms]bool
|
||||
ingraph [MaxRooms]bool
|
||||
@@ -41,7 +41,7 @@ func (g *RogueGame) doPassages() {
|
||||
// otherwise, connect new room to the graph, and draw a tunnel
|
||||
// to it
|
||||
ingraph[r2] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
|
||||
g.conn(r1, r2)
|
||||
g.connectRooms(r1, r2)
|
||||
isconn[r1][r2] = true
|
||||
isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
|
||||
roomcount++
|
||||
@@ -69,18 +69,18 @@ func (g *RogueGame) doPassages() {
|
||||
}
|
||||
// if there is one, connect it and look for the next added passage
|
||||
if j != 0 {
|
||||
g.conn(r1, r2)
|
||||
g.connectRooms(r1, r2)
|
||||
isconn[r1][r2] = true
|
||||
isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
|
||||
}
|
||||
}
|
||||
|
||||
g.passnum()
|
||||
g.numberPassages()
|
||||
}
|
||||
|
||||
// conn draws a corridor from a room in a certain direction (passages.c
|
||||
// conn).
|
||||
func (g *RogueGame) conn(r1, r2 int) {
|
||||
// connectRooms draws a corridor from a room in a certain direction
|
||||
// (passages.c conn).
|
||||
func (g *RogueGame) connectRooms(r1, r2 int) {
|
||||
var (
|
||||
rm int
|
||||
direc byte
|
||||
@@ -193,13 +193,13 @@ func (g *RogueGame) conn(r1, r2 int) {
|
||||
if !rpf.Flags.Has(Gone) {
|
||||
g.door(rpf, spos)
|
||||
} else {
|
||||
g.putpass(spos)
|
||||
g.putPassage(spos)
|
||||
}
|
||||
|
||||
if !rpt.Flags.Has(Gone) {
|
||||
g.door(rpt, epos)
|
||||
} else {
|
||||
g.putpass(epos)
|
||||
g.putPassage(epos)
|
||||
}
|
||||
// Get ready to move...
|
||||
curr := spos
|
||||
@@ -210,13 +210,13 @@ func (g *RogueGame) conn(r1, r2 int) {
|
||||
// Check if we are at the turn place, if so do the turn
|
||||
if distance == turnSpot {
|
||||
for ; turnDistance > 0; turnDistance-- {
|
||||
g.putpass(curr)
|
||||
g.putPassage(curr)
|
||||
curr.X += turnDelta.X
|
||||
curr.Y += turnDelta.Y
|
||||
}
|
||||
}
|
||||
// Continue digging along
|
||||
g.putpass(curr)
|
||||
g.putPassage(curr)
|
||||
|
||||
distance--
|
||||
}
|
||||
@@ -229,9 +229,9 @@ func (g *RogueGame) conn(r1, r2 int) {
|
||||
}
|
||||
}
|
||||
|
||||
// putpass adds a passage character or secret passage here (passages.c
|
||||
// putPassage adds a passage character or secret passage here (passages.c
|
||||
// putpass).
|
||||
func (g *RogueGame) putpass(cp Coord) {
|
||||
func (g *RogueGame) putPassage(cp Coord) {
|
||||
pp := g.Level.At(cp.Y, cp.X)
|
||||
pp.Flags.Set(FPassage)
|
||||
|
||||
@@ -302,8 +302,8 @@ func (g *RogueGame) addPass() {
|
||||
}
|
||||
}
|
||||
|
||||
// passnum assigns a number to each passageway (passages.c passnum).
|
||||
func (g *RogueGame) passnum() {
|
||||
// numberPassages assigns a number to each passageway (passages.c passnum).
|
||||
func (g *RogueGame) numberPassages() {
|
||||
g.pnum = 0
|
||||
|
||||
g.newpnum = false
|
||||
@@ -315,14 +315,14 @@ func (g *RogueGame) passnum() {
|
||||
rp := &g.Level.Rooms[i]
|
||||
for j := range rp.Exits {
|
||||
g.newpnum = true
|
||||
g.numpass(rp.Exits[j].Y, rp.Exits[j].X)
|
||||
g.numberPassage(rp.Exits[j].Y, rp.Exits[j].X)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// numpass numbers a passageway square and its brethren (passages.c
|
||||
// numberPassage numbers a passageway square and its brethren (passages.c
|
||||
// numpass).
|
||||
func (g *RogueGame) numpass(y, x int) {
|
||||
func (g *RogueGame) numberPassage(y, x int) {
|
||||
if x >= NumCols || x < 0 || y >= NumLines || y <= 0 {
|
||||
return
|
||||
}
|
||||
@@ -348,10 +348,10 @@ func (g *RogueGame) numpass(y, x int) {
|
||||
|
||||
*fp |= PlaceFlags(g.pnum) //nolint:gosec // G115: pnum < MaxPass=13
|
||||
// recurse on the surrounding places
|
||||
g.numpass(y+1, x)
|
||||
g.numpass(y-1, x)
|
||||
g.numpass(y, x+1)
|
||||
g.numpass(y, x-1)
|
||||
g.numberPassage(y+1, x)
|
||||
g.numberPassage(y-1, x)
|
||||
g.numberPassage(y, x+1)
|
||||
g.numberPassage(y, x-1)
|
||||
}
|
||||
|
||||
// abs is C abs() for ints.
|
||||
|
||||
Reference in New Issue
Block a user