How to create a video game with the command prompt

Table of contents:

How to create a video game with the command prompt
How to create a video game with the command prompt

You dream of creating your own video game, but you don't know anything about programming. To get a feel for batch programming and with a little story in mind, bring your first video game to life.


Make a Video Game With Cmd Step 1

Step 1. Pay attention

In the programming that you are going to do, the data in quotes is editable, but do not change other pieces of code.

Make a Video Game With Cmd Step 2

Step 2. Go to simple programming software

Take software like Notepad, Notepad ++ or Geany. After opening one of these programs, make a backup of your new document by titling it "My game.bat", for example.

Make a Video Game With Cmd Step 3

Step 3. Start registering lines of code

To start, write:

  • @echo off

  • title 'My game'

  • color 0a

  • if "% 1" neq "" (goto% 1)

  • pause

Make a Video Game With Cmd Step 4

Step 4. Choose a color

Make a backup of your file then launch it. Your file will open and ask you to choose a color following a two-digit code. The first will be for the background color and the second number for the foreground color. For the example, choose the code "0A", which will give you a black background with light green text. You will have to replace "zz" in front of "color" by the code "0A", then save.

Make a Video Game With Cmd Step 5

Step 5. Tap the menu

Delete "pause", then enter the following lines:

  • :Menu

  • cls

  • echo ‘1. To start up'

  • echo ‘2. Instructions'

  • echo ‘3. To leave'

  • set / p answer = ‘Enter the number of your option, then press the Enter key.’

  • if% answer% == 1 goto ‘Start_1’

  • if% answer% == 2 goto ‘Instructions’

  • if% answer% == 3 goto ‘Quit’

Make a Video Game With Cmd Step 6

Step 6. Type the lines of code for "Exit" and "Instructions"

Write the information for "Exit" and "Instructions", like this:

  • :'To leave'

  • echo Thanks for playing!

  • exit / b

  • Enter for "Instructions", this:
  • :'Instructions'

  • cls

  • echo "Instructions"

  • echo.

  • Then type:
  • echo "The instructions you want, here"

  • Finally, write the number of times that is necessary:
  • pause

  • goto Menu

Make a Video Game With Cmd Step 7

Step 7. Start the game

Write the scenario of your story:

  • : Start_1

  • cls

  • echo ‘You come face to face with enemies. They are:'

  • echo "3 peasants"

  • echo "You have a chance to win the fight"

  • set / p answer = ‘Do you want to fight or flee?’

  • if% answer% == ‘Fight’ goto ‘Fight_1’

  • if% answer% == ‘Escape’ goto ‘Escape_1’

Step 8.

  • Integrate the phases of the game.

    Write the lines of code for fight and flight:

    Make a Video Game With Cmd Step 8
    • : Flee_1

    • cls

    • echo You have fled and are safe!

    • pause

    • goto ‘Start_1’

    • : Fight_1

    • echo You have taken the option of fighting.

    • echo The fight is in progress.

    • set / p answer = Enter the number 1 and press the Enter key to continue:

    • if% answer% == 1 goto Combat_1_Loop

    • : ‘Combat_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 ‘Lost_Combattre_1’

    • if% num% == 2 goto ‘Won_Combattre_1’

    • if% num% == 3 goto ‘Won_Combattre_1’

    • if% num% == 4 goto ‘Won_Combattre_1’

    • : ‘Lost_Combattre_1’

    • cls

    • echo Sorry, you just lost the fight:(

    • pause

    • goto Menu

    • : ‘Gagné_Combattre_1’

    • cls

    • echo Congratulations, you just won the fight!

    • set / p answer = ‘Do you want to save? '

    • if% answer% == ‘Yes’ goto ‘Save’

    • if% answer% == ‘No’ goto ‘Start_2’

    • :'To safeguard'

    • goto ‘Start_2’

    • Repeat the lines of code from "Start_1", if you want to create a second or more stages in your game.
    • Remember to be careful. For example for "Combattre_1", make sure that the lines of code "goto Combattre_1", are all well written identically (without typo) for it to work.
  • Complete your file. Once you are done writing your lines of code, save your work and close your file. Then change the file extension to.bat.

    Make a Video Game With Cmd Step 9
  • Advice

    • To make sure that the player can see something, you will have to each time use "echo" just in front of what you want to display to the player.
    • Try out your game little by little as you build it. So you will immediately see the result of what you have just written and if you see an error, you can correct it right away.
    • To exit in the middle of a test of your game, press the CTRL and C keys.
    • Batch programming allows you to create files that automatically launch operations on Windows. Note that playing a little game using the same language is an original way to learn about batch programming.
    • Take the time to re-read your batch script and you will easily find out if there are any errors.
    • One of the most common errors is when the file does not run.

    Popular by topic