Skip to content

[WIP] 課題3-1 takami228 #44

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kadai3-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 課題3-1

* タイピングゲームを作ろう
* 標準出力に英単語を出す(出すものは自由)
* 標準入力から1行受け取る
* 制限時間内に何問解けたか表示する
47 changes: 47 additions & 0 deletions kadai3-1/typegame/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"bufio"
"fmt"
"io"
"os"
"time"
)

func input(r io.Reader) <-chan string {
ch := make(chan string)
go func() {
s := bufio.NewScanner(r)
for s.Scan() {
ch <- s.Text()
}
close(ch)
}()
return ch
}

func main() {
ch := input(os.Stdin)

chanIsFinish := make(chan bool)
go func() {
time.Sleep(time.Second * 3)
chanIsFinish <- true
}()

for {
fmt.Print(">")
var isFinished = false

select {
case isFinished = <-chanIsFinish:
fmt.Println("FINISHED!")
case res := <-ch:
fmt.Println(res)
}

if isFinished {
break
}
}
}