LoginSignup
4
5

More than 5 years have passed since last update.

.batでタイピングゲーム

Last updated at Posted at 2015-03-04

 どうもです。batでタイピングゲームを作りました。

 簡単な英単語のタイピングです。時間を競います。単語数は1365。ですが、自分専用の単語集を作ることができます。

 バッチファイルの中身を掲載しておきますが、このバッチファイルは単体では動作しません、いろんなファイルが必要です。なので、axfcアップローダにフォルダをあげておきます。良かったら遊んでやってください。

 今は表示された単語を入力するただのタイピングですが、そのうち日本語⇔英語の高校生向けテスト対策バッチ(笑)でも作る予定です。

typing.bat
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion
title タイピングゲーム

:start
for /f "delims=" %%i in ('findstr /b [0-9] %cd%\score.txt') do set best=%%i
set /a bestsec=best/100
set /a bestms=best%%100
set que=0
set r=0
set w=0
for /f "delims=" %%i in ('findstr A %cd%\option.txt') do set temp1=%%i
set question=%temp1:~4%
for /f "delims=" %%i in ('findstr B %cd%\option.txt') do set temp2=%%i
set original=%temp2:~4%
for /f "delims=" %%i in ('findstr C %cd%\option.txt') do set temp3=%%i
set line=%temp3:~4%
set loop=0
set usedb=13
if %original% == 1 set usedb=14
if %original% == 2 set usedb=1
cls
echo タイピングゲーム
echo.
echo  1…start
echo  0…setting
choice /c 10 /n
if %errorlevel% == 1 goto top
start /wait %cd%\option.txt
cls
echo トップに戻ります。
timeout /t 2 /nobreak >nul
goto start


:top
cls
echo 準備中...
set /a loop+=1
set /a dbnum=(%random%*usedb/32768)+1
set /a num=(%random%*line/32768)+1
set count=1
if %original% == 2 set dbnum=14
for /f %%n in (%cd%\database\DB%dbnum%.txt) do (
call :check %%n
set /a count+=1
)

:check
if %count% == %num% set sentence=%1& goto setting
exit /b

:setting
set q%loop%=%sentence%
if %question% == %loop% (
call :wait
call :btime
goto ans
)
goto top

:ans
cls
set /a que+=1
echo Q%que%.【!q%que%!】
set /p input="入力> "
set a%que%=%input%
if "!q%que%!" == "%input%" goto right
goto wrong

:right
set /a r+=1
set j%que%=〇
if %que% == %question% goto fin
goto ans

:wrong
set j%que%=×
if %que% == %question% goto fin
goto ans

:fin
cls
call :etime
if %elapse% lss %best% (set renewal=1) else (set renewal=0)
echo  正解数 :%r%問(%question%問中)
echo 経過時間:%diffsec%.%diffms%秒
echo 過去最高:%bestsec%.%bestms%秒
echo.
if %renewal% == 1 (
echo ベストスコア更新!
echo.
echo %elapse% >%cd%\score.txt
)
set loop=0
call :finloop
pause >nul
goto start

:finloop
set /a loop+=1
set echoque=%loop%
if %loop% leq 9 set echoque=0%loop%
echo Q%echoque%...!j%loop%! 【!q%loop%!→!a%loop%!】
if %loop% == %question% exit /b
goto finloop

:btime
for /f "tokens=1,2,3,4 delims=:." %%a in ("%time%") do (
  set hour=1%%a
  set min=1%%b
  set sec=1%%c
  set ms=1%%d
  set /a hour-=100
  set /a min-=100
  set /a sec-=100
  set /a ms-=100
  set /a begin=hour*360000+min*6000+sec*100+ms
)
exit /b

:etime
for /f "tokens=1,2,3,4 delims=:." %%a in ("%time%") do (
  set hour=1%%a
  set min=1%%b
  set sec=1%%c
    set ms=1%%d
  set /a hour-=100
  set /a min-=100
  set /a sec-=100
  set /a ms-=100
  set /a end=hour*360000+min*6000+sec*100+ms
)
set /a elapse=end-begin
set /a diffsec=elapse/100
set /a diffms=elapse%%100


exit /b

:wait
cls
echo タイピングゲームを始めます。何かキーを押してください。
echo.
echo  問題数:%question%問
if %original% geq 1 (echo  オリジナル問題あり) else (
echo  オリジナル問題なし)
echo  過去最高:%bestsec%.%bestms%秒

pause >nul
cls
echo 3秒前...
choice /d y /n /t 1 >nul
echo 2秒前...
choice /d y /n /t 1 >nul
echo 1秒前...
choice /d y /n /t 1 >nul
exit /b

DLはここから。

以上です。不具合・感想などありましたら、是非コメントにて。

4
5
0

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
4
5