From 5bae616ed250021e6c171d5ff1d1a73a7b145b95 Mon Sep 17 00:00:00 2001 From: Jeffrey Duroyon Date: Mon, 23 Aug 2021 23:33:15 +0200 Subject: [PATCH] feat(sell): add hamster selling method --- .DS_Store | Bin 0 -> 8196 bytes storage/model/hamster.go | 68 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..11f8b029b7be91fc6d871c37866701033c461752 GIT binary patch literal 8196 zcmeI1F;5#Y7=}L+s-y%V)CqOE4lHbRs+g`c-7AHGjW!7lkuJFq0+p%`w^Zs1Q%C*@ z5t?|jKpRgw5C+26^2Z9jT_XX8Lb>hN-~PqafsEo6?{Z4`mT?VKxV z&DQK9D)guQZa*DQD>|tV2gCt!KpYSU#DUdu0B1I*R?WF@TBQ^R#DOR20PhbGGRN4) z%tXC)pwL$U#C25bgy(I3K#XjRZOlwW3z9Nj5lvTRuNca7M}1^;Z;T(*xh!|DbCw!yLAFfmb4HjRJJJ~l zCp4fW#F%V`G%nw-qnxiY);KNL7U_JhTjqKWo)MkXCCVNMFX+^BZ|lWFSmm<4I?mYw z1)aPxh=(&gN19{qjaYQ}Y0m#aNqbJ%Qv&#ZH* z$-nYydydlDBWQy-B$%ClW{XOkqI4AH`eG|w`}ch24p%d|JwRfS9Y{j*2wjN`6$y~?9iQ%pwB@V(68 zTvC1$+dutQm!tnJ=WzPF3}J;gzy9Ni5hRHNE95}KutAG>kg@Bb@AEGXiDIPk9> zQ0tv;=MbaXyLDxJzH3LwACWn+E;CVgLBSHP*Vl2x{2zvRj%-_OV`d^+kpBA*0doFp K-=%ok4*UTVY)q*D literal 0 HcmV?d00001 diff --git a/storage/model/hamster.go b/storage/model/hamster.go index d8a7ff3..8e63cb1 100644 --- a/storage/model/hamster.go +++ b/storage/model/hamster.go @@ -3,9 +3,10 @@ package model import ( "errors" "fmt" - uuid "github.com/satori/go.uuid" "hamster-tycoon/randomizer" "time" + + uuid "github.com/satori/go.uuid" ) const ( @@ -58,6 +59,71 @@ func (h *Hamster) Die() { h.Alive = false } +func (h *Hamster) DeterminatePrice() int { + if h.Age >= 600 { + return 0 + } + var price = 50 + if h.Age >= 60 && h.Age <= 300 { + var diffAge, quotient int + diffAge = 300 - h.Age + quotient = diffAge / 25 + price += quotient * 5 + } + if h.Sexe == FEMALE { + price += 20 + } else { + price -= 20 + } + + if h.Gestation { + if h.Age >= 500 { + price += 5 + } else { + price += 20 + } + } + + if h.Age > 300 { + var diffAge, quotient int + diffAge = h.Age - 300 + quotient = diffAge / 100 + price += quotient * 10 + } + + switch h.ThirstLevel { + case Empty: + price -= 20 + case AlmostEmpty: + price -= 10 + case AlmostFull: + price += 10 + case Full: + price += 20 + } + + switch h.HungerLevel { + case Empty: + price -= 20 + case AlmostEmpty: + price -= 10 + case AlmostFull: + price += 10 + case Full: + price += 20 + } + switch { + case h.GestationCooldown > 0 && h.GestationCooldown <= 7: + price -= 10 + case h.GestationCooldown >= 8 && h.GestationCooldown <= 14: + price -= 5 + case h.GestationCooldown > 15: + price -= 2 + } + return price + +} + func (h *Hamster) Grow() { if h.Age >= MaxAge { if randNumber(h.Age-MaxAge, 365) > 364 {