Skip to content

Commit 45fb69a

Browse files
committed
add typing game
1 parent d334295 commit 45fb69a

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM golang:1
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
12+
# this user's GID/UID must match your local user UID/GID to avoid permission issues
13+
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
14+
# https://aka.ms/vscode-remote/containers/non-root-user for details.
15+
ARG USERNAME=vscode
16+
ARG USER_UID=1000
17+
ARG USER_GID=$USER_UID
18+
19+
# Configure apt, install packages and tools
20+
RUN apt-get update \
21+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
22+
#
23+
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
24+
&& apt-get -y install git iproute2 procps lsb-release \
25+
#
26+
# Install gocode-gomod
27+
&& go get -x -d github.com/stamblerre/gocode 2>&1 \
28+
&& go build -o gocode-gomod github.com/stamblerre/gocode \
29+
&& mv gocode-gomod $GOPATH/bin/ \
30+
#
31+
# Install Go tools
32+
&& go get -u -v \
33+
github.com/mdempsky/gocode \
34+
github.com/uudashr/gopkgs/cmd/gopkgs \
35+
github.com/ramya-rao-a/go-outline \
36+
github.com/acroca/go-symbols \
37+
github.com/godoctor/godoctor \
38+
golang.org/x/tools/cmd/guru \
39+
golang.org/x/tools/cmd/gorename \
40+
github.com/rogpeppe/godef \
41+
github.com/zmb3/gogetdoc \
42+
github.com/haya14busa/goplay/cmd/goplay \
43+
github.com/sqs/goreturns \
44+
github.com/josharian/impl \
45+
github.com/davidrjenni/reftools/cmd/fillstruct \
46+
github.com/fatih/gomodifytags \
47+
github.com/cweill/gotests/... \
48+
golang.org/x/tools/cmd/goimports \
49+
golang.org/x/lint/golint \
50+
golang.org/x/tools/cmd/gopls \
51+
github.com/alecthomas/gometalinter \
52+
honnef.co/go/tools/... \
53+
github.com/golangci/golangci-lint/cmd/golangci-lint \
54+
github.com/mgechev/revive \
55+
github.com/derekparker/delve/cmd/dlv 2>&1 \
56+
#
57+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
58+
&& groupadd --gid $USER_GID $USERNAME \
59+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
60+
# [Optional] Add sudo support
61+
&& apt-get install -y sudo \
62+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
63+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
64+
#
65+
# Clean up
66+
&& apt-get autoremove -y \
67+
&& apt-get clean -y \
68+
&& rm -rf /var/lib/apt/lists/*
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
2+
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/go
3+
{
4+
"name": "Go",
5+
"dockerFile": "Dockerfile",
6+
"runArgs": [
7+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
8+
// new files getting created as root, but you may need to update the USER_UID
9+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
10+
// "-u", "vscode",
11+
12+
"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
13+
],
14+
15+
// Use 'settings' to set *default* container specific settings.json values on container create.
16+
// You can edit these settings after create using File > Preferences > Settings > Remote.
17+
"settings": {
18+
"terminal.integrated.shell.linux": "/bin/bash",
19+
"go.gopath": "/go"
20+
},
21+
22+
// Uncomment the next line if you want to publish any ports.
23+
// "appPort": [],
24+
25+
// Uncomment the next line to run commands after the container is created.
26+
// "postCreateCommand": "go version",
27+
28+
// Add the IDs of extensions you want installed when the container is created in the array below.
29+
"extensions": [
30+
"ms-vscode.go"
31+
]
32+
}

kadai3/imura81gt/typ/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/gopherdojo/dojo7/kadai3/imura81gt/typ/typing"
4+
5+
func main() {
6+
typing.Run()
7+
}

kadai3/imura81gt/typ/typing/typing.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package typing
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"io"
7+
"math/rand"
8+
"os"
9+
"time"
10+
)
11+
12+
func input(r io.Reader) <-chan string {
13+
ch := make(chan string)
14+
go func() {
15+
s := bufio.NewScanner(r)
16+
for s.Scan() {
17+
ch <- s.Text()
18+
}
19+
if err := s.Err(); err != nil {
20+
fmt.Fprintln(os.Stderr, err)
21+
return
22+
}
23+
close(ch)
24+
}()
25+
return ch
26+
}
27+
28+
func load() string {
29+
var ws = []string{"すもも", "もも"}
30+
rand.Seed(time.Now().UnixNano())
31+
w1 := ws[rand.Intn(len(ws))]
32+
w2 := ws[rand.Intn(len(ws))]
33+
w3 := ws[rand.Intn(len(ws))]
34+
35+
return fmt.Sprintf("%sも%sも%sのうち", w1, w2, w3)
36+
}
37+
38+
// Run is a function to start typing-game.
39+
func Run() {
40+
const (
41+
limit = 60
42+
interval = 10
43+
)
44+
chi := input(os.Stdin)
45+
46+
var score int
47+
var chars int
48+
49+
txt := load()
50+
51+
B:
52+
for {
53+
fmt.Println(score, chars, ">", txt)
54+
fmt.Print(score, chars, " > ")
55+
select {
56+
case v := <-chi:
57+
if txt == v {
58+
fmt.Println("GOOD!!!")
59+
score++
60+
chars = chars + len([]rune(txt))
61+
txt = load()
62+
} else {
63+
fmt.Println("BAD....")
64+
}
65+
case <-time.After(limit * time.Second):
66+
fmt.Println()
67+
fmt.Println("Time up!")
68+
fmt.Println("Score:", score, "points!", chars, "charactors!")
69+
break B
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)