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

dojo7 [課題3-1] タイピングゲームを作ろう #33

Open
wants to merge 4 commits into
base: kadai2-asuke-yasukuni
Choose a base branch
from

Conversation

asuke-yasukuni
Copy link

課題3-2が重いため、かなり簡素な感じにしました。
インターフェースの概念に慣れてないせいで、チャネルが絡むテストを書くのが以外に難しかったです。

最終的には割とちゃんと書けた気がします(気がするだけかもしれない)。

回答

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

Input() <-chan string
}

type Reader struct{}
Copy link
Member

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.

確かに


type Reader struct{}

func (r *Reader) Input() <-chan string {
Copy link
Member

Choose a reason for hiding this comment

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

empty structの場合はレシーバポインタにしちゃうとポインタ分スタックにメモリを確保するので func (Reader) Input <-chan stringのようにしておくと良さそう

Copy link
Author

Choose a reason for hiding this comment

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

おお、なるほど、そういう書き方が。


go func() {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
Copy link
Member

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.

あー。 s.Err() で取れるのか。


type Writer struct{}

func (w Writer) Output(outputText string) {
Copy link
Member

Choose a reason for hiding this comment

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

func (Writer)

func (r *Reader) Input() <-chan string {
ch := make(chan string)

go func() {
Copy link
Member

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.

おふ。。

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

Successfully merging this pull request may close these issues.

2 participants