How to Create a Playable Video Game from the Command Prompt

Table of contents:

How to Create a Playable Video Game from the Command Prompt
How to Create a Playable Video Game from the Command Prompt
Anonim

This article explains how to create a simple text game with Command Prompt, on a Windows computer.

Steps

538705 1
538705 1

Step 1. Open Notepad

This free text editor is pre-installed on all Windows computers. You will use it to enter the code. To open it, follow these steps:

  • Click Start

    Windowsstart
    Windowsstart

    ;

  • Write Notepad;
  • Click Block notes at the top of the window.
538705 2
538705 2

Step 2. Give your game a title

Copy the following text to Notepad, making sure to replace "[Title]" with your preferred term, before pressing Enter:

@echo off title [Title]

538705 3
538705 3

Step 3. Choose a color for the text and background of your game

The Command Prompt allows you to use text and backgrounds of various colors, which you can select with a specific code from the format "0A", where "0" is the background color and "A" is the text color. The codes for the most common colors are as follows:

  • Text Colors: Use A, B, C, D, E, or F for light green, light blue, light red, light purple, light yellow, or white.
  • Background Colors: Use 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9 for black, blue, green, light blue, red, purple, yellow, white, gray, or light blue.
  • For example, if you want to recreate the normal black and white command prompt interface, use the code "0F".
538705 4
538705 4

Step 4. Set the game colors

Enter the following text in Notepad, making sure to replace "0A" with your preferred text and background color scheme, before pressing Enter:

@echo off title Trial game color 0A if "% 1" neq "" (goto% 1)

538705 5
538705 5

Step 5. Create the game menu

This part of the code basically represents the start menu. Enter the following text in Notepad, then press Enter:

: Menu cls echo 1. Start echo 2. Credits echo 3. Exit set / p answer = Type the answer number and press Enter: if% answer% == 1 goto Start_1 if% answer% == 2 goto Titles of queue if% answer% == 3 goto Quit

538705 6
538705 6

Step 6. Add the output option

By selecting it, players will be able to close the Command Prompt. Enter the following text on Notepad, then press Enter:

: Quit cls echo Thanks for playing! pause exit / b

538705 7
538705 7

Step 7. Add the game credits

Enter the following text in Notepad, making sure to replace "[Title]" with your game title, before hitting Enter:

: Credits cls echo Credits echo. echo Thanks for playing [Title]! pause goto Menu

538705 8
538705 8

Step 8. Create the "Get Started" code

This part of the code allows players to start a new game:

: Start_1 cls echo Oh no! You are surrounded by enemies. echo There are five of them, all armed. echo If you face them, you have a high chance of winning. set / p answer = Do you prefer to escape or fight? if% answer% == fight goto Fight_1 if% answer% == run goto Escape_1 pause

538705 9
538705 9

Step 9. Add the action code

Finally, enter the following part of the program to create the game action:

: Escape_1 cls echo You survived safe and sound. pause goto Start_1: Fight_1 echo Get ready to fight. echo Enemies attack you all at once. set / p answer = Press 1, then Enter to continue. if% answer% == 1 goto Lotta_1_Loop: Lotta_1_Loop set / a num =% random% if% num% gtr 4 goto Lotta_1_Loop if% num% lss 1 goto Lotta_1_Loop if% num% == 1 goto Lotta_Lotta_1 if% num% == 2 goto Battle_Victory_1 if% num% == 3 goto Battle_Victory_1 if% num% == 4 goto Battle_Victory_1: Defeat_Fight_1 cls echo You have been defeated. Do you want to play again? pause goto Menu: Victory_Fight_1 cls echo You have won! set / p answer = Do you want to save? [y / n] if% answer% == 'y' goto 'Save' if% answer% == 'n' goto 'Start_2': Save goto Start_2

538705 10
538705 10

Step 10. Click File

You will see this entry in the upper left corner of the Notepad window. Press it and a drop-down menu will appear.

538705 11
538705 11

Step 11. Click Save As in the File menu

The save window will open.

538705 12
538705 12

Step 12. Name the file, followed by the extension ".bat"

Type your preferred name in the "Filename" text field at the bottom, followed by.bat, to save the game as a Command Prompt file.

For example, to call your game "Dungeon Adventure", you would write Dungeon Adventure.bat

538705 13
538705 13

Step 13. Change the file type

Click the "Save As" menu at the bottom of the window, then click All files among the items that appear.

538705 14
538705 14

Step 14. Save the file to your desktop

To do this, click Desktop in the left sidebar. If you can't see the item you're looking for, swipe the bar up or down.

538705 15
538705 15

Step 15. Click Save in the lower right corner of the window

You will save the game as a BAT file.

538705 16
538705 16

Step 16. Start the game

Double-click the BAT file to open it in the Command Prompt, then follow the on-screen prompts.

  • For example, press

    Step 1. to start the game.

538705 17
538705 17

Step 17. Experiment with the code

Now that you've created the basic structure of the game, you can edit it to change the text, add options, and much more.

  • To change the game code, right click on the BAT file, then click Edit in the drop-down menu. You can press Ctrl + S to save the changes.
  • Make sure you read the code thoroughly to understand what each line does.

Advice

  • If you want to use a more advanced editor for your code, you can download and install Notepad ++, then use it to create a BAT file instead of Notepad.
  • When you want the player to read a message, you have to type the echo command first.
  • Try the game while writing the code, even if you are not done yet; this way you will be able to better understand how what you type in the Command Prompt is displayed and, in addition, you will notice errors and problems first.
  • On Windows, you can use Batch files to automate many tasks, but writing a text game is a fun way to learn how they work.

Warnings

  • Always double check your code before distributing your BAT file.
  • Never download and never run BAT files that come from untrustworthy sources, as they can be used to cause damage to your system.

Recommended: