Refactor
This commit is contained in:
parent
0e079d13bb
commit
68dd6d6807
18
main.odin
18
main.odin
|
|
@ -15,24 +15,6 @@
|
||||||
package phase10
|
package phase10
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:os"
|
|
||||||
import "core:strings"
|
|
||||||
|
|
||||||
// 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
|
|
||||||
strings.trim_space(response)
|
|
||||||
items, _ := strings.fields(response)
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prompt user for names of all players
|
|
||||||
getNames :: proc(backingBuffer: []byte) -> []string {
|
|
||||||
fmt.print("Enter Names: ")
|
|
||||||
return getSpaceDelimetedItems(backingBuffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
// Prompt for names
|
// Prompt for names
|
||||||
|
|
|
||||||
19
phase10.odin
19
phase10.odin
|
|
@ -1,5 +1,7 @@
|
||||||
package phase10
|
package phase10
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
import "core:strings"
|
||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:slice"
|
import "core:slice"
|
||||||
|
|
@ -32,7 +34,7 @@ addScores :: proc(game: ^Game) {
|
||||||
fmt.print("Scores: ")
|
fmt.print("Scores: ")
|
||||||
newScores := getSpaceDelimetedItems(buf[:])
|
newScores := getSpaceDelimetedItems(buf[:])
|
||||||
if len(newScores) != len(game.names) {
|
if len(newScores) != len(game.names) {
|
||||||
fmt.println("[ERROR] == Invalid number of scores")
|
fmt.println("[ERROR] Invalid number of scores")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer delete(newScores)
|
defer delete(newScores)
|
||||||
|
|
@ -114,3 +116,18 @@ printGame :: proc(game: ^Game) {
|
||||||
game.phases[index])
|
game.phases[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
strings.trim_space(response)
|
||||||
|
items, _ := strings.fields(response)
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prompt user for names of all players
|
||||||
|
getNames :: proc(backingBuffer: []byte) -> []string {
|
||||||
|
fmt.print("Enter Names: ")
|
||||||
|
return getSpaceDelimetedItems(backingBuffer)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue