Download Article
Download Article
This wikiHow teaches you how to make a simple, text-based game in Command Prompt on a Windows computer.
Steps
-
Add the title text for your game. Copy the following text into Notepad—making sure to replace "[Title]" with whatever you want to name your game—and then press ↵ Enter : [1] X Research source
@ echo off title [Title]
Advertisement -
Choose a color for your game's text and background. Command Prompt offers several different colors of text and background which you can trigger by inputting a color-specific code in "0A" format where "0" is the color of the background and "A" is the color of the text. Codes for common colors include the following: [2] X Research source
- Text Colors — Use A, B, C, D, E, or F to refer to light-green, light-aqua, light-red, light-purple, light-yellow, or bright-white, respectively.
- Background Colors — Use 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9 to refer to black, blue, green, aqua, red, purple, yellow, white, grey, or light-blue, respectively.
- For example, the standard black-and-white Command Prompt interface would use the code "0F".
-
Set your game's colors. Enter the following text into Notepad—making sure to replace "0A" with your preferred background and text combination—and then press ↵ Enter :
@ echo off title OnlineCmag Game color 0A if " %1 " neq "" ( goto %1 )
-
Create the game menu. This is essentially the game's startup menu. Enter the following text into Notepad, then press ↵ Enter :
: Menu cls echo 1. Start echo 2. Credits echo 3. Exit set /p answer = Type the number of your option and press enter : if %answer% == 1 goto Start_1 if %answer% == 2 goto Credits if %answer% == 3 goto Exit
-
Add an "Exit" option. This is how players will be able to exit the Command Prompt. Enter the following text into Notepad, then press ↵ Enter :
: Exit cls echo Thanks for playing! pause exit /b
-
Add credits for the game. Enter the following text into Notepad—making sure to replace "[Title]" with your game's title—then press ↵ Enter :
: Credits cls echo Credits echo . echo Thank you for playing [Title]! pause goto Menu
-
Create the "Start" code. This is the code which will allow players to start a new game:
: Start_1 cls echo Oh no! You're surrounded by enemies. echo There are five of them, and they're all armed. echo If you fight them, you are having a high chance of winning. set /p answer = Would you like to fight or run? if %answer% == fight goto Fight_1 if %answer% == run goto Run_1 pause
-
Add the action code. Finally, you'll enter the following code to dictate the action of the game:
: Run_1 cls echo You live to fight another day. pause goto Start_1 : Fight_1 echo Prepare to fight. echo The enemies suddenly rush you all at once. set /p answer = Type 1 and press Enter to continue. if %answer% == 1 goto Fight_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_Fight_1 if %num% == 2 goto Win_Fight_1 if %num% == 3 goto Win_Fight_1 if %num% == 4 goto Win_Fight_1 : Lose_Fight_1 cls echo You were defeated. Play again? pause goto Menu : Win_Fight_1 cls echo You are victorious! set /p answer = Would you like to save? [y/n] if %answer% == 'y' goto 'Save' if %answer% == 'n' goto 'Start_2' : Save goto Start_2
-
Click File . It's in the top-left corner of the Notepad window. A drop-down menu will appear.
-
Click Save As… . It's in the File drop-down menu. Doing so will open a Save As window.
-
Enter a file name followed by the ".bat" extension. In the "File name" text box that's near the bottom of the window, type in whatever you want to name the game followed by .bat to ensure that the game will save as a Command Prompt file.
- For example, to name your game "Dungeon Crawl", you would type in Dungeon Crawl.bat here.
-
Change the file type. Click the "Save as type" drop-down box at the bottom of the window, then click All Files in the resulting drop-down menu.
-
Select the desktop as the save location. Click Desktop in the left-hand sidebar to do so. You may first have to scroll up or down on the sidebar in order to find the Desktop folder.
-
Click Save . It's in the bottom-right corner of the window. Doing so will save your game as a BAT file.
-
Run your game. Double-click the BAT file to open your game in Command Prompt, then follow the on-screen prompts.
- For example, you'll press 1 to start the game.
-
Experiment with the code. Now that you have the basic groundwork laid out for the game, you can edit the code to change the in-game text, add options, and more.
- To edit your game's code, right-click the BAT file and then click Edit in the drop-down menu. You can then press Ctrl + S to save any changes.
- Make sure you read through the code to understand what each line of text does.
Advertisement
Community Q&A
Search
-
QuestionDo I need to put a quote mark before and/or after echoing something?Community AnswerNo. After echoing, make a space and write what you want to display in a single line.
-
QuestionWhat is a bat file, and where do I put it?Community AnswerA bat file is a batch file, and it runs on cmd (command prompt). You can put it on your desktop to make it easier to test your stuff.
-
QuestionWhen I click to open the game it opens and immediately closes. Why does it do that?Community AnswerIt is because the coding is wrong. Actually there are few lines on the codes that are to instruct us and make us understand, but which are not supposed to be written on the source code(code area). So just scan through the code lines and delete those unnecessary lines. Doing this should make your game work.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
- If you'd like to use a more advanced code editor, you can download and install Notepad++ and then use it to create a BAT file rather than using Notepad.Thanks
- Whenever you want something to be seen by the player, you have to type echo in front of it.Thanks
- Play your game along the way, even if you don't have the whole thing done; doing so will help you to see how what you type corresponds with what shows up in Command Prompt, and it will also allow you to catch bugs or typos early on.Thanks
Tips from our Readers
The advice in this section is based on the lived experiences of wikiHow readers like you. If you have a helpful tip you’d like to share on wikiHow, please submit it in the field below.
- Make sure there are no spaces before your commands, that can cause the file not to launch.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement
Warnings
- Always proofread your code before distributing your BAT file.Thanks
- Never download and run BAT files from any source you don't trust, as they can be used to harm your computer if they're malicious.Thanks
Advertisement
References
About This Article
Article Summary
X
1. Open Notepad.
2. Type your game code.
3. Save your code as a .bat file.
4. Double-click the .bat file to run the game in a CMD window.
Did this summary help you?
Thanks to all authors for creating a page that has been read 476,530 times.
Advertisement