Vim script で数当てゲームを作った


Vim script の勉強ということで、数当てゲームを作ってみた。プラグイン作成までの道のりは長い…。

let n = 9
let temp = matchend(reltimestr(reltime()), '\d\+\.') + 1
let b:answer = reltimestr(reltime())[temp : ] % (n + 1)
function! WaitUserInput()
let l:userInput = input("数字を入力してください: ")
if match(l:userInput, "^\\d\\+$") == -1
call WaitUserInput()
endif
if b:answer == l:userInput
redraw
echo "あたり!正解は" . b:answer
elseif b:answer < l:userInput
echo l:userInput . "より小さいです\r"
call WaitUserInput()
elseif b:answer > l:userInput
echo l:userInput . "より大きいです\r"
call WaitUserInput()
endif
endfunction
call WaitUserInput()

hoge.vim などと適当なファイルに保存して、:so hoge.vim で実行されます。

参考サイト

カテゴリー: Vim   パーマリンク

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>