Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kadai3-1 miyahara #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Kadai3-1 miyahara #51

wants to merge 2 commits into from

Conversation

hikaru7719
Copy link

  • タイピングゲームを作ろう
    • 標準出力に英単語を出す(出すものは自由)
    • 標準入力から1行受け取る
    • 制限時間内に何問解けたか表示する
      遅くなりましたが、課題3-1です。

@hikaru7719 hikaru7719 changed the title Kadai3 1 miyahara Kadai3-1 miyahara Nov 27, 2018
Copy link

@mizkei mizkei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしましたので、参考にしていただければと思います
gofmtはかけておいたほうが良いです

for s.Scan(){
select{
case <- ctx.Done():
close(ch)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これではcontextがcancelされなかった場合にcloseされないことになりますので(問題はないと思いますが)、閉じるのであれば、このfuncの最初に defer close(ch) しておいたほうが良いと思います

fmt.Println("time up")
break LOOP
default:
typedString := <-ch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultの中にこの処理を書いてしまうと、ユーザの入力があるまでここでブロックしてしまいます
その場合、 ctx.Done() を待つことができないため、制限時間を超えてもユーザが入力を終えるまではゲームが終わらず、制限時間後の最後の入力も成否を判定する対象になってしまうため、同時に待てるようにしたほうが良いと思います

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants