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
85 Comments
1 year ago
I have made a few changes so it should be working again. (at least for me it does):
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
if %right% gtr 19 goto hud
set lespa=!lespa:~0,-1!
set /a right=%right%+1
set /a left=%left%-1
set "rispa=%rispa%-"
goto hud
:s
set /a space=%space%+1
if %space% gtr 10 set space=10
goto hud
:d
if %left% gtr 19 goto hud
set rispa=!rispa:~0,-1!
set /a right=%right%-1
set "lespa=%lespa%-"
set /a left=%left%+1
goto hud
1 year ago
'D' doesn't work for me. Something was coded incorrectly.
Tip 1 year ago
Hello Prof. Pickle
I just make a ripoff of the "Roseymon" game, it called Uvuvwevwevwe onyetenvewve ugwemubwem ossasmon
here is the sample code
@echo off
:menu
cls
echo Welcome to Uvuvwevwevwe onyetenvewve ugwemubwem ossasmon!
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 Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Welcome fellow person! Do you want to start your adventure?
pause
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas: That is great! What is your name?
set /p name=
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Welcome %name%!
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Wanna choose your starter Uvuvwevwevwe onyetenvewve ugwemubwem ossasmon?
pause
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Okay! Choose one of theese Uvuvwevwevwe onyetenvewve ugwemubwem ossasmons!
echo 4) 4. Uvuvwevwevwe onyetenvewve ugwemubwem ossasca (Plant)
echo 5) 5. Uvuvwevwevwe onyetenvewve ugwemubwem ossasdolf (Water)
echo 6) 6. Uvuvwevwevwe onyetenvewve ugwemubwem ossasfire (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 Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Ah! Uvuvwevwevwe onyetenvewve ugwemubwem ossasca! A well choice!
pause
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas: 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 Uvuvwevwevwe onyetenvewve ugwemubwem ossas: Okay! Here we go!
Pause
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossas sent out Uvuvwevwevwe onyetenvewve ugwemubwem ossasman
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossasman 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. Uvuvwevwevwe onyetenvewve ugwemubwem ossas 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 Uvuvwevwevwe onyetenvewve ugwemubwem ossas petals dealt 13 dmg!
Pause
echo It is super effective!
Pause
echo The Uvuvwevwevwe onyetenvewve ugwemubwem ossasman got knocked out!
Pause
echo Your Uvuvwevwevwe onyetenvewve ugwemubwem ossasca leveld up!
echo It is now level 2!
pause
atk2:
pause
echo Leaf block blocked the opponents attack!
Pause
echo Uvuvwevwevwe onyetenvewve ugwemubwem ossasman 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
8 years ago on Introduction
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
Reply 1 year ago
Hi, Alex. Sorry for late response, but i fixed your code and it shoud work now!
Code:
@ECHO off
:home
title Scissors, Paper, Rock!
echo Welcome to Scissors Paper Rock made by Alex.
echo.
set /p user="Enter your username: "
if %user%==LeoL3o05 goto win
:gamehome
:level1
cls
echo Welcome, %user%!
color 09
echo Level 1
echo.
echo 1: Scissors
echo 2: Paper
echo 3: Rock
set /p choice="Enter your choice: "
if %choice% equ 1 (set you=1)
if %choice% equ 2 (set you=2)
if %choice% equ 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
:level1input
if %you% equ 1 (if %cpu% equ 1 ( goto draw))
if %you% equ 1 (if %cpu% equ 2 (goto win))
if %you% equ 1 (if %cpu% equ 3 (goto lose))
if %you% equ 2 (if %cpu% equ 1 (goto lose))
if %you% equ 2 (if %cpu% equ 2 (goto draw))
if %you% equ 2 (if %cpu% equ 3 (goto win))
if %you% equ 3 (if %cpu% equ 1 (goto win))
if %you% equ 3 (if %cpu% equ 2 (goto lose))
if %you% equ 3 (if %cpu% equ 3 (goto draw))
echo human: %you% computer: %cpu%
pause
:draw
color 0e
cls
echo Aww... so close! It's a draw!
echo Press any key to go back home.
pause
goto gamehome
:lose
color 04
cls
echo Sorry... the computer overpowered you.
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
Reply 8 years ago on Introduction
Oh and can you please comment you email below? Twank youu
Reply 5 years ago
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
Reply 6 years ago
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
Reply 6 years ago
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.
2 years ago
A & D won't work!
3 years ago
everything works great. unfortunately, the D button does not work as it should. instead of going to the right, I go to the left. as if the A / D were the same. please help.
6 years ago
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
Reply 6 years ago
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
Reply 3 years ago
I think that's wrong too. Nothing is wrong with
set /p letter=
if %letter% == 1 goto storymode
if %letter% == 2 goto battle
if %letter% == 3 goto exit
(Tested it myself)
I think the problem is the labels, at the end you're doing :
label_name:
While it should be :label_name
Reply 6 years ago
ohk thx
Reply 6 years ago
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):
Reply 6 years ago
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!
3 years ago
@echo off && setlocal enableextensions enabledelayedexpansion
set "height=h" && set "length="
:game
cls
echo Your character is []. Move your character using the W, A, S, and D keys.
echo.
for %%H in (!height!) do echo.
echo !length![]
choice /c WASD /n
if "!errorlevel!" equ "1" set "height=!height:~0,-2!"
if "!errorlevel!" equ "2" set "length=!length:~0,-1!"
if "!errorlevel!" equ "3" set "height=!height! h"
if "!errorlevel!" equ "4" set "length=!length! "
goto :game
BOOM! 14 LINES!
9 years ago on Introduction
I am having a problem with my game everytime i type 1 (which is the option for fight)
it shows an error.What can i do to fix it
here is the code.
echo off
cls
:Menu
cls
Title The random boring encounter game
color 0a
echo The Random Boring Encounter Game
echo
echo 1) Start
echo 2) Instructions
echo 3) Exit
Choice /c 123 /n
if %errorlevel% == 1 goto starter
if %errorlevel% == 2 goto ist
if %errorlevel% == 3 goto exit
:exit
cls
echo Thanks for playing.
pause
exit
:ist
cls
echo There is a completely random chance of winning or losing.But there is a chance
echo written next to the type of the troop.Like-
echo Farmer[s] 1 out of 10 chance of losing.
echo There are 9 levels of monsters.
echo 1)Continue
set /p Gobackinfo=
if %Gobackinfo% equ 1 goto Menu
:starter
echo Picking fights.
cls
set /a points=0
set /a num=%random%
if %num% gtr 9 goto starter
if %num% lss 1 goto starter
if %num%==1 goto aa
if %num%==2 goto bb
if %num%==3 goto cc
if %num%==4 goto dd
if %num%==5 goto ee
if %num%==6 goto ff
if %num%==7 goto gg
if %num%==8 goto hh
if %num%==9 goto ii
:aa
echo Farmer[s] 1 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p aa1=
if %aa1%==1 goto fightaa
if %aa1%==2 goto run
:fightaa
cls
set /p aa2 = %random%
if %aa1% gtr 10 goto fightaa
if %aa1% lss 0 goto fightaa
if %aa1%==1 goto win5
if %aa1%==2 goto lose5
if %aa1%==3 goto win5
if %aa1%==4 goto win5
if %aa1%==5 goto win5
if %aa1%==6 goto win5
if %aa1%==7 goto win5
if %aa1%==8 goto win5
if %aa1%==9 goto win5
if %aa1%==10 goto win5
:win5
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose5
echo Loading Results.....
timeout /t 7 >nul
echo You lost the fight
echo Score=%points%
:bb
echo Hunter[s] 2 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p bb1=
if %bb1%==1 goto fightbb
if %bb1%==2 goto run
:fightbb
cls
set /p bb2 = %random%
if %bb2% gtr 10 goto fightbb
if %bb2% lss 0 goto fightbb
if %bb2%==1 goto win9
if %bb2%==2 goto lose9
if %bb2%==3 goto win9
if %bb2%==4 goto win9
if %bb2%==5 goto win9
if %bb2%==6 goto win9
if %bb2%==7 goto win9
if %bb2%==8 goto win9
if %bb2%==9 goto lose9
if %bb2%==10 goto win9
:win9
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
echo
echo
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose9
echo You lost the fight
echo
echo
echo Score=%points%
timeout /t 7 >nul
goto starter
:cc
echo Soldier[s] 3 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p cc1=
if %cc1%==1 goto fightcc
if %cc1%==2 goto run
:fightcc
cls
set /p cc2 = %random%
if %cc2% gtr 10 goto fightcc
if %cc2% lss 0 goto fightcc
if %cc2%==1 goto win8
if %cc2%==2 goto lose8
if %cc2%==3 goto win8
if %cc2%==4 goto win8
if %cc2%==5 goto win8
if %cc2%==6 goto win8
if %cc2%==7 goto win8
if %cc2%==8 goto win8
if %cc2%==9 goto lose8
if %cc2%==10 goto lose8
:win8
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose8
echo You lost the fight
echo Score=%points%
timeout /t 7 >nul
goto starter
:dd
echo horseman[s] 4 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p dd1=
if %dd1%==1 goto fightdd
if %dd1%==2 goto run
:fightdd
cls
set /p dd2 = %random%
if %dd2% gtr 10 goto fightdd
if %dd2% lss 0 goto fightdd
if %dd2%==1 goto win7
if %dd2%==2 goto lose7
if %dd2%==3 goto win7
if %dd2%==4 goto win7
if %dd2%==5 goto win7
if %dd2%==6 goto win7
if %dd2%==7 goto win7
if %dd2%==8 goto lose7
if %dd2%==9 goto lose7
if %dd2%==10 goto lose7
:win7
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose7
echo You lost the fight
echo Score=%points%
timeout /t 7 >nul
goto starter
:ee
echo King 5 out of 10 chance of losing.
echo 1] Fight him
echo 2] Run away (100% safe)
set /p ee1=
if %ee1%==1 goto fightee
if %ee1%==2 goto run
:fightee
cls
set /p ee2 = %random%
if %ee2% gtr 10 goto fightee
if %ee2% lss 0 goto fightee
if %ee2%==1 goto win6
if %ee2%==2 goto lose6
if %ee2%==3 goto win6
if %ee2%==4 goto win6
if %ee2%==5 goto win6
if %ee2%==6 goto win6
if %ee2%==7 goto lose6
if %ee2%==8 goto lose6
if %ee2%==9 goto lose6
if %ee2%==10 goto lose6
:win6
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose6
echo You lost the fight
echo Score=%points%
timeout /t 7 >nul
goto starter
:run
echo You are safe.
timeout /t 7 >nul
goto starter
:ff
echo Minotaur[s] 6 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p cc1=
if %ff1%==1 goto fightff
if %ff1%==2 goto run
:fightff
set /p ff2 = %random%
if %ff2% gtr 10 goto fightff
if %ff2% lss 0 goto fightff
if %ff2%==1 goto win4
if %ff2%==2 goto lose4
if %ff2%==3 goto win4
if %ff2%==4 goto win4
if %ff2%==5 goto win4
if %ff2%==6 goto lose4
if %ff2%==7 goto lose4
if %ff2%==8 goto lose4
if %ff2%==9 goto lose4
if %ff2%==10 goto lose4
:win4
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:run
echo You are safe.
timeout /t 7 >nul
goto starter
:lose4
echo You lost the fight
echo Score=%points%
timeout /t 7 >nul
goto starter
:gg
echo Giant[s] 7 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p gg1=
if %gg1%==1 goto fightgg
if %gg1%==2 goto run
:fightgg
set /p gg2 = %random%
if %gg2% gtr 10 goto fightgg
if %gg2% lss 0 goto fightgg
if %gg2%==1 goto win1
if %gg2%==2 goto lose1
if %gg2%==3 goto win1
if %gg2%==4 goto win1
if %gg2%==5 goto lose1
if %gg2%==6 goto lose1
if %gg2%==7 goto lose1
if %gg2%==8 goto lose1
if %gg2%==9 goto lose1
if %gg2%==10 goto lose1
:run
echo You are safe.
timeout /t 7 >nul
goto starter
:win1
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose1
echo You lost the fight
echo Score=%points%
timeout /t 7 >nul
goto starter
:hh
echo Titan[s] 8 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p hh1=
if %hh1%==1 goto fighthh
if %hh1%==2 goto run
:fighthh
set /p hh2 = %random%
if %hh2% gtr 10 goto fighthh
if %hh2% lss 0 goto fighthh
if %hh2%==1 goto lose2
if %hh2%==2 goto lose2
if %hh2%==3 goto lose2
if %hh2%==4 goto lose2
if %hh2%==5 goto lose2
if %hh2%==6 goto win2
if %hh2%==7 goto win2
if %hh2%==8 goto lose2
if %hh2%==9 goto lose2
if %hh2%==10 goto lose2
:run
echo You are safe.
timeout /t 7 >nul
goto starter
:win2
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
echo
echo
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose2
echo You lost the fight
echo
echo
echo Score=%points%
timeout /t 7 >nul
goto starter
:ii
echo God[s] 9 out of 10 chance of losing.
echo 1] Fight them
echo 2] Run away (100% safe)
set /p ii1=
if %ii1%==1 goto fightii
if %ii1%==2 goto run
:fightii
set /p ii2 = %random%
if %ii2% gtr 10 goto fightii
if %ii2% lss 0 goto fightii
if %ii2%==1 goto lose3
if %ii2%==2 goto lose3
if %ii2%==3 goto lose3
if %ii2%==4 goto lose3
if %ii2%==5 goto lose3
if %ii2%==6 goto win3
if %ii2%==7 goto lose3
if %ii2%==8 goto lose3
if %ii2%==9 goto lose3
if %ii2%==10 goto lose3
:win3
echo Loading Results.....
timeout /t 7 >nul
cls
echo You Won!!!!!!
echo
echo
set /a points=1+%points%
echo Score=%points%
timeout /t 7 >nul
goto starter
:lose3
echo You lost the fight
echo
echo
echo Score=%points%
timeout /t 7 >nul
goto starter
:run
echo You are safe.
timeout /t 7 >nul
goto starter
Reply 3 years ago
Try running the batch file from cmd. The error mesage will show up and you can fix it accordingly.
For example:
This batch file has an error:
@echo off
If %1 == goto no
Echo %1 & exit /b
:no
Echo No arguments! & exit /b
If you run it from cmd with arguments:
F:\> test.bat Test
Test
If you run it from cmd without arguments:
F:\> test.bat
goto was unexpected at this time.
Hope this was useful for you!