refactor: plotter, generator
This commit is contained in:
+28
-5
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user