Want to write a simple computer game using Notepad on your PC? Even if you've never written a game before, this tutorial will help you write a basic batch script computer game using easy commands.

Steps

  1. 1
    Decide on a game. Before deciding to make a shoot-em-up game or point-and-click game, know that even with MS DOS 8, batch script has serious limitations to its capabilities. You will not be able to create more of a game than a text-based game. It can be a quiz or a scenario game, but you will have only text. As to whether or not you want to have ASCII graphics is up to you, but the game will still be based entirely on text input.
  2. 2
    Learn the script. The script is not that hard to learn, you may even learn it simply by looking at a program. To know any scripting language you may need to know some basic commands in your computer's command line. For this command line, the basic commands that you will need are:
    • echo
    • color
    • title
    • goto
    • if
    • set
    • labeling (not a command, but how to label)
    Advertisement
  3. 3
    Learn how to use the above commands.
  4. 4
    Start scripting your game. It is suggested that a beginner use notepad, but if you would like to use MS DOS EDIT, that's fine, too. It is also suggested to a beginner to begin with a basic quiz game, so this is what this article will show you how to do. Remember to start by turning off the echo. Then introduce your game with some text through the echo command, then use set to allow input with the goto command. This may sound confusing, so look above (Note: the command REM creates comments, i.e. notes for the developer that won't show in the final result):
  5. 5
    Work on the instructions page. At this point, you should save your file(save as something.bat), and put it in a folder that you created for the game. After saving it, run it and make sure it works.
  6. 6
    Work on the contents of the game itself. This is where most of your creativity/research, work, and time is spent working on the game, as well as where most of the game's scripting should be. There should be a place that you go when you get an answer wrong, and a way to advance to the next question when you get the answer right. The above will have basic questions about the exterior of a car. You may replace them with what you like.
    • Run the program and make sure it works.
  7. 7
    Create a winning screen. Creating a winning screen is as simple as the instructions screen. Create a text document with praise for winning and save it as WIN.txt in the batch folder. Add the following lines to the end of your game for the winning screen:
  8. 8
    Your game should now look like the code above:
    • Run the program and make sure it works.
  9. 9
    Touch up your file. Start by going to each label and placing the cls command after it. This will clear the screen at each label so you don't have a screen full of unnecessary information.
  10. 10
    Correct grammar where appropriate. If you want, make all of the answers on the list complete sentences. NOTE THAT YOU SHOULD AVOID CONTRACTIONS IN THE BATCH SCRIPT ECHO COMMAND! You should also avoid slashes and greater than/less than symbols, stars, percent symbols, and any other unusual symbols. These symbols will create a syntax error that causes the program to stop, lag, or crash.
  11. 11
    Create graphics for the game if you would like. Generate ASCII art in separate text documents and use the type command to display them in the program:
  12. 12
    Correct any typing errors that you can find. Think of your own things to correct. Then add your color with the color command. It is suggested that you place it at the beginning of the program so that the whole program is of this color. Here is the explanation of how to use it directly from the command line:

    Sets the default console foreground and background colors.

    COLOR [attr]

    attr Specifies color attribute of console output

    Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second the foreground. Each digit can be any of the following values:

    0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White

    If no argument is given, this command restores the color to what it was when CMD.EXE started. This value either comes from the current console window, the /T command line switch or from the Default Color registry value.

    • In other words, if you wanted a bright white background and black text:

      @echo off
      color f0
      :MAIN
      cls
      echo.
      
  13. 13
    Congratulations, you have just created a basic computer game with batch script!
  14. Advertisement

Community Q&A

  • Question
    Is it possible to add sound to the game, and can this be done on DosBox?
    Community Answer
    Community Answer
    Yes, you can do this on DosBox. It is basically like the command prompt, but just a different program.
  • Question
    Why won't my command prompt work? When I open it, it closes straight away.
    Community Answer
    Community Answer
    The command prompt is most likely blocked by the administrator if you are coding from a work or school computer.
  • Question
    How do I open the code for my batch file?
    Community Answer
    Community Answer
    Open Notepad. Write the code into the window and save it. You can open the file later by right-clicking the file and opening it with Notepad. Make sure you don't make Notepad the default program, though, or else double-clicking the script will open it in Notepad instead of running it.
Advertisement

Warnings

  • It is often times said that it is illegal to send batch files over the internet. By no means is this true, but be aware of the fact that you may get in trouble for sending dangerous batch files over the internet(e.g.: batch files that crash the computer, delete vital system files, etc...). They are not called viruses, but they are still harmful and you can get in serious trouble for them.
    ⧼thumbs_response⧽
  • NEVER put any MS DOS commands in the echo command, as they will be carried out. Remember that everything displayed by the command line is an echo!
    ⧼thumbs_response⧽
  • NEVER put any MS DOS commands in the text files that are typed out to the console. Text files solve some problems, such as the slashes and stars, but commands in them will still be carried out by the system.
    ⧼thumbs_response⧽
  • Be wary of the "del" command. Although it can be used to delete, for example, users for a longer game, it is unrestricted and can be used to delete anything, including vital files. NEVER use this command until you really know what you're doing with it.
    ⧼thumbs_response⧽
Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 42 people, some anonymous, worked to edit and improve it over time. This article has been viewed 324,803 times.
How helpful is this?
Co-authors: 42
Updated: January 29, 2022
Views: 324,803
Categories: Programming
Advertisement