/* ---------------- Phase 10 Tracker ---------------- This program helps the user keep track of a game of Phase 10 as it is being played. It will keep track of players and their scores over the course of the game, inferring which phase they are on based on their score. To use the program, first you will input the first names of all of the players, seperated by spaces. Then, after each round is finished, you will enter the score of each player's hand, again seperated by spaces and in the same order that the names were supplied. */ package phase10 import "core:fmt" import "core:os" import "core:strings" import "core:strconv" // Return a slice of space delimited strings from stdin getSpaceDelimetedItems :: proc(backingBuffer: []byte) -> []string { count, _ := os.read(os.stdin, backingBuffer) response := string(backingBuffer[:count - 1]) // leave off the newline items, _ := strings.split(response, " ") return items } // Prompt user for names of all players getNames :: proc(backingBuffer: []byte) -> []string { fmt.print("Enter Names: ") return getSpaceDelimetedItems(backingBuffer) } // Prompt user to enter scores for each player addScores :: proc(game: ^Game) { buf: [2048]byte fmt.print(" ") for name in game.names { fmt.print(name, "") } fmt.println() fmt.print("Scores: ") newScores := getSpaceDelimetedItems(buf[:]) defer delete(newScores) for score, index in newScores { intScore, _ := strconv.parse_int(score) append(&(game.scores[index]), intScore) } } main :: proc() { // Prompt for names buf: [2048]byte names := getNames(buf[:]) defer delete(names) // Show names to user for name in names { fmt.println("Name:", name) } // Create game game: Game for name in names { if name == "hayden" { addPlayer(&game, name, phase = 10, score = 40) } else { addPlayer(&game, name) } } defer deleteGameData(&game) // Clean up game data // Main loop of adding scores fmt.println(game) winner: string for winner == "" { addScores(&game) updatePhases(&game) fmt.println(game) winner = checkWinner(&game) } fmt.println("The winner is:", winner) }