refactor: plotter, generator

This commit is contained in:
Ilia Denisov
2025-09-12 21:32:50 +03:00
parent d3b00b5c8d
commit 05999687aa
11 changed files with 262 additions and 140 deletions
+28 -5
View File
@@ -2,14 +2,17 @@ package generator
import (
"fmt"
"math/rand"
"github.com/iliadenisov/galaxy/pkg/generator/plotter"
)
type Map struct {
Width uint
Height uint
Width uint32
Height uint32
HomePlanets []PlanetarySystem
FreePlanets []Planet
plotter Plotter
plotter plotter.Plotter
}
type Coordinate struct {
@@ -27,8 +30,8 @@ type PlanetarySystem struct {
DW []Planet
}
func NewMap(width, height, players uint) (*Map, error) {
p, err := NewPlotter(width, height, 1.0)
func NewMap(width, height, players uint32) (*Map, error) {
p, err := plotter.NewPlotter(width, height, 1.0)
if err != nil {
return nil, fmt.Errorf("NewPlotter: %s", err)
}
@@ -51,3 +54,23 @@ func (m Map) NewCoordinate(deadZoneRaduis float32) (Coordinate, error) {
return Coordinate{X: x, Y: y}, nil
}
}
func NewPlanet(c Coordinate, size, resources float32) Planet {
return Planet{
Position: c,
Size: size,
Resources: resources,
}
}
// RandI returns a random float32 value between min and max
func RandI(min, max float32) float32 {
return min + rand.Float32()*(max-min)
}
// RandIFn is a wrapper for the [RandI] func
func RandIFn(min, max float32) func() float32 {
return func() float32 {
return RandI(min, max)
}
}