Skip to content

Instantly share code, notes, and snippets.

@do0m-nametaken
Created August 23, 2024 04:33
Show Gist options
  • Save do0m-nametaken/ee6f0b57dc31d3dd0dcd2b617786e3a6 to your computer and use it in GitHub Desktop.
Save do0m-nametaken/ee6f0b57dc31d3dd0dcd2b617786e3a6 to your computer and use it in GitHub Desktop.
Word memory game (same game seen in humanbenchmark.com) in Batch made in Nov. 6, 2021
:beginning
@echo off
setlocal EnableDelayedExpansion
if not exist wordlist.txt goto:nolist
if exist rememberedwords.temp if exist gameinfo.temp goto:foundgame
:menu
cls
echo Sean's Word memory game
echo [1] Normal game (3 lives)
echo [2] Custom lives
choice /c 12 /n
if %ERRORLEVEL% equ 1 set lives=3&goto:startgame
if %ERRORLEVEL% equ 2 goto:custom
goto:menu
:nolist
cls
echo wordlist.txt Not found!
echo To continue you have to make a list of words in a text file named "wordlist.txt"
echo It can be anything with any amount
echo.
echo Press any key to retry...
pause>nul
goto:beginning
:foundgame
cls
echo Found an existing game
echo [Q] continue game
echo [E] Delete and start a new game
choice /c QE /n
if %ERRORLEVEL% equ 1 goto:continuegame
if %ERRORLEVEL% equ 2 goto:foundnewgame
:continuegame
set "curline=1"
for /f "delims=" %%a in (gameinfo.temp) do (
if !curline!==1 set "lives=%%a"
if !curline!==2 set "score=%%a"
set /a "curline+=1"
)
cls
echo Reading wordlist.txt...
for /f %%h in (wordlist.txt) do (
set /a "words+=1"
set "wordseen_%%h=1"
)
echo Found words: %words%
echo.
pause
goto:start
:foundnewgame
cls
del rememberedwords.temp
del gameinfo.temp
goto:menu
:custom
set dum=
if not defined lives set lives=NOT_DEFINED
cls
echo Use "start" to start game
echo Lives = %lives%
set /p input=
if /i %input%==start goto:startgame
for /f "delims=0123456789" %%d in ("%input%") do set dum=%%d
if defined dum (
cls
echo INVALID INPUT:
echo %input%
echo.
pause
goto:custom
)
set "lives=%input%"
goto:custom
:startgame
if exist rememberedwords.temp del rememberedwords.temp
set score=0
set words=0
cls
echo Reading wordlist.txt...
for /f %%h in (wordlist.txt) do set /a "words+=1"
echo Found words: %words%
echo.
pause
setlocal EnableDelayedExpansion
:start
for /f %%a in (wordlist.txt) do (
set /a "rand=(!RANDOM!*%words%/32768)+1"
if !rand! equ %words% set "curword=%%a" & goto:start2
)
goto:start
:start2
cls
echo Lives:
echo %lives%
echo.
echo Score:
echo %score%
echo.
echo Word:
echo %curword%
if defined mistake (echo.&echo INCORRECT:&echo %mistake% & set "mistake=") else (echo.&echo.&echo.)
echo.
echo [Q] New
echo [P] Seen
choice /c QP /n >nul
set what=new
if !wordseen_%curword%! equ 1 set what=seen
:start3
if %ERRORLEVEL% equ 1 set ifwhat=new
if %ERRORLEVEL% equ 2 set ifwhat=seen
if not %ifwhat%==%what% goto:lose
if %what%==new (
if not !wordseen_%curword%! equ 1 echo %curword%>>rememberedwords.temp & set wordseen_%curword%=1
)
(
echo %lives%
echo %score%
)>gameinfo.temp
set /a score+=1
goto:start
:lose
set /a lives-=1
if %lives% gtr 0 set "mistake=It was %what%" & goto:start
if exist rememberedwords.temp del rememberedwords.temp
if exist gameinfo.temp del gameinfo.temp
cls
echo Incorrect!
echo It was %what%!
echo.
echo Word:
echo %curword%
echo.
echo Score:
echo %score%
pause
goto:menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment