mirror of
https://github.com/mvvasilev/last_light.git
synced 2025-04-19 20:59:51 +03:00
26 lines
495 B
Go
26 lines
495 B
Go
|
package model
|
||
|
|
||
|
import "math/rand"
|
||
|
|
||
|
type EntitySupplier func(x, y int) Entity
|
||
|
|
||
|
type EntityTable struct {
|
||
|
table []EntitySupplier
|
||
|
}
|
||
|
|
||
|
func CreateEntityTable() *EntityTable {
|
||
|
return &EntityTable{
|
||
|
table: make([]EntitySupplier, 0),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (igt *EntityTable) Add(weight int, createItemFunction EntitySupplier) {
|
||
|
for range weight {
|
||
|
igt.table = append(igt.table, createItemFunction)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (igt *EntityTable) Generate(x, y int) Entity {
|
||
|
return igt.table[rand.Intn(len(igt.table))](x, y)
|
||
|
}
|