/** * User.ts export the User class that provides methods for communicating with the player */ const DEFAULT_PROMPT = ">"; export default class User { #prompt: string; constructor(prompt: string = DEFAULT_PROMPT) { this.#prompt = prompt; } ask(question: string): string { const answer = prompt(`${question}\n${this.#prompt} `); if (!answer) { return ""; } return answer; } async tell(statement: string): Promise { await this.out(`\n${statement}\n`); } private async out(text: string): Promise { const data = new TextEncoder().encode(text); await Deno.stdout.write(data); } }