Advertisement
tsounakis

BABABOOEY

Oct 21st, 2020
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.99 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "bufio"
  6.     "strings"
  7.     "os"
  8. )
  9.  
  10. type Animals struct {
  11.     eat string
  12.     move string
  13.     speak string
  14. }
  15.  
  16. func (animal *Animals) Eat() {
  17.     fmt.Printf(animal.eat)
  18. }
  19.  
  20. func (animal *Animals) Move() {
  21.     fmt.Printf(animal.move)
  22. }
  23.  
  24. func (animal *Animals) Speak() {
  25.     fmt.Printf(animal.speak)
  26. }
  27.  
  28. func callFunc (an Animals, in string) () {
  29.     switch in {
  30.     case "eat":
  31.         an.Eat()
  32.         break
  33.     case "move":
  34.         an.Move()
  35.         break
  36.     case "speak":
  37.         an.Speak()
  38.         break
  39.     }
  40. }
  41.  
  42. func main() {
  43.     var in []string
  44.     var command string
  45.     var an2 Animals
  46.     input := bufio.NewScanner(os.Stdin)
  47.     cow :=  Animals{"grass", "walk", "moo"}
  48.     bird := Animals{"worms", "fly", "peep"}
  49.     snake := Animals{"mice", "slither", "hsss"}
  50.  
  51.  
  52.     dic2 := map[string]Animals {
  53.         "cow" : cow,
  54.         "bird" : bird,
  55.         "snake" : snake,
  56.     }
  57.  
  58.     fmt.Printf(">")
  59.     for input.Scan() {
  60.         command = input.Text()
  61.         in = strings.Split(command, " ")
  62.         an2 = dic2[in[0]]
  63.         callFunc(an2, in[1])
  64.         fmt.Printf("\n>")
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement