func doPromptLine(rl *readline.Instance, prompt string, hide bool) (string, error) { var line = "" var bytepwd []byte var err error if hide { bytepwd, err = rl.ReadPassword(prompt) line = string(bytepwd) } else { line, err = rl.Readline() } if err != nil { return "", err } return line, nil }
func NewLocalGame(rl *readline.Instance) *localGame { fmt.Println("welcome to our game!") fmt.Println("What is your name?") line, err := rl.Readline() if err != nil { panic(err) } pl := &Player{} pl.splitName(line) // TODO: this needs to go into a // more generic constructor func // pre-fill with actions r, err := db.Query(` select ActionID, Action from TextAdventure.Actions `) lolwut: if err != nil { fmt.Println("Failed getting actions!") panic(err) } actions := Actions{} for r.Next() { var id int var actionText string err = r.Scan(&id, &actionText) if err != nil { r.Close() goto lolwut } actions[id] = actionText } if validTokens == nil { r, err = db.Query( ` select (select group_concat(Action separator '|') from TextAdventure.Actions) actions, (select group_concat(Item separator '|') from TextAdventure.Items) item, (select group_concat(Room separator '|') from TextAdventure.Rooms) rooms `, ) var rstr string //var actions, items, rooms string for r.Next() { err = r.Scan(&allActions, &allItems, &allRooms) if err != nil { r.Close() goto lolwut } } rstr += allActions + "|" + allItems + "|" + allRooms rstr += "|" + preps r.Close() validTokens = regexp.MustCompile( fmt.Sprintf( "(?i)((%s)\\s{0,1})+", rstr, ), ) sentence := fmt.Sprintf( "(?i)(%s)\\s?(%s)?\\s?(%s)?\\s?(%s)?", allActions, allItems, preps, allItems, ) parseDebug("sentence regexp:\n%s", sentence) sentenceRegexp = regexp.MustCompile( // (verb) (prep.) (object) (prep.) (p. obj) sentence, ) } return &localGame{ player: pl, actions: actions, rl: rl, roomID: 1, } }