Esempio n. 1
0
func (g Game) Play() {
	var input string = ""
	var err error = nil
	var score int64 = 0
	i := 0

	fmt.Printf("%s goes first!\n", g.Players[i].Name)
	for {
		fmt.Printf("%s scored: ", g.Players[i].Name)

		input = reader.GetString(os.Stdin)
		if input == "done" {
			break
		}

		score, err = strconv.ParseInt(input, 0, 0)

		if err != nil {
			fmt.Printf("Uh oh! There was a problem with that input: %s\n", err)
			os.Exit(1)
		}

		g.Players[i].IncreaseScore(int(score))

		i = (i + 1) % len(g.Players)
	}
}
Esempio n. 2
0
func CreatePlayers(n int) Players {
	players := make(Players, n)

	for i := 0; i < n; i++ {
		fmt.Printf("Name of player %d: ", i+1)
		players[i] = Player{reader.GetString(os.Stdin), 0}
	}

	return players
}
Esempio n. 3
0
func main() {
	fmt.Println("Let's Go Scrabble!")
	fmt.Print("How many players? ")

	numPlayers, err := strconv.ParseInt(reader.GetString(os.Stdin), 0, 0)

	if err != nil {
		fmt.Printf("There was an issue with getting the number of players: %s\n", err)
		os.Exit(1)
	}

	if numPlayers < 2 {
		fmt.Println("Please play with more people than that.")
		os.Exit(1)
	}

	players := player.CreatePlayers(int(numPlayers))
	g := game.Game{Players: players}
	g.ShufflePlayers()
	g.Play()
	g.Finish()
}