T3RRYT3RR0R

Minesweeper

Jan 25th, 2021 (edited)
482
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off & CD "%~dp0"
  2. ::::::::::::::::::: Requires Game_EngineDEBUG.bat by T3RRY to run. Filename: Minesweeper.bat
  3. ::: OS Requirement: Windows 10
  4. ::: [ * Author: T3RRY * ] Creation Date - 25/01/2021
  5. :::     Version 1.3
  6. ::: Added: Sweep on selection of cell with 0 neigbouring mines; clear surrounding empty cells.
  7. ::: Corrected: Sweep overwriting of previously known safe cells or user flagged cells.
  8.  Call Game_EngineDebug.bat /Q /N 10 2> nul || (
  9.   Echo/Requires Game_EngineDEBUG.bat by T3RRY to run.
  10.   Available for download from: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
  11.   Pause
  12.   Exit /B 0
  13.  )
  14. Set lvl=1
  15.  TITLE Minesweeper by T3RRY. [E]xit
  16.  Setlocal EnableDelayedExpansion
  17.  %Play.Music%{%~dp0components\synth-loop.wav}{100}{1}
  18.  %Monitor.Game%
  19.  Endlocal
  20. :start
  21.  CLS
  22.  Setlocal EnableExtensions EnableDelayedExpansion
  23.  %background.Border%{48;2;120;90;0}{10}{25}{1}{10}{@}{-1}
  24.  Set /A .Yi=.Ymax-1,.Ym=.Ymin+1,info=.Ymax+2,.Xi=.Xmax-1,.Xm=.Xmin+1,.Yo=.Ymax+1,safe=0,mines=0
  25.  %Update.Background%
  26.   (For /L %%Y in (!.Ym! 1 !.Yi!)Do For /L %%X in (!.Xm! 1 !.Xi!)Do (
  27.    <nul Set /P "=%\E%[%%Y;%%XH%\E%[90m%\E%!!%\E%[0m"
  28.    Set /A mine=!Random! %%5 + 1
  29.    If !mine!==2 (
  30.     Set /A mines+=1
  31.     If %%X LSS 10 (
  32.      Set "}%%Y;%%X=%\E%[%%Y;%%XH%\E%!!%%!!%%X0m%\E%!!%%!!%%X0mX"
  33.     ) Else (
  34.      Set "}%%Y;%%X=%\E%[%%Y;%%XH%\E%!!%%!!%%X0m%\E%!!%%!!%%Y0mX"
  35.     )
  36.    )Else (Set /A "safe+=1")
  37.   )) >%Background%
  38.  Type %Background%
  39.  Set /A .Xm-=.Xmin,.Xi-=.Xmin,.Ym-=.Ymin,.Yi-=.Ymin
  40.  :loop
  41.  <nul Set /P "=%\E%[!info!;1H%\E%[K%\E%[33mSafe moves: %\E%[32m!safe! %\E%[33mMines: %\E%[31m!mines!%\E%[0m"
  42.  Set /A ".Yp=1,.Xp=1,.Pco=1"
  43.  Set /P ".Yp=%\E%[!.Yo!;1H%\E%[K%\E%[33mEnter Y [%\E%[36m!.Ym!-!.Yi!%\E%[33m]: %\E%[0m"
  44.  Echo/!.Yp!#|Findstr.exe /RX "[Ee#]*" > nul && Goto :end
  45.  Echo/!.Yp!#|Findstr.exe /RX "[0123456789#]*" > nul || Goto :loop
  46.  Set /P ".Xp=%\E%[!.Yo!;1H%\E%[K%\E%[36mEnter X [%\E%[33m!.Xm!-!.Xi!%\E%[36m]: %\E%[0m"
  47.  Echo/!.Xp!#|Findstr.exe /RX "[Ee#]*" > nul && Goto :end
  48.  Echo/!.Xp!#|Findstr.exe /RX "[0123456789#]*" > nul || Goto :loop
  49.  Set /A ".Xp+=.Xmin,.Yp+=.Ymin" 2> nul
  50.  If !.Yp! GEQ !.Ymax! Goto :loop
  51.  If !.Xp! GEQ !.Xmax! Goto :loop
  52.  If !.Yp! LEQ !.Ymin! Goto :loop
  53.  If !.Xp! LEQ !.Xmin! Goto :loop
  54.  <nul Set /P "=%\E%[!.Yp!;!.Xp!H%\E%[7;35m %\E%[0m"
  55.  <nul Set /P "=%\E%[!.Yo!;1H%\E%[K%\E%[33m[%\E%[36mF%\E%[33m]lag [%\E%[36mC%\E%[33m]onfirm [%\E%[36mB%\E%[33m]ack%\E%[0m"
  56.  For /F "Delims=" %%C in ('Choice /N /C:FCBE')Do If "%%C"== "C" (
  57.   For %%z in ("!.Yp!;!.Xp!")Do If "!}%%~z:~-1!" == "X" (
  58.    %Play.Music%{%~dp0components\backfire.wav}{100}{0}
  59.    %Update.Background%
  60.    <nul Set /P "=%\E%[%%~zH%\E%[7;1;31mB%\E%[0m"
  61.    <nul Set /P "=%\E%[!.Yo!;1H"
  62.    Timeout /T 3 /Nobreak > nul
  63.    Pause
  64.    Endlocal
  65.    Goto :Start
  66.   )Else (
  67.    Set /A "safe-=1"
  68.    For %%o in (".ne" ".nw" ".se" ".sw" ".no" ".ea" ".we" ".so")Do Set "%%~o="
  69.    Set /A .no=.Yp-1,.so=.Yp+1,.ea=.Xp+1,.we=.Xp-1"
  70.    Set ".se=!.so!;!.ea!"
  71.    Set ".sw=!.so!;!.we!"
  72.    Set ".ne=!.no!;!.ea!"
  73.    Set ".nw=!.no!;!.we!"
  74.    For %%o in (".no" ".so" )Do For %%v in ("!%%~o!")Do Set "%%~o=!}%%~v;%.Xp%!"
  75.    For %%o in (".ea" ".we" )Do For %%v in ("!%%~o!")Do Set "%%~o=!}%.Yp%;%%~v!"
  76.    For %%o in (".ne" ".nw" ".se" ".sw")Do For %%v in ("!%%~o!")Do If "!}%%~v:~-1!" == "X" (Set "%%~o=!}%%~v!")Else (Set "%%~o=")
  77.    Set ".Pco=0"
  78.    For %%o in (".ne" ".nw" ".se" ".sw" ".no" ".ea" ".we" ".so")Do If Not "!%%~o!" == "" (
  79.     If "!%%~o:~-1!" == "X" ( Set /A ".Pco+=1" )
  80.    )
  81.    Set "}!.Yp!;!.Xp!=%\E%[!.Yp!;!.Xp!H%\E%[7;32m!.Pco!%\E%[0m"
  82.    <nul Set /P "=%\E%[!.Yp!;!.Xp!H%\E%[7;32m!.Pco!%\E%[0m"
  83.    If !safe! EQU 0 (
  84.     <nul Set /P "=%\E%[!info!;1H%\E%[K%\E%[32mYou Won^^^!%\E%[0m"
  85.     Goto :end
  86.    )
  87.   )
  88.  )Else If "%%C" == "F" (
  89.   <nul Set /P "=%\E%[!.Yp!;!.Xp!H%\E%[7;33m?%\E%[0m"
  90.   For %%v in ("!.Yp!;!.Xp!")Do if not "!}%%~v:~-1!" == "X" (
  91.    Set "}%%~v=%\E%[!.Yp!;!.Xp!H%\E%[7;33m?%\E%[0m"
  92.   )
  93.  )Else If "%%C" == "B" (
  94.   <nul Set /P "=%\E%[!.Yp!;!.Xp!H%\E%[90m%\E%[48;2;20;20;40m?%\E%[0m"
  95.  )Else If "%%C" == "E" Goto :end
  96.  IF "!.Pco!" == "0" (
  97.   %Play.Music%{%~dp0components\collectcoin.wav}{100}{0}
  98.   For %%o in ("p.ne" "p.nw" "p.se" "p.sw" "p.no" "p.ea" "p.we" "p.so")Do Set "%%~o="
  99.   For %%p in (".ne" ".nw" ".se" ".sw" ".no" ".ea" ".we" ".so")Do If "!%%~p!" == "" (
  100.    Set /A p.no=.Yp-1,p.so=.Yp+1,p.ea=.Xp+1,p.we=.Xp-1"
  101.    Set "p.se=!p.so!;!p.ea!"
  102.    Set "p.sw=!p.so!;!p.we!"
  103.    Set "p.ne=!p.no!;!p.ea!"
  104.    Set "p.nw=!p.no!;!p.we!"
  105.    For %%o in ("p.no" "p.so" )Do For %%v in ("!%%~o!")Do Set "%%~o=%%~v;!.Xp!"
  106.    For %%o in ("p.ea" "p.we" )Do For %%v in ("!%%~o!")Do Set "%%~o=!.Yp!;%%~v!"
  107.    For %%v in ("!p%%~p!")Do if "!}%%~v!" == "" If not "!}%%~v:~-1!" == "!.Char!" (
  108.     <nul Set /P "=%\E%[!p%%~p!H%\E%[7;32m☺%\E%[0m"
  109.     Set "}%%~v=%\E%[%%~vH%\E%[7;32m☺%\E%[0m"
  110.    )
  111.   )
  112.  )
  113.  Goto :loop
  114.  :end
  115.  Timeout /T 2 /Nobreak > nul
  116.  %Stop.Music:running=%
  117.  Exit /B 0
RAW Paste Data