summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-24 09:48:20 -0400
committerdemo <demo@antix1>2026-05-24 09:48:20 -0400
commit8a58972359906787fdd612246d220c2ffe0b0974 (patch)
tree2b6c6b68f5dd1e2bc0b2488bc0e4626f98e8dc74 /main.go
parentc9c781bdc435fe19f51ae457da315c42d1c4a024 (diff)
feat: specify secs using -s + use Ball{}
Diffstat (limited to 'main.go')
-rw-r--r--main.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/main.go b/main.go
index faf3519..7e2180a 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "flag"
"fmt"
"time"
)
@@ -8,25 +9,31 @@ import (
type Ball struct{ hits int }
func main() {
- table := make(chan *Ball)
+ numSecs := flag.Int("s", 1, "Number of seconds game should last")
+ flag.Parse()
+
+ table := make(chan Ball)
go player("ping", table)
go player("pong", table)
- table <- new(Ball)
+ table <- Ball{}
// Make the game last this long.
- time.Sleep(1 * time.Second)
+ time.Sleep(time.Duration(*numSecs) * time.Second)
// Game over: grab the ball.
<-table
}
-func player(name string, table chan *Ball) {
+func player(name string, table chan Ball) {
for {
ball := <-table
ball.hits++
fmt.Println(name, ball.hits)
+
+ // Simulate some contact with the paddle.
time.Sleep(100 * time.Millisecond)
+
table <- ball
}
}