Introduction: Batch Game Movement (Tutorial)

Now, there are many ways to get a character in batch to move, however, in this tutorial is probably the shortest codes anyone has made.

Enjoy!

Note: Copy and paste the following code into notepad or another text-editing program and save it as movement.bat


Step 1: Code 1 (simple Movement)

@setlocal enableextensions enabledelayedexpansion
@echo off
title movement
color 0a

set length=         
set height= a

:controls
cls
echo Use WASD to move your character ([]).
echo.
for %%a in ( %height% ) do echo.
echo %length%[]
choice /c wasd /n
if %errorlevel% equ 1 call:up
if %errorlevel% equ 2 call:left
if %errorlevel% equ 3 call:down
if %errorlevel% equ 4 call:right

:left
set length=!length:~0,-1!
goto controls

:right
set length=%length%
goto controls

:up
set height=!height:~0,-2!
goto controls

:down
set height=%height% a
goto control

As you can see, the code is very small (29 lines to be exact). This, I believe, is one of the smallest anyone has made.

Feel free to use it as the basis for any games to come, also, extra points if you make pong with it.

Step 2: Code 2 (Grid Confined Movement)

In this code, your character will be confined to a "cage".

@setlocal enableextensions enabledelayedexpansion
@echo off
color 0a
title Movement 2 ~ Grid
cls
goto data

:data
set lespa=         
set rispa=         
set space=5
set err=0
set right=10
set left=10

:hud
cls
echo Move your character (X) with the WASD keys. Press R to reset
echo #######################
if %space% equ 0 if %err% neq 1 (
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 1 if %err% neq 1 (
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 2 if %err% neq 1 (
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 3 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 4 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 5 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 6 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 7 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 8 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     # )
if %space% equ 9 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     # )
if %space% equ 10 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%# )
echo #######################
echo.
echo.
choice /c wasdr /n
if %errorlevel% equ 1 goto w
if %errorlevel% equ 2 goto a
if %errorlevel% equ 3 goto s
if %errorlevel% equ 4 goto d
if %errorlevel% equ 5 goto data

:w
set /a space=%space%-1
if %space% lss 0 set space=0
goto hud

:a
set lespa=!lespa:~0,-1!
set /a left=%left%-1
if %left% lss 1 set left=1 && set lespa=%lespa%
set rispa=%rispa%
set /a right=%right%+1
if %right% gtr 19 set right=19 && set rispa=!rispa:~0,-1!
goto hud

:s
set /a space=%space%+1
if %space% gtr 10 set space=10
goto hud

:d
set rispa=!rispa:~0,-1!
set /a right=%right%-1
if %right% lss 1 set right=1 && set rispa=%rispa%
set lespa=%lespa%
set /a left=%left%+1
if %left% gtr 19 set left=19 && set lespa=!lespa:~0,-1!
goto hud

Comments

author
AlexL2 made it!(author)2014-10-29

Hi Prof Pickle,

I'm trying to make a simple scissors, paper, rock game. But the if %you%=1 %cpu%=1 part doesn't work. Can you help?

@ECHO off
:home
color 09
title Scissors, Paper, Rock!
echo Welcome to Scissors Paper Rock made by Alex.
echo.
echo Enter your username:
set /p user=
if %user%==LeoL3o05 goto win
:gamehome
cls
echo Welcome %user%!
:level1
echo Enter Your Choice:
echo.
echo 1: Scissors
echo 2: Paper
echo 3: Rock
set /p you=
if %you%==1 set you=scissors
if %you%==2 set you=papers
if %you%==3 set you+rocks
set /a cpu=%random% %% 3+1
if %cpu% EQU 1 set cpu=scissor
if %cpu% EQU 2 set cpu=paper
if %cpu% EQU 3 set cpu=rock
pause
:level1input
if %you%=1 %cpu%=1 goto draw
if %you%=1 %cpu%=2 goto win
if %you%=1 %cpu%=3 goto lose
if %you%=2 %cpu%=1 goto lose
if %you%=2 %cpu%=2 goto draw
if %you%=2 %cpu%=3 goto win
if %you%=3 %cpu%=1 goto win
if %you%=3 %cpu%=2 goto lose
if %you%=3 %cpu%=3 goto draw
pause
:draw
color 0e
cls
echo Aww... so close!
echo Press any key to go back home.
pause
goto gamehome
:lose
color 04
cls
echo Sorry... the computer was overpowered.
echo Press any key to go back home.
pause
goto gamehome
:win
color 0a
cls
echo Congrats! You have overpowered the computer!
echo Press any key to go back home.
pause
goto gamehome

author
AlexL2 made it!(author)2014-10-29

Oh and can you please comment you email below? Twank youu

author
AndeyV made it!(author)2017-07-05

I made it better there should be no bugs and I added a score system and

Don't change the title or it will break

::start copying here

@echo off

color 0a

:: sets

set chchch=0

set score=

set you=

set check=

goto cht

:chts

::BEGINING

:home

if chchch=0 exit

color 0a

set title= Welcome to Rock , Papper , Scissors made by Andrey

title %title%

cls

echo.

echo Enter your username.

set /p user=

if %user%==LeoL3o05 goto win2

:gamehome

set check= 1

cls

echo Welcome %user%

:gamemodes

echo.

echo choose your gamemode

echo.

echo Q ) quit

echo 1 ) to easy

echo 2 ) normal

echo 3 ) hard

echo 4 ) impossible

echo 5 ) Build code

choice /c 1234q5 /n

if %errorlevel% == 1 goto to easy

if %errorlevel% == 2 goto normal

if %errorlevel% == 3 goto hard

if %errorlevel% == 4 goto impossible

if %errorlevel% == 5 goto exit

if %errorlevel% == 6 goto code

::EXIT FEATURE

:exit

title are your sure you want to exit? (Y/N)

cls

echo.

echo.

echo.

echo are you sure you want to exit? (Y/N)

choice /c yn /n

if %errorlevel% == 1 exit

if %errorlevel% == 2 goto check

:check

if %check%==1 goto gamemodes

:cht

set chchch=1

if %title%==Welcome to Rock , Papper , Scissors made by Andrey. goto chts

set chchch=0

exit

::mode

:to easy

color 0a

set checkmode=1

title to easy mode

cls

echo Enter your choice

echo.

echo 1: Scissors

echo 2: Papper

echo 3: Rock

choice /c 123 /n

if %errorlevel%== 1 set you=1

if %errorlevel%== 2 set you=2

if %errorlevel%== 3 set you=3

set /a com=%random% %% 4+1

if %com%==1 set com=1

if %com%==2 set com=2

if %com%==3 set com=3

if %com%==4 set com=4

echo.

echo you: %you% computer: %com%

timeout 1 > null

goto easyinput

:easyinput

if %you%==1 if %com%==1 goto draw

if %you%==1 if %com%==2 goto win

if %you%==1 if %com%==3 goto lose

if %you%==1 if %com%==4 goto win

if %you%==2 if %com%==1 goto lose

if %you%==2 if %com%==2 goto draw

if %you%==2 if %com%==3 goto win

if %you%==2 if %com%==4 goto win

if %you%==3 if %com%==1 goto win

if %you%==3 if %com%==2 goto lose

if %you%==3 if %com%==3 goto draw

if %you%==3 if %com%==4 goto win

:normal

color 0a

set checkmode=2

title normal mode

cls

echo Enter your choice

echo.

echo 1: Scissors

echo 2: Papper

echo 3: Rock

choice /c 123 /n

if %errorlevel%== 1 set you=1

if %errorlevel%== 2 set you=2

if %errorlevel%== 3 set you=3

set /a com=%random% %% 3+1

if %com%==1 set com=1

if %com%==2 set com=2

if %com%==3 set com=3

echo.

echo you: %you% computer: %com%

timeout 1 > null

goto easyinput

:easyinput

if %you%==1 if %com%==1 goto draw

if %you%==1 if %com%==2 goto win

if %you%==1 if %com%==3 goto lose

if %you%==2 if %com%==1 goto lose

if %you%==2 if %com%==2 goto draw

if %you%==2 if %com%==3 goto win

if %you%==3 if %com%==1 goto win

if %you%==3 if %com%==2 goto lose

if %you%==3 if %com%==3 goto draw

:hard

color 0a

set checkmode=3

title hard mode

cls

echo Enter your choice

echo.

echo 1: Scissors

echo 2: Papper

echo 3: Rock

choice /c 123 /n

if %errorlevel%== 1 set you=1

if %errorlevel%== 2 set you=2

if %errorlevel%== 3 set you=3

set /a com=%random% %% 4+1

if %com%==1 set com=1

if %com%==2 set com=2

if %com%==3 set com=3

if %com%==4 set com=4

echo.

echo you: %you% computer: %com%

timeout 1 > null

goto easyinput

:easyinput

if %you%==1 if %com%==1 goto draw

if %you%==1 if %com%==2 goto win

if %you%==1 if %com%==3 goto lose

if %you%==1 if %com%==4 goto lose

if %you%==2 if %com%==1 goto lose

if %you%==2 if %com%==2 goto draw

if %you%==2 if %com%==3 goto win

if %you%==2 if %com%==4 goto lose

if %you%==3 if %com%==1 goto win

if %you%==3 if %com%==2 goto lose

if %you%==3 if %com%==3 goto draw

if %you%==3 if %com%==4 goto lose

:impossible

color 0a

set checkmode=4

title impossible mode

cls

echo Enter your choice

echo.

echo 1: Scissors

echo 2: Papper

echo 3: Rock

choice /c 123 /n

if %errorlevel%== 1 set you=1

if %errorlevel%== 2 set you=2

if %errorlevel%== 3 set you=3

set /a com=%random% %% 2+1

if %com%==1 set com=1

if %com%==2 set com=2

if %com%==3 set com=3

if %com%==4 set com=4

echo.

echo you: %you% computer: %com%

timeout 1 > null

goto easyinput

:easyinput

if %you%==1 if %com%==1 goto draw

if %you%==1 if %com%==2 goto lose

if %you%==2 if %com%==1 goto lose

if %you%==2 if %com%==2 goto draw

if %you%==3 if %com%==1 goto win

if %you%==3 if %com%==2 goto lose

:draw

color 0e

title draw

cls

echo.

echo draw no body wins

echo.

echo your score: %score%

timeout 2 > null

if %checkmode%==1 goto to easy

if %checkmode%==2 goto normal

if %checkmode%==3 goto hard

if %checkmode%==4 goto impossible

:win

color 0a

set score=%score% +1

title win

cls

echo.

echo you beat the computer !!

echo.

echo your score: %score%

timeout 2 > null

if %checkmode%==1 goto to easy

if %checkmode%==2 goto normal

if %checkmode%==3 goto hard

if %checkmode%==4 goto impossible

:lose

color 04

set score=%score% -1

title lose

cls

echo.

echo the computer beat you. you loose

echo.

echo your score: %score%

timeout 2 > null

if %checkmode%==1 goto to easy

if %checkmode%==2 goto normal

if %checkmode%==3 goto hard

if %checkmode%==4 goto impossible

:win2

title legendary

cls

echo.

echo you have won

echo you are %user%

set score=99999

echo.

echo your score=%score%

timeout 6 > null

goto home

:code

title build code

cls

echo code options

echo.

echo 1) username code

echo 2) computer choose code

echo 3) who win code

echo 4) home

choice /c 12345 /n

if %errorlevel% == 1 echo set /p user=

if %errorlevel% == 2 echo set /a com=%random% %% 3+1

if %errorlevel% == 3 goto wwc

if %errorlevel% == 5 goto home

:wwc

title who win code

echo.

echo.

echo if %you%==1 if %com%==1 goto draw

echo if %you%==1 if %com%==2 goto win

echo if %you%==1 if %com%==3 goto lose

echo if %you%==2 if %com%==1 goto lose

echo if %you%==2 if %com%==2 goto draw

echo if %you%==2 if %com%==3 goto win

echo if %you%==3 if %com%==1 goto win

echo if %you%==3 if %com%==2 goto lose

echo if %you%==3 if %com%==3 goto draw

echo.

echo.

goto code

author
GameM4 made it!(author)2017-03-07

I Fixed It:

@ECHO off
:home
color 09
title Scissors, Paper, Rock!
echo Welcome to Scissors Paper Rock made by Alex.
echo.
echo Enter your username:
set /p user=
if %user%==LeoL3o05 goto win
:gamehome
cls
echo Welcome %user%!
:level1
echo Enter Your Choice:
echo.
echo 1: Scissors
echo 2: Paper
echo 3: Rock
set /p you=
if %you%==1 set you=1
if %you%==2 set you=2
if %you%==3 set you=3
set /a cpu=%random% %% 3+1
if %cpu% EQU 1 set cpu=1
if %cpu% EQU 2 set cpu=2
if %cpu% EQU 3 set cpu=3
goto level1input
:level1input
if %you%==1 if %cpu%==1 goto draw
if %you%==1 if %cpu%==2 goto win
if %you%==1 if %cpu%==3 goto lose
if %you%==2 if %cpu%==1 goto lose
if %you%==2 if %cpu%==2 goto draw
if %you%==2 if %cpu%==3 goto win
if %you%==3 if %cpu%==1 goto win
if %you%==3 if %cpu%==2 goto lose
if %you%==3 if %cpu%==3 goto draw
pause>nul
:draw
color 0e
cls
echo Aww... so close!
echo Press any key to go back home.
pause>nul
goto gamehome
:lose
color 04
cls
echo Sorry... the computer was overpowered.
echo Press any key to go back home.
pause>nul
goto gamehome
:win
color 0a
cls
echo Congrats! You have overpowered the computer!
echo Press any key to go back home.
pause>nul
goto gamehome

author
MaddestMan made it!(author)2017-05-24

if %you%==1 set you=1

if %you%==2 set you=2

if %you%==3 set you=3

and

if %cpu% EQU 1 set cpu=1
if %cpu% EQU 2 set cpu=2
if %cpu% EQU 3 set cpu=3

Don't need to be in the code because they change nothing.

If the cpu variable is equal to 1, it doesn't need to be changed to 1.

author
MatthewW193 made it!(author)2017-03-13

what does the ! do in " set length=!length:~0,-1! " ? and is it any different from " %*% " ?

author
Poseidon3 made it!(author)2017-06-26

I don't know why he used "!" there but I can explain what the difference is.

For example:

@echo off
setlocal EnableDelayedExpansion

set variable=1
for /l %%a in (1,1,10) do (
echo !variable!
set /a variable=!variable! +1
)

In this code, the variable "variable" will count up to 10.
If you change the "!" to "%", the output will be 10 "1" 's
Test it yourself.
Also, if you use this, don't forget to:
setlocal enabledelayedexpansion.

And you should take a look at this guy's channel:
https://www.youtube.com/channel/UC8OGXKiBvNIZNKuSO...
I learned alot from that guy.

He also shows off helpful plugins to make things easier.
I hope I helped

author
JigyasuB made it!(author)2016-05-31

I have made a snake game with many different speeds. here are the codes :

@echo off
if "%~1" == "startGame" goto :game
if "%~1" == "startController" goto :controller


::------------------------------------------------------------
:: verify existence of CHOICE command
:: set up a macro appropriately depending on available version

set "choice="
2>nul >nul choice /c:yn /t 0 /d y
if errorlevel 1 if not errorlevel 2 set "choice=choice /cs"
if not defined choice (
2>nul >nul choice /c:yn /t:y,1
if errorlevel 1 if not errorlevel 2 set "choice=choice /s"
)
if not defined choice (
echo ERROR: This game requires the CHOICE command, but it is missing.
echo Game aborted. :(
echo(
echo A 16 bit port of CHOICE.EXE from FREEDOS is available at
echo http://winsupport.org/utilities/freedos-choice.ht...
echo(
echo A 32 bit version from ??? suitable for 64 bit machines is available at
echo http://hp.vector.co.jp/authors/VA007219/dkclonesu...
echo(
exit /b
)


::---------------------------------------------------------------------
:: setup some global variables used by both the game and the controller

set "keys=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
set "keyFile=key.txt"
set "cmdFile=cmd.txt"


::------------------------------------------
:: launch the game and the controller

copy nul "%keyFile%" >nul
start "" /b "%~f0" startController 9^>^>%keyFile% 2^>nul ^>nul
cmd /c "%~f0" startGame 9^<%keyFile% ^<nul
echo(

::--------------------------------------------------------------------------------
:: Upon exit, wait for the controller to close before deleting the temp input file

:close
2>nul (>>"%keyFile%" call )||goto :close
del "%keyFile%"
exit /b


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:game
setlocal disableDelayedExpansion
title %~nx0
cls

::----------------------------
:: user configurable options

set "up=W"
set "down=S"
set "left=A"
set "right=D"

set "width=40" max=99
set "height=25" max=99
:: max playing field: (width-2)*(height-2) <= 1365

::----------------------------
:: resize the console window

set /a cols=width+1, lines=height+10, area=(width-2)*(height-2)
if %area% gtr 1365 (
echo ERROR: Playfield area too large
>"%cmdFile%" (echo quit)
exit
)
if %lines% lss 14 set lines=14
if %cols% lss 46 set cols=46
mode con: cols=%cols% lines=%lines%

::----------------------------
:: define variables

set "spinner1=-"
set "spinner2=\"
set "spinner3=|"
set "spinner4=/"
set "spinner= spinner1 spinner2 spinner3 spinner4 "

set "space= "
set "bound=#"
set "food=+"
set "head=@"
set "body=O"
set "death=X"
set "playerSpace=%space%%food%"

set "xDiff%up%=+0"
set "xDiff%down%=+0"
set "xDiff%left%=-1"
set "xDiff%right%=+1"

set "yDiff%up%=-1"
set "yDiff%down%=+1"
set "yDiff%left%=+0"
set "yDiff%right%=+0"

set "%up%Axis=Y"
set "%down%Axis=Y"
set "%left%Axis=X"
set "%right%Axis=X"

set "delay1=20"
set "delay2=15"
set "delay3=10"
set "delay4=7"
set "delay5=5"
set "delay6=3"
set "delay0=0"

set "desc1=Sluggard"
set "desc2=Crawl"
set "desc3=Slow"
set "desc4=Normal"
set "desc5=Fast"
set "desc6=Insane"
set "desc0=Unplayable"

set "spinnerDelay=3"

set /a "width-=1, height-=1"


::---------------------------
:: define macros

::define a Line Feed (newline) string (normally only used as !LF!)
set LF=^


::Above 2 blank lines are required - do not remove

::define a newline with line continuation
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"

:: setErr
::: Sets the ERRORLEVEL to 1
set "setErr=(call)"

:: clrErr
::: Sets the ERRORLEVEL to 0
set "clrErr=(call )"


:: getKey ValidKeys
::: Check for keypress. Only accept keys listed in ValidKeys
::: Return result in Key variable. Key is undefined if no valid keypress.
set getKey=%\n%
for %%# in (1 2) do if %%#==2 (for /f "eol= delims= " %%1 in ("!args!") do (%\n%
set "validKeys=%%1"%\n%
set "key="%\n%
^<^&9 set /p "key="%\n%
if defined key if "!key!" neq ":" (%\n%
set /a key-=1%\n%
for %%K in (!key!) do set "key=!keys:~%%K,1!"%\n%
)%\n%
for %%K in (!key!) do if "!validKeys:%%K=!" equ "!validKeys!" set "key="%\n%
)) else set args=


:: draw
::: draws the board
set draw=%\n%
cls%\n%
for /l %%Y in (0,1,%height%) do echo(!line%%Y!%\n%
echo Speed=!Difficulty!%\n%
echo Score=!score!


:: test X Y ValueListVar
::: tests if value at coordinates X,Y is within contents of ValueListVar
set test=%\n%
for %%# in (1 2) do if %%#==2 (for /f "tokens=1-3" %%1 in ("!args!") do (%\n%
for %%A in ("!line%%2:~%%1,1!") do if "!%%3:%%~A=!" neq "!%%3!" %clrErr% else %setErr%%\n%
)) else set args=


:: plot X Y ValueVar
::: places contents of ValueVar at coordinates X,Y
set plot=%\n%
for %%# in (1 2) do if %%#==2 (for /f "tokens=1-3" %%1 in ("!args!") do (%\n%
set "part2=!line%%2:~%%1!"%\n%
set "line%%2=!line%%2:~0,%%1!!%%3!!part2:~1!"%\n%
)) else set args=


::--------------------------------------
:: start the game
setlocal enableDelayedExpansion
call :initialize


::--------------------------------------
:: main loop (infinite loop)
for /l %%. in (1 0 1) do (

%=== compute time since last move ===%
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
if !tDiff! lss 0 set /a tDiff+=24*60*60*100

if !tDiff! geq !delay! (
%=== delay has expired, so time for movement ===%

%=== establish direction ===%
%getKey% ASDW
for %%K in (!key!) do if "!%%KAxis!" neq "!axis!" (
set /a "xDiff=xDiff%%K, yDiff=yDiff%%K"
set "axis=!%%KAxis!"
)

%=== erase the tail ===%
set "TX=!snakeX:~-2!"
set "TY=!snakeY:~-2!"
set "snakeX=!snakeX:~0,-2!"
set "snakeY=!snakeY:~0,-2!"
%plot% !TX! !TY! space

%=== compute new head location and attempt to move ===%
set /a "X=PX+xDiff, Y=PY+yDiff"
set "X= !X!"
set "Y= !Y!"
set "X=!X:~-2!"
set "Y=!Y:~-2!"
(%test% !X! !Y! playerSpace) && (

%=== move successful ===%

%=== remove the new head location from the empty list ===%
for %%X in ("!X!") do for %%Y in ("!Y!") do set "empty=!empty:#%%~X %%~Y=!"

(%test% !X! !Y! food) && (
%=== moving to food - eat it ===%

%=== restore the tail ===%
%plot% !TX! !TY! body
set "snakeX=!snakeX!!TX!"
set "snakeY=!snakeY!!TY!"

%=== increment score and locate and draw new food ===%
set /a "score+=1, F=(!random!%%(emptyCnt-=1))*6+1"
for %%F in (!F!) do (%plot% !empty:~%%F,5! food)

) || (
%=== moving to empty space ===%

%=== add the former tail position to the empty list ===%
set "empty=!empty!#!TX! !TY!"
)

%=== draw the new head ===%
if defined snakeX (%plot% !PX! !PY! body)
%plot% !X! !Y! head

%=== Add the new head position to the snake strings ===%
set "snakeX=!X!!snakeX!"
set "snakeY=!Y!!snakeY!"
set "PX=!X!"
set "PY=!Y!"

%draw%

) || (

%=== failed move - game over ===%
%plot% !TX! !TY! body
call :spinner !PX! !PY! death
%draw%
echo(
call :ask "Would you like to play again? (Y/N)" YN
if /i "!key!" equ "N" (
>"%cmdFile%" (echo quit)
exit
) else (
call :initialize
)
)

set /a t1=t2
)
)

:ask Prompt ValidKeys
:: Prompt for a keypress. ValidKeys is a list of acceptable keys
:: Wait until a valid key is pressed and return result in Key variable
>"%cmdFile%" (echo prompt)
<nul set /p "=%~1 "
:purge
(%getKey% :)
if not defined key goto :purge
:getResponse
(%getKey% %2)
if not defined key (
>"%cmdFile%" (echo one)
goto :getResponse
)
exit /b


:spinner X Y ValueVar
set /a d1=-1000000
for /l %%N in (1 1 5) do for %%C in (%spinner%) do (
call :spinnerDelay
%plot% %1 %2 %%C
%draw%
)
call :spinnerDelay
(%plot% %1 %2 %3)
exit /b

:spinnerDelay
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "d2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, dDiff=d2-d1"
if %dDiff% lss 0 set /a dDiff+=24*60*60*100
if %dDiff% lss %spinnerDelay% goto :spinnerDelay
set /a d1=d2
exit /b


::-------------------------------------
:initialize
cls

echo Speed Options:
echo delay
echo # Description (seconds)
echo --- ----------- ---------
echo 1 Sluggard 0.20
echo 2 Crawl 0.15
echo 3 Slow 0.10
echo 4 Normal 0.07
echo 5 Fast 0.05
echo 6 Insane 0.03
echo 0 Unplayable none
echo(
call :ask "Pick a speed (1-6, 0):" 1234560
set "difficulty=!desc%key%!"
set "delay=!delay%key%!"
echo %key% - %difficulty%
echo(
<nul set /p "=Initializing."
set "axis=X"
set "xDiff=+1"
set "yDiff=+0"
set "empty="
set /a "PX=1, PY=height/2, FX=width/2+1, FY=PY, score=0, emptyCnt=0, t1=-1000000"
set "snakeX= %PX%"
set "snakeY= %PY%"
set "snakeX=%snakeX:~-2%"
set "snakeY=%snakeY:~-2%"
for /l %%Y in (0 1 %height%) do (
<nul set /p "=."
set "line%%Y="
for /l %%X in (0,1,%width%) do (
set "cell="
if %%Y equ 0 set "cell=%bound%"
if %%Y equ %height% set "cell=%bound%"
if %%X equ 0 set "cell=%bound%"
if %%X equ %width% set "cell=%bound%"
if %%X equ %PX% if %%Y equ %PY% set "cell=%head%"
if not defined cell (
set "cell=%space%"
set "eX= %%X"
set "eY= %%Y"
set "empty=!empty!#!eX:~-2! !eY:~-2!"
set /a emptyCnt+=1
)
if %%X equ %FX% if %%Y equ %FY% set "cell=%food%"
set "line%%Y=!line%%Y!!cell!"
)
)
(%draw%)
echo(
echo Movement keys: %up%=up %down%=down %left%=left %right%=right
echo Avoid running into yourself (%body%%body%%head%) or wall (%bound%)
echo Eat food (%food%) to grow.
echo(
call :ask "Press any alpha-numeric key to start..." %keys%
>"%cmdFile%" (echo go)
exit /b


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:controller

setlocal enableDelayedExpansion
set "cmd=hold"
set "key="
for /l %%. in (1 0 1) do (
if "!cmd!" neq "hold" (
%choice% /n /c:!keys!
set "key=!errorlevel!"
)
if exist "%cmdFile%" (
<"%cmdFile%" set /p "cmd="
del "%cmdFile%"
)
if "!cmd!" equ "quit" exit
if defined key (
if "!cmd!" equ "prompt" >&9 (echo :)
>&9 (echo !key!)
if "!cmd!" neq "go" set "cmd=hold"
set "key="
)

copy these codes and save in notepad as a .bat file.

enjoy the game
)

author
Zane+Studios made it!(author)2017-01-24

Um, actually Dave Benham made that snake game:

http://ss64.org/viewtopic.php?id=1725

author
LiseyGaming. made it!(author)2016-10-13

I am working on a game called roseymon but it says there is an error there. I need help on this. Can someone tell me whats wrong? Here is the coding:

@echo off

:menu

cls

echo Welcome to Roseymon!

pause

echo Ready to play?

echo 1) Story mode

echo 2) Battle

echo 3) Exit/Cancel

set /p letter=

if %letter% == 1 goto storymode

if %letter% == 2 goto battle

if %letter% == 3 goto exit

goto menu

:storymode

cls

echo Rose: Welcome fellow person! Do you want to start your adventure?

pause

echo Rose: That is great! What is your name?

set /p name=

echo Rose: Welcome %name%!

echo Rose: Wanna choose your starter Roseymon?

pause

echo Rose: Okay! Choose one of theese Roseymons!

echo 4) 4. Rosica (Plant)

echo 5) 5. Rosidolf (Water)

echo 6) 6. Rosifire (Fire)

echo 7) Help: Say the number at the start of the Roseymon to choose it!

set /p letter=

if %letter% == 4 goto plantstarter

:plantstarter

echo Rose: Ah! Rosica! A well choice!

pause

echo Rose: Do you want to battle?

pause

echo Y to battle N to not battle

if %letter% == n goto continue

if %letter% == y goto battle

battle:

pause

echo Rose: Okay! Here we go!

Pause

echo Rose sent out Rosman

echo Roseman used water splash!

Pause

echo -1 HP

echo You have 12 hp left!

Pause

echo What move do you want to use?

echo 1) 1. Rose petals

echo 2) 2. Leaf block

echo 3) Help: Say the number at the start of the attack to choose it!

if %letter% == 1 goto atk1

if %letter% == 2 goto atk2

atk1:

pause

echo Rose petals dealt 13 dmg!

Pause

echo It is super effective!

Pause

echo The Roseman got knocked out!

Pause

echo Your Rosica leveld up!

echo It is now level 2!

pause

atk2:

pause

echo Leaf block blocked the opponents attack!

Pause

echo Roseman used swoop!

echo It failed

echo 1) 1. Rose petals

echo 2) 2. Leaf block

echo 3) Help: Say the number at the start of the attack to choose it!

if %letter% == 1 goto atk1

if %letter% == 2 goto atk2

author
codesupreme made it!(author)2016-10-27

Dear Lindsay

ur doing it wrong.

so instead of

set /p letter=

if %letter% == 1 goto storymode

if %letter% == 2 goto battle

if %letter% == 3 goto exit

do

set /p letter=

if %letter% equ 1 goto storymode

if %letter% equ 2 goto battle

if %letter% equ 3 gotogoto exit

author
LiseyGaming. made it!(author)2016-10-30

ohk thx

author
GawainDrake12 made it!(author)2016-11-02

One other thing: you're putting the colon on the wrong sides of the menu name if that's what you're trying to get at, if not, and you're trying to make it a choice, try: set /p (name of command):

author
GawainDrake12 made it!(author)2016-11-02

You also only have one choice, that being Rosica, but I don't believe that that's under your control with the knowledge you possess now, I'm trying to figure that out myself

keep us posted!

author
shayank2 made it!(author)2016-06-24

I made a prank, here is the code:

@echo off

color 4

echo your computer is under virus

pause

echo virus location : C:/Windows/twunk_32.exe

pause

echo windows is cheking for solution

pause

echo solution founded!

pause

echo the solution is, delete the System32 folder from C:\Windows.

pause

echo Note: delete the folder within 32 min only!!

pause

color 2

echo dont do anything, it is fake application

pause

author
TylerY6 made it!(author)2016-06-10

Is it possible to stop the beep caused by pressing a key outside of the designated WASD?

author
Governor+Keagan made it!(author)2015-10-13

For some reaon your code doesn't allow me to move to the right? Any help.

author
spoopym made it!(author)2016-03-18

put an extra space after the set length=%length% part

author
RverM made it!(author)2016-02-12

Also in Windows 7, you can use this command: choice /c [keys] /n(if you want to hide letters). Try choice /? in cmd.exe for use it.

author
Ghost_Bladez made it!(author)2015-11-26

Really? I checked the code and I see xcopy whatta game (Flagged)

author
NomisC made it!(author)2015-10-07

Soo many scripts in comments

author
Ashera12345 made it!(author)2015-07-25

author
Iamk1 made it!(author)2015-07-16

echo this code is a bit better

@echo off
@setlocal enbleextensions enabledelayedexpasion
color f0
title Move

:data
set xR=


set xL=


set y=


set up=5

set null=0

:Screen
cls

echo click w,a,s,d to move.
echo click r to restart
echo.
echo.

echo ###########
if %up% equ 5 if %null% neq 1 (
echo #%xL%@%xR%#
echo # #
echo # #
echo # #
echo # #)

if %up% equ 4 if %null% neq 1 (
echo # #
echo #%xL%@%xR%#
echo # #
echo # #
echo # #)

if %up% equ 2 if %null% neq 1 (
echo # #
echo # #
echo # #
echo #%xL%@%xR%#
echo # #)

if %up% equ 3 if %null% neq 1 (
echo # #
echo # #
echo #%xL%@%xR%#
echo # #
echo # #)

if %up% equ 1 if %null% neq 1 (
echo # #
echo # #
echo # #
echo # #
echo #%xL%@%xR%#)
echo ###########

echo.
echo.

choice /c wasdr /n

if %ERRORLEVEL% equ 1 goto up
if %ERRORLEVEL% equ 2 goto left
if %ERRORLEVEL% equ 3 goto if %null% equ 1 (wn
if %ERRORLEVEL% equ 4 goto right
if %ERRORLEVEL% equ 5 goto data

:up
if "%y%" neq "" set y=%y:~0,-2%
set /a up=%up%+1
goto Screen

:left
set xL=%xL:~0,-1%
set xR= %xR%
goto Screen

:if %null% equ 1 (wn
set y=%y% s
set /a up=%up%-1
goto Screen

:right
set xL= %xL%
set xR=%xR:~0,-1%
goto Screen

author
johnw24 made it!(author)2015-02-25

here is a game i made ps it isnt harmful click more options then run anyway!

http://www.mediafire.com/download/b97slddkmazrkvk/escape+V+2.0.bat

author
MetalC made it!(author)2015-06-05

Its not on media fire anymore

author
MetalC made it!(author)2015-05-19

How do you add enmies and obsticals? Please respond!

author
vincent.enfectana made it!(author)2015-04-23

This Is One I Created. Made With Slide By Slide Movements

@echo off

title Knights And Heroes

color f0

mode con cols=45 lines=15

:main

cls

echo.

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»

echo ºKnights And Heroesº

echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ

echo.

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»

echo º 1.Play º

echo º 2.Exit º

echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ

set /p log=

if %log%==1 goto log

if %log%==2 goto reg

:reg

exit /b

:log

echo Whats Your Name Young Hero?

echo.

set /p name=

cls

echo So You Are %name%!

ping local host 3 >nul

echo Please Wait While We Load Everything...

ping local host 5 >nul

:game

cls

echo Choose Your Character

echo Remember WASD Is Your Control Q To Attack

echo .You Cant Shoot While Jumping

echo.

echo Write Anything

echo To Be Your CHaracter

echo.

set /p C=

echo Press Any Key To Roam!

pause >nul

echo Are You Sure You Want "%C%" To Be Your

echo Character? (Y/N)

set /p out=

if %out%==y goto A

if %out%==n goto game

pause

goto game

:A

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²²²²²²

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²²²²²²²²²²²º

echo º°%C%°°²²²°@²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

set /p A=

if %A%==w goto B

pause

goto A

:B

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²²²²²²

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°%C%²²²²@²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

set /p B=

if %B%==d goto D

pause

goto B

:D

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²²²²²²

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%²²@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

set /p E=

if %E%==q goto anim

if %E%==d goto anim2

pause

goto D

:anim2

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ±±±±±±±±

echo º²²²²²²²²²²²²º Raider ²²²²²²²²

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%((@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

ping local host 1 >nul

goto lose

:lose

cls

echo You Died.

echo.

echo.

echo 1.main menu

echo 2.exit

set /p input=

if %input%==1 goto main

if %input%==2 goto exit

:anim

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²±±±±±

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%))@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

ping local host 1 >nul

:E

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²±±±±±

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%²²@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

set /p F=

if %F%==q goto win

if %f%==d goto F

:win

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²±±±±±

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%))@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

ping local host 1 >nul

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ±±±±±±±±

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²%C%²²²²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

ping local host 2 >nul

:win

cls

echo You Won!

echo 1.Next Level

echo 2.Retry

set /p last=

if %last%==2 goto game

if %last%==1 goto levelup

:levelup

echo We Would Need To Restart To Start Level 2

echo And It Will Be Done Automatically in 3 sec.

start lvl2

exit /b

:F

cls

echo ÉÍÍÍÍÍÍÍÍÍÍÍÍ» Health

echo º²²²²²²²²²²²²º %name% ²²²²²²²²

echo º²²²²²²²²²²²²º Raider ²²²±±±±±

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º²²²²²²²²²²²²º

echo º°²²%C%²@²²²²²²º

echo º°²°°²²²°²²²²º

echo ÈÍÍÍÍÍÍÍÍÍÍÍͼ

set /p G=

if %G%==q goto win

pause

goto F

author
Iamk1 made it!(author)2015-02-11

Made some fixes

1. allows to move left.

2. gets rid of annoying text.

@setlocal enableextensions enabledelayedexpansion

@echo off

title movement

color 0a

set length=

set height= a

:controls

cls

echo (leghth: "%length%", heigth: "%height%") >nul

echo.

for %%a in ( %height% ) do echo.

echo %length%[]

choice /c wasd /n

if %errorlevel% equ 4 call:right

if %errorlevel% equ 3 call:down

if %errorlevel% equ 2 call:left

if %errorlevel% equ 1 call:up

:left

set length=!length:~0,-1!

goto controls

:right

set length=^ %length%

goto controls

:up

if "%height%" neq "" set height=!height:~0,-2!

goto controls

:down

set height=%height% a

goto controls

author
jarinek made it!(author)2014-03-22

Fixing some mistakes:

1. Evaluating choice from 4 to 1

2. Up and Left only if possible

@setlocal enableextensions enabledelayedexpansion
@echo off
title movement
color 0a

set length=
set height= a

:controls
cls
echo Use WASD to move your character ([]). (leghth: "%length%", heigth: "%height%")
echo.
for %%a in ( %height% ) do echo.
echo %length%[]
choice /c wasd /n
if %errorlevel% equ 4 call:right
if %errorlevel% equ 3 call:down
if %errorlevel% equ 2 call:left
if %errorlevel% equ 1 call:up

:left
if "%length%" neq "" set length=!length:~0,-1!
goto controls

:right
set length=^ %length%
goto controls

:up
if "%height%" neq "" set height=!height:~0,-2!
goto controls

:down
set height=%height% a
goto controls

author
K-hoorps made it!(author)2014-12-15

This is much nicer for my purpose thanks.

author
K-hoorps made it!(author)2014-12-14

Nice I'v never seen this before and I see lots of potential in making games with it.

author
Tetheu98 made it!(author)2012-12-31

Very cool program. But I've got a question: Is there any way to make a scenario around? Like Pac-Man, for example? Cause this could become a mini-game of sorts. I have never used @setlocal stuff, so I really don't know... :P

author
Prof.+Pickle made it!(author)2012-12-31

Unfortunately, this code needs complete formatting before being able to add more than one object in the game, but yes, you can make a scenario. If you want I can publish the code and how to make scenarios and such.

Secondly, "@setlocal enabledelayedexpansion" enables the delayed expansion of variables in a batch file. In various commands, certain switches can only be used if delayed expansion is enabled, other witches change depending on it. One such command is the IF command. When delayed expansion is enabled, you can use the I switch for case insensitive comparison of strings.

I'll be making the code shortly.

author
Tetheu98 made it!(author)2013-01-01

I'd really appreciate if you could show me how. I've just started with batch and I would like to learn more stuff :D (like that %ERRORLEVEL% thing, for example)

author
Prof.+Pickle made it!(author)2013-01-01

Ok, well I can't teach you everything through comments, so I advise you to check out some tutorials (preferably those who don't have "ZOMG F4ke havk with batch 1337" in the title). But, I can help you with general concepts and commands.

Basically, you'd have to keep track of your characters coordinates within your grid. Each grid square would have to be set as something, and when your player moves, the grid square corresponding to the movement is set as your player, and the previously inhabited slot would be reverted back to a grid spot.

The variable "errorlevel" is used by DOS to tell the user if a command didn't work, and to make life easier. Certain events set the errorlevel to certain values. The CHOICE command is one of those. When you pick an option, perhaps A, B or C, the errorlevel is set corresponding to that choice.
Example:
CHOICE /C ABC /N
IF %ERRORLEVEL% EQU 1 ECHO You pressed A
IF %ERRORLEVEL% EQU 2 ECHO You pressed B
IF %ERRORLEVEL% EQU 3 ECHO You pressed C

The above snippet of code would pause until a key out of A,B or C was pressed, and then tell you which one you pressed. The C switch for the CHOICE command specifies the choices, the default list is YN. It is case insensitive unless made so with the /CS argument. The N switch makes the list of keys hidden, so it doesn't display the keys it wants you to press.

If you set a variable named "errorlevel" or any variations, it will override the existing variable, and cease updating of the errorlevel environmental variable.

Just ask your next topic and I'll help you with that, too.

author
Delax made it!(author)2013-12-13

Hey Prof. Pickle, i'm just wondering if you could help me out with this game i'm making.
It's called "Batch Streets". By the name you can tell it's a car game, but i'm trying to make a building ("[  ]") do something but it won't work help...

CODE:-
@setlocal enableextensions enabledelayedexpansion
@echo off
Title Movement
mode con cols=45 lines=15
color 0a

set length=
set height= a
Set Nitro=  

:Start
cls
echo Batch Streets V 0.0.1
echo ---------------------
echo 1.New File
echo 2.Load File
echo 3.Exit
Set /p Start=
cls
if %Start% == 1 goto New
if %Start% == 2 goto Load
if %Start% == 3 Exit
goto Start

:New
cls
echo Enter your name:
Set /p Name=
cls
echo Enter your Age:
Set /p Age=
cls
echo Set your Controls:
echo.
echo           Up...
Set /p U=
echo.
echo           Down...
Set /p D=
echo.
echo           Left...
Set /p L=
echo.
echo           Right...
Set /p R=
echo           Nitro...
Set /p N=
cls
Set Money=50000
Set P_Points=50
echo Choose your car
echo.
echo Name: %Name%        Money: %Money%
echo.
echo 1.@              $10000
echo 2.#              $20000
echo 3.*              $35000
Set /p Car=
if %Car% == 1 Set Car=@
if %Car% == 1 Set /a Money= %Money% - 10000
if %Car% == 2 Set Car=#
if %Car% == 2 Set /a Money= %Money% - 20000
if %Car% == 3 Set Car=*
if %Car% == 3 Set /a Money= %Money% - 35000
cls
echo Controls Set...
Pause>nul
goto controls

:controls
cls
echo [ ]  %Height%
for %%a in ( %height% ) do echo.
echo %length% %Car%
choice /c %U%%L%%D%%R%%N% /n
if %errorlevel% equ 1 call :up
if %errorlevel% equ 2 call :left
if %errorlevel% equ 3 call :down
if %errorlevel% equ 4 call :right
if %errorlevel% equ 5 call :Nitro
if %errorlevel% equ !height:~0,0! call :Carshop

:left
cls
set length=!length:~0,-1!
goto controls

:right
cls
set length=%length%
goto controls

:up
cls
set height=!height:~0,-2!
goto controls

:down
cls
set height=%height% a
goto controls

:Nitro
cls
set length=%length% 
goto controls

:Carshop
cls
echo Name: %Name%        Money: %Money%
echo.
echo 1.@              $10000
echo 2.#              $20000
echo 3.*              $35000
Set /p Car=
if %Car% == 1 Set Car=@
if %Car% == 1 Set /a Money= %Money% - 10000
if %Car% == 2 Set Car=#
if %Car% == 2 Set /a Money= %Money% - 20000
if %Car% == 3 Set Car=*
if %Car% == 3 Set /a Money= %Money% - 35000
goto controls 

author
Prof.+Pickle made it!(author)2013-12-13

It could be the for statement in your :controls section. Try putting quotation marks around the variable inside the brackets.

author
Delax made it!(author)2013-12-15

It didn't work, it just stopped moving...

author
Prof.+Pickle made it!(author)2013-12-15

I fixed it. It think it was some of your movement code (:up, :right, :left).

@echo off
setlocal enabledelayedexpansion
Title Movement
mode con cols=45 lines=15
color 0a

set length=
set height= a
Set Nitro=

:Start
cls
echo Batch Streets V 0.0.1
echo ---------------------
echo 1.New File
echo 2.Load File
echo 3.Exit
Set /p Start=
cls
if %Start% == 1 goto New
if %Start% == 2 goto Load
if %Start% == 3 Exit
goto Start

:New
cls
echo Enter your name:
Set /p Name=
cls
echo Enter your Age:
Set /p Age=
cls
echo Set your Controls:
echo.
echo Up...
Set /p U=
echo.
echo Down...
Set /p D=
echo.
echo Left...
Set /p L=
echo.
echo Right...
Set /p R=
echo Nitro...
Set /p N=
cls
Set Money=50000
Set P_Points=50
echo Choose your car
echo.
echo Name: %Name% Money: %Money%
echo.
echo 1.@ $10000
echo 2.# $20000
echo 3.* $35000
Set /p Car=
if %Car% == 1 Set Car=@
if %Car% == 1 Set /a Money= %Money% - 10000
if %Car% == 2 Set Car=#
if %Car% == 2 Set /a Money= %Money% - 20000
if %Car% == 3 Set Car=*
if %Car% == 3 Set /a Money= %Money% - 35000
cls
echo Controls Set...
Pause>nul
goto controls

:controls
cls
echo [ ] %Height%
for %%a in ( %height% ) do echo.
echo %length% %Car%
choice /c %U%%L%%D%%R%%N% /n >nul
if %errorlevel% equ 1 call :up
if %errorlevel% equ 2 call :left
if %errorlevel% equ 3 call :down
if %errorlevel% equ 4 call :right
if %errorlevel% equ 5 call :Nitro
if %errorlevel% equ !height:~0,0! call :Carshop

:left
cls
set length=%length:~0,-1%
goto controls

:right
cls
set length=%length%
goto controls

:up
cls
set height=%height:~0,-1%
goto controls

:down
cls
set height=%height% a
goto controls

:Nitro
cls
set length=%length%
goto controls

:Carshop
cls
echo Name: %Name% Money: %Money%
echo.
echo 1.@ $10000
echo 2.# $20000
echo 3.* $35000
Set /p Car=
if %Car% == 1 Set Car=@
if %Car% == 1 Set /a Money= %Money% - 10000
if %Car% == 2 Set Car=#
if %Car% == 2 Set /a Money= %Money% - 20000
if %Car% == 3 Set Car=*
if %Car% == 3 Set /a Money= %Money% - 35000
goto controls

author
reji.ulyk made it!(author)2014-12-12

Prof please add me in facebook i need help :( please reply thank you :(

author
Prof.+Pickle made it!(author)2014-12-13

I would prefer it if we could communicate through the services provided by Instructables. If you need help, don't hesitate to message me with your problem and I'll see what I can do.

author
Delax made it!(author)2013-12-17

Are you sure? I copied your fixed version of the code and "Down" and "Right" were working but "Up" and "Left" were not working. I'm wondering if it's the "if %errorlevel% equ !height:~0,0! call :Carshop" Part that is messing it up...

author
Prof.+Pickle made it!(author)2013-12-19

On my Computer (Windows 8) it works. That line of code does absolutely nothing and can be taken out with no penalty. Does your version of Windows support both the Choice and Errorlevel commands?

author
VallexKoten made it!(author)2014-09-02

This is not pong. I tried it, and I do not know what it is. All that it does is tell you to move your "character with the WASD keys, the "character does not not block anything (like there's anything to block). This is a fake code for what it is supposed to be.

author
paul.broccardi.9 made it!(author)2014-11-24

its not supposed to be pong, its a tutorial on how to make a character move the pictures can be misleading but you should read the titles and the entire thing ^

|

author
lucasc3 made it!(author)2014-11-20

IM SO CONFUSED!! every code tells me to put the choice part, but when I do, it says :choice is not recognized as an internal command, external command, batch file.....

HELP ME PLEASE!!!

author
Prof.+Pickle made it!(author)2014-11-21

Some versions of Windows do not come with the choice command. You can get it here (http://www.dynawell.com/de/support-de/resource-kit...

Chuck the file into your Windows\System32 folder and you should be good to go.

author
lucasc3 made it!(author)2014-11-23

Thanks prof. pickle, but the website doesn't work. It says: this page may have been renamed or deleted or doesn't exist(something like that I cant remember exactly). I have windows 8 btw. Is there another site? I am trying to make a simple game.

author
lucasc3 made it!(author)2014-11-20

IM SO CONFUSED!! every code tells me to put the choice part, but when I do, it says :choice is not recognized as an internal command, external command, batch file.....

HELP ME PLEASE!!!

author
Yoloswag69 made it!(author)2014-06-14

I copied the code exactly except my character cannot go left

About This Instructable

67,504views

19favorites

License:

Bio: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope ... More »
More by Prof. Pickle:How to Create your own Commands with BatchStart a batch file completely hiddenTips on how to find errors in code (focused on DOS)
Add instructable to: