Ejemplo n.º 1
0
func (g Gamer) Play(args ...string) {
	var (
		in              string
		c               *check.Check
		guesses         int
		continuePlaying = true
	)

	if len(args) > 0 {
		c = check.NewCheck(args[0])
	} else {
		c = check.NewCheck()
	}

	g.printer.GameStart()

	for continuePlaying {
		g.printer.EnterAGuess()
		in = input.GetInput(g.stdin)
		switch {
		case input.WantsToQuit(in):
			continuePlaying = false
		case !input.Valid(in):
			g.printer.UnknownGameCommand()
		default:
			c.Guess(in)
			g.printer.CorrectColorsAndPositions(c.CorrectColors, c.CorrectPositions)
			guesses++
			if c.Won() {
				g.printer.YouWon(guesses)
				continuePlaying = false
			}
		}
	}

	g.printer.ThanksForPlaying()
}
Ejemplo n.º 2
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()
}