github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/tamagotchi/realm.gno (about)

     1  package tamagotchi
     2  
     3  import (
     4  	"std"
     5  
     6  	"gno.land/p/demo/tamagotchi"
     7  	"gno.land/p/demo/ufmt"
     8  )
     9  
    10  var t *tamagotchi.Tamagotchi
    11  
    12  func init() {
    13  	Reset("gnome#0")
    14  }
    15  
    16  func Reset(optionalName string) string {
    17  	name := optionalName
    18  	if name == "" {
    19  		height := std.GetHeight()
    20  		name = ufmt.Sprintf("gnome#%d", height)
    21  	}
    22  
    23  	t = tamagotchi.New(name)
    24  
    25  	return ufmt.Sprintf("A new tamagotchi is born. Their name is %s %s.", t.Name(), t.Face())
    26  }
    27  
    28  func Feed() string {
    29  	t.Feed()
    30  	return t.Markdown()
    31  }
    32  
    33  func Play() string {
    34  	t.Play()
    35  	return t.Markdown()
    36  }
    37  
    38  func Heal() string {
    39  	t.Heal()
    40  	return t.Markdown()
    41  }
    42  
    43  func Render(path string) string {
    44  	tama := t.Markdown()
    45  	links := `Actions:
    46  * [Feed](/r/demo/tamagotchi?help&__func=Feed)
    47  * [Play](/r/demo/tamagotchi?help&__func=Play)
    48  * [Heal](/r/demo/tamagotchi?help&__func=Heal)
    49  * [Reset](/r/demo/tamagotchi?help&__func=Reset)
    50  `
    51  
    52  	return tama + "\n\n" + links
    53  }