请教一个go语言编程中的问题

LiuTheTutor · · 171 次点击 · 开始浏览    置顶
正在学习一个go语言写的仿吃豆人的小程序,如下: https://github.com/gophergala/golab 在其ctrl/engine.go文件中,遇到一点疑问 ```go func simulate() { t := time.Now().UnixNano() for { // Check if we have to start a new game select { case <-model.NewGameCh: initNew() default: } // First erase target images. We have to do this before handling mouse clicks // as they may change the target positions eraseDrawTargetPoss(true) // Process mouse clicks clickLoop: for { select { case click := <-model.ClickCh: handleClick(click) default: break clickLoop } } // Next clear moving objects from the lab image: model.Gopher.EraseImg() for _, bd := range model.Bulldogs { bd.EraseImg() } model.DrawImgAt(model.ExitImg, model.ExitPos.X, model.ExitPos.X) if !model.Dead { // Draw target positions eraseDrawTargetPoss(false) } now := time.Now().UnixNano() dt = float64(now-t) / 1e9 // Now step moving objects stepGopher() stepBulldogs() // Check if Gopher reached the exit point if int(model.Gopher.Pos.X) == model.ExitPos.X && int(model.Gopher.Pos.Y) == model.ExitPos.Y { handleWinning() } t = now // Sleep some time. // Iterations might not be exact, but we don't rely on it: // We calculate delta time and calculate moving and next positions // based on the delta time. model.Mutex.Unlock() // While sleeping, clients can request view images if model.Won { // If won, nothing has to be done, just wait for a new game signal <-model.NewGameCh // Blocking receive // Send back value to detect it at the proper place model.NewGameCh <- 1 } time.Sleep(time.Millisecond * 50) // ~20 FPS model.Mutex.Lock() // We will modify model now, labyrinth image might change so lock. time.Sleep(time.Millisecond * time.Duration(LoopDelay)) model.Mutex.Lock() // We will modify model now, labyrinth image might change so lock. } } ``` 我的疑问在于clickLoop后面的这个for循环, 在某个时间段,处理完所有的click之后,这个循环不是会退出么?如果退出了,如何再次进入这个循环,再次收集鼠标点击的操作?

有疑问加站长微信联系

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:812540095

171 次点击  
加入收藏 微博
1 回复  |  直到 2020-07-06 17:00:32
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传