refactor: generator

This commit is contained in:
Ilia Denisov
2025-09-11 23:26:32 +03:00
parent 371453fac5
commit d3b00b5c8d
9 changed files with 241 additions and 201 deletions
+53
View File
@@ -0,0 +1,53 @@
package generator
import (
"fmt"
)
type Map struct {
Width uint
Height uint
HomePlanets []PlanetarySystem
FreePlanets []Planet
plotter Plotter
}
type Coordinate struct {
X, Y float32
}
type Planet struct {
Position Coordinate
Size float32
Resources float32 // Сырьё
}
type PlanetarySystem struct {
HW Planet
DW []Planet
}
func NewMap(width, height, players uint) (*Map, error) {
p, err := NewPlotter(width, height, 1.0)
if err != nil {
return nil, fmt.Errorf("NewPlotter: %s", err)
}
return &Map{
Width: width,
Height: height,
HomePlanets: make([]PlanetarySystem, players),
plotter: p,
}, nil
}
func (m *Map) AddPlanet(planet Planet) {
m.FreePlanets = append(m.FreePlanets, planet)
}
func (m Map) NewCoordinate(deadZoneRaduis float32) (Coordinate, error) {
if x, y, err := m.plotter.RandomFreePoint(deadZoneRaduis); err != nil {
return Coordinate{}, fmt.Errorf("NewCoordinate: RandomFreePoint: %s", err)
} else {
return Coordinate{X: x, Y: y}, nil
}
}