Add bounds checking for addScores
This commit is contained in:
parent
b1fc251574
commit
0e079d13bb
|
|
@ -48,7 +48,6 @@ main :: proc() {
|
|||
defer deleteGameData(&game) // Clean up game data
|
||||
|
||||
// Main game loop
|
||||
// fmt.println(game)
|
||||
printGame(&game)
|
||||
winner: int = -1
|
||||
for winner == -1 {
|
||||
|
|
@ -59,5 +58,9 @@ main :: proc() {
|
|||
winner = checkWinner(&game)
|
||||
}
|
||||
|
||||
fmt.printfln("%v wins! They had %v points!", game.names[winner], getScore(&game, winner))
|
||||
fmt.printfln(
|
||||
"%v wins! They had %v points!",
|
||||
game.names[winner],
|
||||
getScore(&game, winner)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ addScores :: proc(game: ^Game) {
|
|||
fmt.println()
|
||||
fmt.print("Scores: ")
|
||||
newScores := getSpaceDelimetedItems(buf[:])
|
||||
if len(newScores) != len(game.names) {
|
||||
fmt.println("[ERROR] == Invalid number of scores")
|
||||
return
|
||||
}
|
||||
defer delete(newScores)
|
||||
for score, index in newScores {
|
||||
intScore, _ := strconv.parse_int(score)
|
||||
|
|
@ -101,6 +105,7 @@ checkWinner :: proc(game: ^Game) -> int {
|
|||
return -1
|
||||
}
|
||||
|
||||
// Print state of the game as a nice table
|
||||
printGame :: proc(game: ^Game) {
|
||||
fmt.printf("Name\tScore\tPhase\n")
|
||||
fmt.printf("----\t-----\t-----\n")
|
||||
|
|
|
|||
Loading…
Reference in a new issue