Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: moul <[email protected]>
  • Loading branch information
moul committed Nov 21, 2023
1 parent 6fe0d2f commit babd46c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
9 changes: 6 additions & 3 deletions examples/gno.land/p/demo/tamagotchi/tamagotchi.gno
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (t Tamagotchi) dead() bool { return t.health == 0 }

// Update applies changes based on the duration since the last update
func (t *Tamagotchi) update() {
if !t.dead() {
if t.dead() {
return
}

Expand All @@ -105,8 +105,6 @@ func (t *Tamagotchi) update() {
return
}

t.lastUpdated = now

duration := now.Sub(t.lastUpdated)
elapsedMins := int(duration.Minutes())

Expand All @@ -120,7 +118,12 @@ func (t *Tamagotchi) update() {
if t.age > t.maxAge {
t.age = t.maxAge
t.health = 0
t.sleepy = 0
t.happiness = 0
t.hunger = 0
}

t.lastUpdated = now
}

// Face returns an ASCII art representation of the Tamagotchi's current state
Expand Down
74 changes: 66 additions & 8 deletions examples/gno.land/p/demo/tamagotchi/z0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import (
"std"
"time"

"internal/os_test"

"gno.land/p/demo/tamagotchi"
)

func main() {
t := tamagotchi.New("Gnome")

println("-- INITIAL")
println("\n-- INITIAL\n")
println(t.Markdown())

// println("-- WAIT 20 minutes")
// println(t.Markdown())
println("\n-- WAIT 20 minutes\n")
os_test.Sleep(20 * time.Minute)
println(t.Markdown())

println("-- FEEDx3, PLAYx2, HEALx4")
println("\n-- FEEDx3, PLAYx2, HEALx4\n")
t.Feed()
t.Feed()
t.Feed()
Expand All @@ -27,22 +30,77 @@ func main() {
t.Heal()
t.Heal()
println(t.Markdown())

println("\n-- WAIT 20 minutes\n")
os_test.Sleep(20 * time.Minute)
println(t.Markdown())

println("\n-- WAIT 20 hours\n")
os_test.Sleep(20 * time.Hour)
println(t.Markdown())

println("\n-- WAIT 20 hours\n")
os_test.Sleep(20 * time.Hour)
println(t.Markdown())
}

// Output:
// -- INITIAL
//
// # Gnome 😃
//
// * age: 0
// * hunger: 50
// * happiness: 50
// * health: 50
// * sleepy: 0
//
// -- WAIT 20 minutes
//
// # Gnome 😃
//
// * age: 0
// * hunger: 70
// * happiness: 30
// * health: 30
// * sleepy: 20
//
// -- FEEDx3, PLAYx2, HEALx4
//
// # Gnome 😃
//
// * age: 0
// * hunger: 20
// * happiness: 70
// * health: 90
// * sleepy: 0
// * hunger: 40
// * happiness: 50
// * health: 70
// * sleepy: 20
//
// -- WAIT 20 minutes
//
// # Gnome 😃
//
// * age: 0
// * hunger: 60
// * happiness: 30
// * health: 50
// * sleepy: 40
//
// -- WAIT 20 hours
//
// # Gnome 😵
//
// * age: 20
// * hunger: 100
// * happiness: 0
// * health: 0
// * sleepy: 100
//
// -- WAIT 20 hours
//
// # Gnome 😵
//
// * age: 20
// * hunger: 100
// * happiness: 0
// * health: 0
// * sleepy: 100
10 changes: 5 additions & 5 deletions examples/gno.land/r/demo/tamagotchi/z0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func main() {
}

// Output:
// # gnome#0 😃
// # gnome#0 😵
//
// * age: 0
// * hunger: 50
// * happiness: 50
// * health: 50
// * age: 100
// * hunger: 0
// * happiness: 0
// * health: 0
// * sleepy: 0
//
// Actions:
Expand Down

0 comments on commit babd46c

Please sign in to comment.