From babd46c036a72a27d9cc7d6a56ce7679e0bcad7c Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 21 Nov 2023 19:14:58 +0000 Subject: [PATCH] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../gno.land/p/demo/tamagotchi/tamagotchi.gno | 9 ++- .../p/demo/tamagotchi/z0_filetest.gno | 74 +++++++++++++++++-- .../r/demo/tamagotchi/z0_filetest.gno | 10 +-- 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/examples/gno.land/p/demo/tamagotchi/tamagotchi.gno b/examples/gno.land/p/demo/tamagotchi/tamagotchi.gno index 2d99007fd85..5330605ee4e 100644 --- a/examples/gno.land/p/demo/tamagotchi/tamagotchi.gno +++ b/examples/gno.land/p/demo/tamagotchi/tamagotchi.gno @@ -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 } @@ -105,8 +105,6 @@ func (t *Tamagotchi) update() { return } - t.lastUpdated = now - duration := now.Sub(t.lastUpdated) elapsedMins := int(duration.Minutes()) @@ -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 diff --git a/examples/gno.land/p/demo/tamagotchi/z0_filetest.gno b/examples/gno.land/p/demo/tamagotchi/z0_filetest.gno index b32d02ed5d8..fcdcb5ab198 100644 --- a/examples/gno.land/p/demo/tamagotchi/z0_filetest.gno +++ b/examples/gno.land/p/demo/tamagotchi/z0_filetest.gno @@ -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() @@ -27,10 +30,23 @@ 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 @@ -38,11 +54,53 @@ func main() { // * 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 diff --git a/examples/gno.land/r/demo/tamagotchi/z0_filetest.gno b/examples/gno.land/r/demo/tamagotchi/z0_filetest.gno index 6ee7ff19971..8c393388873 100644 --- a/examples/gno.land/r/demo/tamagotchi/z0_filetest.gno +++ b/examples/gno.land/r/demo/tamagotchi/z0_filetest.gno @@ -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: