From 76562ea0eb53e0ca3d6ef531453f968931e67b1c Mon Sep 17 00:00:00 2001 From: chokkoyamada Date: Sun, 9 Sep 2018 22:42:43 +0900 Subject: [PATCH 1/2] added .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4befed3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.idea From 838ba3e197a8f9ea53c7d71bc4cefa62108f8535 Mon Sep 17 00:00:00 2001 From: chokkoyamada Date: Mon, 10 Sep 2018 02:04:00 +0900 Subject: [PATCH 2/2] kadai3-1 --- kadai3-1/chokkoyamada/main.go | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 kadai3-1/chokkoyamada/main.go diff --git a/kadai3-1/chokkoyamada/main.go b/kadai3-1/chokkoyamada/main.go new file mode 100644 index 0000000..5489ac8 --- /dev/null +++ b/kadai3-1/chokkoyamada/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "fmt" + "io" + "bufio" + "os" + "time" + "math/rand" +) + +func input(r io.Reader) <-chan string { + c := make(chan string) + go func() { + s := bufio.NewScanner(r) + for s.Scan() { + c <- s.Text() + } + close(c) + }() + return c + +} + +func main() { + //制限時間 + limit := 15 + //問題の単語はこの中から毎回ランダムで抽出される + question := []string{"apple", "orange", "pine", "strawberry", "banana"} + rand.Seed(time.Now().Unix()) + + score := 0 + + fmt.Printf("タイピングゲーム開始! 表示された単語を入力してください。制限時間は%d秒です。\n", limit) + t := time.After(time.Duration(limit) * time.Second) + + ch := input(os.Stdin) + +M: + for { + s := question[rand.Intn(len(question))] + fmt.Printf(">%s\n", s) + select { + case v := <-ch: + fmt.Println(v) + if s == v { + fmt.Println("正解!") + score += 1 + } else { + fmt.Println("間違い") + } + + case <-t: + fmt.Println("タイムアップ!") + break M + } + } + + fmt.Printf("タイピングゲーム終了です。スコアは%d点です。\n", score) + +}