Skip to content

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

Open
asuke-yasukuni wants to merge 4 commits into
kadai2-asuke-yasukunifrom
kadai3-asuke-yasukuni
Open

dojo7 [課題3-1] タイピングゲームを作ろう#33
asuke-yasukuni wants to merge 4 commits into
kadai2-asuke-yasukunifrom
kadai3-asuke-yasukuni

Conversation

@asuke-yasukuni

Copy link
Copy Markdown

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

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

回答

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

Input() <-chan string
}

type Reader struct{}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

こうかいしなくても良さそう

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

エラー処理

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

タイムアウトした際にこのゴールーチンが終了しなさそう。

Copy link
Copy Markdown
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