PDF download Download Article PDF download Download Article

This wikiHow teaches you how to make a simple, text-based game in Command Prompt on a Windows computer.

  1. Notepad is a free text editor which is pre-installed on all Windows computers. You'll use Notepad to input your code. To open it, do the following:
    • Click Start
      Windows Start
    • Type in notepad
    • Click Notepad at the top of the window.
  2. Copy the following text into Notepad—making sure to replace "[Title]" with whatever you want to name your game—and then press Enter : [1]
     @ 
     echo 
    off title 
    [Title]
    Advertisement
  3. 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]
    • 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".
  4. 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 
     ) 
    
  5. 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 
    
  6. 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
  7. 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 
    
  8. 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 
    
  9. 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 
    
  10. It's in the top-left corner of the Notepad window. A drop-down menu will appear.
  11. It's in the File drop-down menu. Doing so will open a Save As window.
  12. 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.
  13. Click the "Save as type" drop-down box at the bottom of the window, then click All Files in the resulting drop-down menu.
  14. 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.
  15. It's in the bottom-right corner of the window. Doing so will save your game as a BAT file.
  16. 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.
  17. 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.
  18. Advertisement


Community Q&A

Search
Add New Question
  • Question
    Do I need to put a quote mark before and/or after echoing something?
    Community Answer
    No. After echoing, make a space and write what you want to display in a single line.
  • Question
    What is a bat file, and where do I put it?
    Community Answer
    A 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.
  • Question
    When I click to open the game it opens and immediately closes. Why does it do that?
    Community Answer
    It 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.
See more answers
Ask a Question
      Advertisement

      Tips

      Show More Tips

      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.
      • 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.
      Advertisement

      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.

      Did this article help you?

      Advertisement