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() }
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" I "github.com/trayo/go_mastermind/interfaces" "github.com/trayo/go_mastermind/print" . "github.com/trayo/go_mastermind/game" ) var _ = Describe("playing a game", func() { var ( stdin *bytes.Buffer stdinReader *bufio.Reader buffer *gbytes.Buffer printer print.Printer gamer I.Gamer commandSequence = func(args ...string) { stdin.WriteString(strings.Join(args, "\n")) } ) BeforeEach(func() { stdin = &bytes.Buffer{} stdinReader = bufio.NewReader(stdin) buffer = gbytes.NewBuffer() printer = print.NewPrinter(buffer) gamer = NewGamer(stdinReader, printer) })