Exemplo n.º 1
0
func Run(gamer I.Gamer, stdin *bufio.Reader, printer print.Printer) {
	var in string

	printer.ClearScreen()
	printer.WelcomeMessage()
	printer.WhatsNext()
	in = input.GetInput(stdin)

	for !input.WantsToQuit(in) {
		switch {
		case input.WantsInstructions(in):
			printer.ClearScreen()
			printer.Instructions()
		case input.WantsToPlay(in):
			printer.ClearScreen()
			gamer.Play()
		case input.SecretCode(in):
			printer.EnterCode()
			in = input.GetInput(stdin)
			for !input.Valid(in) {
				printer.UnknownGameCommand()
				printer.EnterCode()
				in = input.GetInput(stdin)
			}
			printer.ClearScreen()
			gamer.Play(in)
		default:
			printer.UnknownMainCommand()
		}

		printer.WhatsNext()
		in = input.GetInput(stdin)
	}

	printer.QuitMessage()
}
Exemplo n.º 2
0
	BeforeEach(func() {
		stdin = &bytes.Buffer{}
		stdinReader = bufio.NewReader(stdin)

		buffer = gbytes.NewBuffer()

		printer = print.NewPrinter(buffer)

		gamer = NewGamer(stdinReader, printer)
	})

	Context("with invalid input", func() {
		It("will ask for valid input", func() {
			commandSequence("hoohah", "this wont work", "q")

			gamer.Play()

			Eventually(buffer).Should(gbytes.Say("Unknown command"))
			Eventually(buffer).Should(gbytes.Say("Valid commands are"))
			Eventually(buffer).Should(gbytes.Say("Unknown command"))
			Eventually(buffer).Should(gbytes.Say("Valid commands are"))
			Eventually(buffer).Should(gbytes.Say("Thanks for playing"))
		})
	})

	Context("with valid input", func() {
		It("starts up", func() {
			commandSequence("q")

			gamer.Play()