summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-24 10:01:53 -0400
committerdemo <demo@antix1>2026-05-24 10:01:53 -0400
commit67e7ebf8c507f2f02cff0866e3ccf48032f20b16 (patch)
tree09f29379b0d042d9e7ca73c67a8cb9d3ffdd67d7
parent8a58972359906787fdd612246d220c2ffe0b0974 (diff)
refactor: move game code into testable function
-rw-r--r--main.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/main.go b/main.go
index 7e2180a..c812764 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,10 @@ func main() {
numSecs := flag.Int("s", 1, "Number of seconds game should last")
flag.Parse()
+ game(*numSecs)
+}
+
+func game(numSecs int) {
table := make(chan Ball)
go player("ping", table)
go player("pong", table)
@@ -19,7 +23,7 @@ func main() {
table <- Ball{}
// Make the game last this long.
- time.Sleep(time.Duration(*numSecs) * time.Second)
+ time.Sleep(time.Duration(numSecs) * time.Second)
// Game over: grab the ball.
<-table