This is code for a game I plan on making.
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /l %%g in (0,1,15) do set board[%%g]=0
call :tilespawn
call :tilespawn
:startloop
cls
for /l %%g in (0,1,15) do echo !board[%%g]!
choice /c wasdx /n /m ""
if %errorlevel%==1 rem UP
if %errorlevel%==2 rem LEFT
if %errorlevel%==3 goto movedown
if %errorlevel%==4 rem RIGHT
:backtoloop
call :tilespawn
if %errorlevel% neq 5 goto startloop
exit /b
:tilespawn
set /a randtile=%random%%%16
if !board[%randtile%]! gtr 0 goto tilespawn
set /a board[%randtile%]=%random%%%10/9*2+2
exit /b
:movedown
set a=3
set j=0
set h=-1
set k=12
set i=0
set g=-4
:movetile
set /a d=0
set /a c=%k%
set /a b=%c%
:1
if !board[%a%+%b%]! neq 0 (
set /a e=!board[%a%+%b%]!
set /a board[%a%+%b%]=0
if %e%==%d% (
set /a board[%a%+%b%-%g%]*=2
set /a d=!board[%a%+%b%-%g%]!
) else (
set /a c+=%g%
set /a board[%c%+%a%+4]=%e%-%d%
set /a d=%e%
)
)
set /a b+=%g%
if %i% neq %b%+%g% goto 1
set /a a+=%h%
if %j% neq %a%+%h% goto movetile
goto backtoloop
Whenever I press S, it displays "< was unexpected at this time" before quitting. I don't understand where the problem is.
When I get help with the :movetile section of code (which I believe has the erroneous code), I will implement the game further. Any help would be greatly appreciated. Ask me if you want more information about the code!