Documentation
¶
Overview ¶
Package farming is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package farming contains deterministic rules shared by farming and life-sim games. Calendar and crop records are deliberately independent of devices, rendering, and storage so games can drive them from a fixed-step loop.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Calendar ¶
Calendar is a repeating season calendar. Day is one-based and Hour is in [0, 24). Advancing past the end of a season starts the next season at day 1.
Example ¶
package main
import (
"fmt"
"time"
"github.com/nsgo-dev/game/pkg/farming"
)
func main() {
c := farming.Calendar{
Seasons: []farming.Season{{ID: "spring", Days: 2}, {ID: "summer", Days: 3}},
Day: 2,
Hour: 23,
}
for _, d := range []time.Duration{2 * time.Hour, 48 * time.Hour} {
days, err := c.Advance(d)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("crossed %d: %s day %d hour %.0f\n", days, c.Seasons[c.Season].ID, c.Day, c.Hour)
}
}
Output: crossed 1: summer day 1 hour 1 crossed 2: summer day 3 hour 1
type Crop ¶
Crop is the persistent state of one planted crop.
func (*Crop) WateredDay ¶
WateredDay records one day's watering. It returns true when the crop became ripe on this day.
Example ¶
package main
import (
"fmt"
"github.com/nsgo-dev/game/pkg/farming"
)
func main() {
turnip := farming.CropKind{ID: "turnip", Stages: 3, DaysPerStage: 2}
crop := farming.Crop{Kind: "turnip"}
// The crop grows one stage every two watered days and is ripe at its last stage.
for day := 1; day <= 4; day++ {
ripe, err := crop.WateredDay(turnip)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("day %d: stage %d ripe %t\n", day, crop.Stage, ripe)
}
}
Output: day 1: stage 0 ripe false day 2: stage 1 ripe false day 3: stage 1 ripe false day 4: stage 2 ripe true