Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- title 2048 Colorized
- mode con: cols=35 lines=13
- for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
- <nul >"%temp%\x" set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%.%DEL%"
- :startgame
- set score=0
- set winstate=0
- for /l %%g in (0,1,15) do set board[%%g]=0
- call :tilespawn
- call :tilespawn
- :startloop
- for /l %%g in (0,1,15) do set board2[%%g]= !board[%%g]!& if !board[%%g]!==0 set board2[%%g]=
- set h=-1
- :0
- set /a h+=1
- set board2[%h%]=!board2[%h%]:~-6!
- if %h% neq 15 goto 0
- set h=-1
- :00
- set /a h+=1
- if !board[%h%]!==0 set board3[%h%]=07
- if !board[%h%]!==2 set board3[%h%]=f0
- if !board[%h%]!==4 set board3[%h%]=70
- if !board[%h%]!==8 set board3[%h%]=c7
- if !board[%h%]!==16 set board3[%h%]=cf
- if !board[%h%]!==32 set board3[%h%]=47
- if !board[%h%]!==64 set board3[%h%]=4f
- if !board[%h%]!==128 set board3[%h%]=67
- if !board[%h%]!==256 set board3[%h%]=6f
- if !board[%h%]!==512 set board3[%h%]=e8
- if !board[%h%]!==1024 set board3[%h%]=e8
- if !board[%h%]!==2048 set board3[%h%]=e0
- if %h% neq 15 goto 00
- cls
- echo Score: %score%
- echo(
- echo ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄ¿
- <nul set /p=^|
- call :colorPrintVar %board3[0]% board2[0]
- <nul set /p=^|
- call :colorPrintVar %board3[1]% board2[1]
- <nul set /p=^|
- call :colorPrintVar %board3[2]% board2[2]
- <nul set /p=^|
- call :colorPrintVar %board3[3]% board2[3]
- echo ^|
- echo ÃÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´
- <nul set /p=^|
- call :colorPrintVar %board3[4]% board2[4]
- <nul set /p=^|
- call :colorPrintVar %board3[5]% board2[5]
- <nul set /p=^|
- call :colorPrintVar %board3[6]% board2[6]
- <nul set /p=^|
- call :colorPrintVar %board3[7]% board2[7]
- echo ^|
- echo ÃÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´
- <nul set /p=^|
- call :colorPrintVar %board3[8]% board2[8]
- <nul set /p=^|
- call :colorPrintVar %board3[9]% board2[9]
- <nul set /p=^|
- call :colorPrintVar %board3[10]% board2[10]
- <nul set /p=^|
- call :colorPrintVar %board3[11]% board2[11]
- echo ^|
- echo ÃÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´
- <nul set /p=^|
- call :colorPrintVar %board3[12]% board2[12]
- <nul set /p=^|
- call :colorPrintVar %board3[13]% board2[13]
- <nul set /p=^|
- call :colorPrintVar %board3[14]% board2[14]
- <nul set /p=^|
- call :colorPrintVar %board3[15]% board2[15]
- echo ^|
- echo ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÙ
- for /l %%g in (0,1,15) do set tmpboard[%%g]=!board[%%g]!
- choice /c wasdxn /n /m ""
- if %errorlevel%==1 call :rotateclockwise&call :rotateclockwise&call :rotateclockwise&call :compress&call :merge&call :compress&call :compress&call :rotateclockwise
- if %errorlevel%==2 call :compress&call :merge&call :compress&call :compress
- if %errorlevel%==3 call :rotateclockwise&call :compress&call :merge&call :compress&call :compress&call :rotateclockwise&call :rotateclockwise&call :rotateclockwise
- if %errorlevel%==4 call :rotateclockwise&call :rotateclockwise&call :compress&call :merge&call :compress&call :compress&call :rotateclockwise&call :rotateclockwise
- if %errorlevel%==5 goto end
- if %errorlevel%==6 goto startgame
- set boardchanged=0
- set tiles=0
- for /l %%g in (0,1,15) do (
- if !board[%%g]! neq !tmpboard[%%g]! set boardchanged=1
- if !board[%%g]! neq 0 set /a tiles+=1
- if !board[%%g]!==2048 if %winstate%==0 set winstate=1
- )
- if %boardchanged%==1 call :tilespawn
- if %winstate%==1 goto youwin
- set youlost=0
- set v=0
- :1
- set /a v+=1
- set /a w=%v%%%4
- set /a x=%v%/4
- set /a y=%v%-1
- set /a z=%v%-4
- if %tiles%==15 if %w% neq 0 if !board[%v%]!==!board[%y%]! set youlost=1
- if %tiles%==15 if %x% neq 0 if !board[%v%]!==!board[%z%]! set youlost=1
- if %tiles%==15 if %v% neq 15 goto 1
- if %tiles%==15 if %youlost%==0 goto youlost
- goto startloop
- :youlost
- for /l %%g in (0,1,15) do set board2[%%g]= !board[%%g]!& if !board[%%g]!==0 set board2[%%g]=
- set h=-1
- :0
- set /a h+=1
- set board2[%h%]=!board2[%h%]:~-6!
- if %h% neq 15 goto 0
- set h=-1
- :00
- set /a h+=1
- if !board[%h%]!==0 set board3[%h%]=07
- if !board[%h%]!==2 set board3[%h%]=f0
- if !board[%h%]!==4 set board3[%h%]=70
- if !board[%h%]!==8 set board3[%h%]=c7
- if !board[%h%]!==16 set board3[%h%]=cf
- if !board[%h%]!==32 set board3[%h%]=47
- if !board[%h%]!==64 set board3[%h%]=4f
- if !board[%h%]!==128 set board3[%h%]=67
- if !board[%h%]!==256 set board3[%h%]=6f
- if !board[%h%]!==512 set board3[%h%]=e8
- if !board[%h%]!==1024 set board3[%h%]=e8
- if !board[%h%]!==2048 set board3[%h%]=e0
- if %h% neq 15 goto 00
- cls
- echo Score: %score%
- echo(
- call :colorPrintVar %board3[0]% board2[0]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[1]% board2[1]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[2]% board2[2]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[3]% board2[3] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[4]% board2[4]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[5]% board2[5]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[6]% board2[6]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[7]% board2[7] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[8]% board2[8]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[9]% board2[9]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[10]% board2[10]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[11]% board2[11] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[12]% board2[12]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[13]% board2[13]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[14]% board2[14]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[15]% board2[15] /n
- echo GAME OVER!
- choice /c nx /n /m "Press N to play again..."
- if %errorlevel%==1 goto startgame
- if %errorlevel%==2 goto end
- :youwin
- set winstate=2
- for /l %%g in (0,1,15) do set board2[%%g]= !board[%%g]!& if !board[%%g]!==0 set board2[%%g]=
- set h=-1
- :0
- set /a h+=1
- set board2[%h%]=!board2[%h%]:~-6!
- if %h% neq 15 goto 0
- set h=-1
- :00
- set /a h+=1
- if !board[%h%]!==0 set board3[%h%]=07
- if !board[%h%]!==2 set board3[%h%]=f0
- if !board[%h%]!==4 set board3[%h%]=70
- if !board[%h%]!==8 set board3[%h%]=c7
- if !board[%h%]!==16 set board3[%h%]=cf
- if !board[%h%]!==32 set board3[%h%]=47
- if !board[%h%]!==64 set board3[%h%]=4f
- if !board[%h%]!==128 set board3[%h%]=67
- if !board[%h%]!==256 set board3[%h%]=6f
- if !board[%h%]!==512 set board3[%h%]=e8
- if !board[%h%]!==1024 set board3[%h%]=e8
- if !board[%h%]!==2048 set board3[%h%]=e0
- if %h% neq 15 goto 00
- cls
- echo Score: %score%
- echo(
- call :colorPrintVar %board3[0]% board2[0]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[1]% board2[1]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[2]% board2[2]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[3]% board2[3] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[4]% board2[4]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[5]% board2[5]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[6]% board2[6]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[7]% board2[7] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[8]% board2[8]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[9]% board2[9]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[10]% board2[10]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[11]% board2[11] /n
- echo ------+------+------+------
- call :colorPrintVar %board3[12]% board2[12]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[13]% board2[13]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[14]% board2[14]
- call :colorPrint 07 "|"
- call :colorPrintVar %board3[15]% board2[15] /n
- echo YOU WIN!
- echo Press C to continue
- choice /c cnx /n /m "Press N to play again"
- if %errorlevel%==1 goto startloop
- if %errorlevel%==2 goto startgame
- if %errorlevel%==3 goto end
- :tilespawn
- set /a randtile=%random%%%16
- if !board[%randtile%]! gtr 0 goto tilespawn
- set /a board[%randtile%]=%random%%%10/9*2+2
- exit /b
- :compress
- set x=-1
- :2
- set /a x+=1
- for /l %%g in (0,1,3) do set tmparray[%%g]=0
- set w=0
- set y=-1
- :3
- set /a y+=1
- set /a z=%x%*4+%y%
- if !board[%z%]! neq 0 set /a tmparray[%w%]=!board[%z%]! & set /a w+=1
- if %y% neq 3 goto 3
- for /l %%g in (0,1,3) do set /a z=%x%*4+%%g & set /a board[!z!]=!tmparray[%%g]!
- if %x% neq 3 goto 2
- exit /b
- :merge
- set x=-1
- :4
- set /a x+=1
- set y=-1
- :5
- set /a y+=1
- set /a w=%x%*4+%y%
- set /a z=%w%+1
- if !board[%w%]!==!board[%z%]! set /a board[%w%]*=2 & set board[%z%]=0 & set /a score+=!board[%w%]!
- if %y% neq 2 goto 5
- if %x% neq 3 goto 4
- exit /b
- :rotateclockwise
- set i=0
- for %%j in (12 8 4 0 13 9 5 1 14 10 6 2 15 11 7 3) do (
- set /A tmparray[!i!]=board[%%j], i+=1
- )
- for /l %%g in (0,1,15) do set /a board[%%g]=!tmparray[%%g]!
- exit /b
- :colorPrint Color Str [/n]
- setlocal
- set "str=%~2"
- call :colorPrintVar %1 str %3
- exit /b
- :colorPrintVar Color StrVar [/n]
- if not defined %~2 exit /b
- set "str=a%DEL%!%~2:\=a%DEL%\..\%DEL%%DEL%%DEL%!"
- set "str=!str:/=a%DEL%/..\%DEL%%DEL%%DEL%!"
- set "str=!str:"=\"!"
- pushd "%temp%"
- findstr /p /A:%1 "." "!str!\..\x" nul
- if /i "%~3"=="/n" echo(
- exit /b
- :end
- del "%temp%\x"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement