This is one of the free and easy ways to make video games. You also don't need to download it. In the process, you'll learn a bit about batch programming. You need to provide your own story to run this game.
Step
Step 1. Anything inside the apostrophe can be changed, it won't affect the game – don't type it in the actual code
Step 2. Open Notepad or another coder program - Geany, Notepad++, etc
Save the file with the name 'My Games'.bat
Step 3. Start writing the code
Start by typing:
-
@echo off
-
title 'My Game'
-
color 0A
-
if "%1" neq "" (goto %1)
-
pause
Step 4. Add color
Now save and run. The program will throw up an error and a completely different color combination. Find a color you like and type after “color” instead of “zz”. A good combination is color 0A, which results in green text and a red background.
Step 5. Create a Menu
To create a menu, omit the pause section and type:
-
:Menu
-
cls
-
echo '1. Start'
-
echo '2. Instruction'
-
echo '3. Go out'
-
set /p answer='Enter the number of your choice and press enter.'
-
if %answer%==1 goto 'Start_1'
-
if %answer%==2 goto 'Hint'
-
if %answer%==3 goto 'Exit'
Step 6. Create an 'Exit' and a 'Hint'
To make the screen exit, type the following code:
-
:'Go out'
-
echo Thanks for playing!
-
exit /b
- Now for the hint menu, type:
-
:'Instruction'
-
cls
-
echo 'Hint'
-
echo.
- Then write:
-
echo 'Your hint here'
- As many as you like, then type:
-
pause
-
goto Menu
Step 7. Start the game
Type in a scenario:
-
:Start_1
-
cls
-
echo 'You met a bad person. Their troops are:'
-
echo '3 farmers'
-
echo 'You have a good chance of winning.'
-
set /p answer='Do you want to fight or run?'
-
if %answer%=='Fight' goto 'Fight_1'
-
if %answer%=='Run' goto 'Run_1'
Step 8.
Fight and Run.
Now to create the fight and run menu:
-
:Run_1
-
cls
-
echo you are safe!
-
pause
-
goto 'Start_1'
-
:fight_1
-
echo You choose to fight.
-
echo The battle begins.
-
set /p answer= Type the number 1 and press enter to continue:
-
if %answer%==1 goto Bertarung_1_Loop
-
:'Fight_1_Loop'
-
set /a num=%random%
-
if %num% gtr 4 goto 'Fight_1_Loop'
-
if %num% lss 1 goto 'Fight_1_Loop'
-
if %num%==1 goto 'Lose_Bertarung_1'
-
if %num%==2 goto 'Win_Battle_1'
-
if %num%==3 goto 'Win_Battle_1'
-
if %num%==4 goto 'Win_Battle_1'
-
:'Lost_Fight_1'
-
cls
-
echo Sorry, you lost!(
-
pause
-
goto Menu
-
:'Win_Fight_1'
-
cls
-
echo Congratulations, you won!
-
set /p answer='Do you want to save it?'
-
if %answer%=='Yes' goto 'Save'
-
if %answer%=='No' goto 'Start_2'
-
:'Save'
-
goto 'Start_2'
- Now you can repeat the code used in 'Start_1' to create the second, third, fourth, and so on.
- Also, if you type for example: Fight_1 you should also make sure that the part that says goto Fight_1 stays the same as the other so that if you change one you'll have to change both.
Close Notepad, then click yes, save the file. Change the format to all files and add.bat after the name.
Tips
- Remember, whenever you want something visible to the user, type echo in front of it.
- Play the game as it builds even if it's not finished yet. This will help you see the relationship between what you typed in and what you get and detect errors.
- If you need to exit in the middle of a game test, type Ctrl-C.
- Batch files in Windows can be used for automated work, but writing text games like this is a fun way to see how it works.
- Check the batch script carefully and you will find out which one is wrong.
- A very common error is that the program does not run.