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 yoheimiyamoto #46

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

Conversation

yoheimiyamoto
Copy link

  • 標準出力に英単語を出す(出すものは自由)
  • 標準入力から1行受け取る
  • 制限時間内に何問解けたか表示する

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.

コメントしましたので、参考にしていただければと思います

// words -> 出題するワード一覧
func Play(r io.Reader, w io.Writer, words []string) {
inputCh := make(chan string)
inputDone := make(chan struct{}, 1)
Copy link

Choose a reason for hiding this comment

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

特に値を入れていることはなさそうなので、サイズの指定は必要なさそうです

Copy link
Author

Choose a reason for hiding this comment

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

了解です。修正しましたっ

}
close(inputDone) // inputのチャネルを閉じる
fmt.Fprintln(w, "タイムアウト。ゲーム終了")
fmt.Println(s.Result())
Copy link

Choose a reason for hiding this comment

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

ここまで w io.Writer にのみ利用してきているので、ここも os.Stdout ではなく w に書き込んだほうがテストしやすさ的にも良いと思います

Copy link
Author

Choose a reason for hiding this comment

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

そうですねっ。こちらも修正しました。

fmt.Fprintln(w, "不正解!")
s.addIncorrect()
}
case <-time.After(5 * time.Second):
Copy link

Choose a reason for hiding this comment

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

一つのワード入力の 制限時間5秒 であるならばよいのですが、ゲーム自体の制限時間であれば、このforの外で time.After を実行しておかないとforに入るたびに5秒からカウントしてしまいます

Copy link
Author

Choose a reason for hiding this comment

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

こちらも修正しましたっ

}
}()

// 上記を以下のようにgoroutine使わずに記述するとゲームがフリーズしてしまう理由が理解できていないです。
Copy link

Choose a reason for hiding this comment

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

doneがcloseされるまでブロックすることになるので、inputの実行箇所でとまることになります

Copy link
Author

Choose a reason for hiding this comment

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

ありがとうございます。理解できましたっ

}()

// ゲームが終了した場合、inputも終了させる。
go func() {
Copy link

Choose a reason for hiding this comment

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

goroutineとして実行しているので、この処理自体ほとんど意味がなさそうです

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.

3 participants