54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
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
|
|
}
|
|
}
|