feat: add json format
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
package model
|
||||
|
||||
type Cage struct {
|
||||
Hamsters []*Hamster
|
||||
Hamsters []*Hamster `json:"hamsters"`
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package model
|
||||
|
||||
type Game struct {
|
||||
ID string
|
||||
server Server
|
||||
Cages []*Cage
|
||||
SelledHamster []*Hamster
|
||||
ID string `json:"game_id"`
|
||||
Server Server `json:"server"`
|
||||
Cages []*Cage `json:"cages"`
|
||||
SoldHamster []*Hamster `json:"sold_hamsters"`
|
||||
}
|
||||
|
||||
@@ -30,24 +30,24 @@ const (
|
||||
var GlobalHamsterNumber = 1
|
||||
|
||||
type Hamster struct {
|
||||
ID string
|
||||
Name string
|
||||
Number int
|
||||
Sexe string
|
||||
Age int // in days
|
||||
Father *Hamster
|
||||
Mother *Hamster
|
||||
HungerLevel int8
|
||||
ThirstLevel int8
|
||||
Weight float64
|
||||
Height float64
|
||||
Alive bool
|
||||
Selled bool
|
||||
Gestation bool
|
||||
GestationPeriod int8
|
||||
GestationCooldown int8
|
||||
GestationFather *Hamster
|
||||
Child []*Hamster
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Number int `json:"number"`
|
||||
Sexe string `json:"sexe"`
|
||||
Age int `json:"age"`
|
||||
Father *Hamster `json:"father"`
|
||||
Mother *Hamster `json:"mother"`
|
||||
HungerLevel int8 `json:"hunger_level"`
|
||||
ThirstLevel int8 `json:"thirst_level"`
|
||||
Weight float64 `json:"weight"`
|
||||
Height float64 `json:"height"`
|
||||
Alive bool `json:"alive"`
|
||||
Sold bool `json:"sold"`
|
||||
Gestation bool `json:"gestation"`
|
||||
GestationPeriod int8 `json:"gestation_period"`
|
||||
GestationCooldown int8 `json:"gestation_cooldown"`
|
||||
GestationFather *Hamster `json:"gestation_father"`
|
||||
Child []*Hamster `json:"childs"`
|
||||
}
|
||||
|
||||
func (h *Hamster) Die() {
|
||||
@@ -100,7 +100,7 @@ func (h *Hamster) Fuck(another *Hamster) (bool, error) {
|
||||
}
|
||||
|
||||
func Born(father *Hamster, mother *Hamster) ([]*Hamster, error) {
|
||||
if !mother.Alive || mother.Selled {
|
||||
if !mother.Alive || mother.Sold {
|
||||
return nil, errors.New("the mother is not here")
|
||||
}
|
||||
if mother.GestationPeriod != TotalGestationPeriod {
|
||||
@@ -125,7 +125,7 @@ func Born(father *Hamster, mother *Hamster) ([]*Hamster, error) {
|
||||
HungerLevel: Full,
|
||||
ThirstLevel: Full,
|
||||
Alive: true,
|
||||
Selled: false,
|
||||
Sold: false,
|
||||
Gestation: false,
|
||||
GestationPeriod: 0,
|
||||
GestationCooldown: 30,
|
||||
|
||||
Reference in New Issue
Block a user