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

February 03, 2010category: Vim 

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 で実行されます。

参考サイト

comments (0)

comments