func ui() { defer wde.Stop() w, err := wde.NewWindow(640, 480) handle(err) w.SetTitle("g") w.Show() paint.Start(func(img *image.RGBA) { screen := w.Screen() screen.CopyRGBA(img, screen.Bounds()) w.FlushImage(screen.Bounds()) }, func(argv []string) { if len(argv) == 0 { return } paint.WithConsole(func(c *console.Console) { c.Bprint(">") c.Println(strings.Join(argv, " ")) }) if cmd, ok := commands[argv[0]]; ok { go cmd(argv[1:]) } else { paint.WithConsole(func(c *console.Console) { c.Errorln("Unknown command or filename.") c.Print("Type") c.Bprint("help") c.Println("at the prompt for a listing of basic commands.") }) } }) paint.ResetViewport(w.Screen().Bounds()) for event := range w.EventChan() { switch e := event.(type) { case wde.CloseEvent: _ = e return case wde.KeyTypedEvent: paint.Typed(e.Key, e.Glyph) case wde.ResizeEvent: paint.ResetViewport(w.Screen().Bounds()) } } }
func init() { commands["strongbad_email.exe"] = func([]string) { paint.WithConsole(func(c *console.Console) { c.Println("Dear Stong Bag,") c.Println("Do you like crap? Did you invent the word crap?") c.Println("Sometimes I like to write about crap. Isn't crap") c.Println("craptastic? Crap is the crap. Crap crap crap crap.") c.Println() c.Println("Crapfully crapfully,") c.Println("Dennis") }) } }
func init() { commands["help"] = func(argv []string) { key := strings.Join(argv, " ") paint.WithConsole(func(c *console.Console) { if h, ok := help[key]; ok { c.Println(h) } else { c.Error("No help for topic") c.Berrorln(key) } }) } }
func (r *Room) Look(argv []string) { if r == nil { paint.WithConsole(func(c *console.Console) { c.Println("You see nothing. You're not even a real person.") }) return } if len(argv) == 1 { var output string switch a := strings.ToLower(argv[0]); a { case "north": if output = r.Direct[North]; output == "" { output = "Nothing stands out to the north." } case "south": if output = r.Direct[South]; output == "" { output = "Nothing stands out to the south." } case "east": if output = r.Direct[East]; output == "" { output = "Nothing stands out to the east." } case "west": if output = r.Direct[West]; output == "" { output = "Nothing stands out to the west." } case "dennis": if output = r.Direct[Dennis]; output == "" { output = "Dennis isn't a real direction. You're just being silly." } } if output != "" { paint.WithConsole(func(c *console.Console) { c.Println(output) }) return } } if len(argv) != 0 { target := strings.ToLower(strings.Join(argv, " ")) if d, ok := r.Object[target]; ok { paint.WithConsole(func(c *console.Console) { c.Println(d.Desc) }) } else { paint.WithConsole(func(c *console.Console) { c.Errorln("I don't see any", strings.ToUpper(target)+".") }) } return } var possibleExits []string if r.Pass[North] { possibleExits = append(possibleExits, "NORTH") } if r.Pass[South] { possibleExits = append(possibleExits, "SOUTH") } if r.Pass[East] { possibleExits = append(possibleExits, "EAST") } if r.Pass[West] { possibleExits = append(possibleExits, "WEST") } if r.Pass[Dennis] { possibleExits = append(possibleExits, "DENNIS") } var exits string switch l := len(possibleExits); l { case 0: exits = "There are no obvious exits." case 1: exits = "There is an exit to the " + possibleExits[0] + "." case 2: exits = "Possible exits are " + possibleExits[0] + " and " + possibleExits[1] + "." default: exits = "Possible exits are " + strings.Join(possibleExits[:l-1], ", ") + ", and " + possibleExits[l-1] + "." } paint.WithConsole(func(c *console.Console) { c.Println(r.Desc) c.Println(exits) }) }