LoginSignup
48

More than 5 years have passed since last update.

Go言語でpongコマンドを実装する

Last updated at Posted at 2015-04-21

pong.gif

はい。出オチです。

実行ファイルはこちら(WIndows,OSX,CentOS向けを用意)
https://github.com/kurehajime/pong-command/releases/tag/0.2

ソースはこちら
https://github.com/kurehajime/pong-command

中身補足

termbox-goというライブラリを利用してGUI風CUIを実現しています。

こんな感じでキーイベント拾えます。


for {
    switch ev := termbox.PollEvent(); ev.Type {
    case termbox.EventKey:
        switch ev.Key {
        case termbox.KeyEsc:
            //Escキー押した時の処理
        case termbox.KeyArrowUp:
            //上キー押した時の処理
        case termbox.KeyArrowDown:
            //下キー押した時の処理
        default:
        }
    default:
    }
}

こんな感じで任意の座標に文字を配置できます。


termbox.SetCell(x, y,str, FontColor, BackgroundColor)

なんだかRogueクローンが作りたくなるライブラリですね。

Go言語は並列処理がとても簡単に書けるので、この手のちょっとしたアクション要素のあるコマンドが実装しやすいです。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
48