package main import ( "flag" "fmt" "time" ) type Ball struct{ hits int } func main() { 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 <- Ball{} // Make the game last this long. time.Sleep(time.Duration(*numSecs) * time.Second) // Game over: grab the ball. <-table } 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 } }