feat: add json format

This commit is contained in:
Jeffrey Duroyon
2020-05-11 00:03:32 +02:00
parent c8993f1ca3
commit 29a2a58d0e
3 changed files with 25 additions and 25 deletions

View File

@@ -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,