Making a Batch File Game (Part 1).

by MarkosJ_BatCoding in Circuits > Software

737 Views, 1 Favorites, 0 Comments

Making a Batch File Game (Part 1).

687474703a2f2f646d6e763434666433696d64762e636c6f756466726f6e742e6e65742f7777772e707573686d6f6e2e636f6d2f696d672f636f64652f62617463682e676966.gif

HELLO! and welcome to my instructible about how to make a basic game using windows batch. Batch or CMD is a coding language that windows uses throughout its system. Making a batch or bat file can be extremely useful. For example, if you wanted to open multiple programs at the same time, then just make a basic bat file to do it with just a click.

To begin you will need to have a working windows computer, and a keyboard and mouse. Make sure you get a comfortable keyboard as you may end up coding for what feels like hours!

Supplies

1 Windows computer

2 Keyboard and mouse

3 Some enthusiasm! coding can be slow and tedious but you can make some really cool stuff.

Learning the Basic Functions of Batch Programing.

Capture.PNG
Capture 3.PNG
Capture 2.PNG
Capture 4.PNG

The image above is the first of many functions for bat. What @echo off does is it clears the screen and debugs the program you've created. This makes a clean slate to start programing off.


The next command is the echo command. It displays a piece of text to the user, which helps you better understand the coding. Open the notepad program and type at the top:

@echo offecho hello world

Now save the file as test.bat this will ensure the program is saved as a batch file and not just a notepad file, do this by saving it as test.bat. Now run the program by double clicking it. You should see a cmd file flash up on the screen then immediately disappear. This is because we haven't told the program to keep the test on screen. To do this just type pause underneath the echo hello world.

@echo offecho hello worldpause

Now save and run the program again. Now it should show the text your wrote in a black box. This is your first batch file. Congrats!

The next step is to add the cls command or the clear screen command. This command clears the screen, to help de-clutter everything a bit and to remove text that has been previously displayed. enter the program below and see what it does.

@echo offecho hello worldpausecls

Variables.

Capture 5.PNG
Capture 6.PNG

Now you have mastered the basics of Batch, you should know what variables are how to implement them. The first piece of code we need to explore is the set command. This command will activate a variable. bellow is an example of the set command

@echo offset /p variable=echo you typed: %variable%pausecls

Allow me to explain what all this means.

The piece of code that reads set /p variable: means "set the variable's name to variable. The /p tells the computer that it is a variable.

The next part echo you typed: %variable% The echo tells the computer to display the words in front of it onscreen, and the word in the percent is what the variable is. For example, when I put this piece of code in a notepad and save that as a batch file and open it. It will show me a blank screen where I can type in. After I type in and press enter, the screen will show You typed: and then what ever you previously typed. Give it a go and see how it works.

If Than / Else Statements, and Sending to Other Places.

These statements will help you decide what happens in your game or program. We can use the if than or else statement to make a decision part of the game. It works like this, if the player types in the word "yes" then move to level 2, if anything else is pressed, then send them back to level 1.

Do you understand where I'm going with this?

Here is the code we need to use, ill explain it down below.

@echo offecho you are on level 2, do you wish to continue? YES or NOset /p choice=if %choice%==yes goto :level2 if NOT goto :level1:level1echo test level 1pausecls:level2echo test level2pausecls

Now its starting to get a little complicated. The set /p choice= piece of code tells the system to create a variable.

if the variable is detected as being the word YES then it will send you to level 2. If anything else is detected, then you will be sent back to level 1.


The :level1 and :level2 are the places in which to be sent.

Now you have learnt how to use basic batch. Part 2 will include a step by step tutorial on how to make a text-based adventure game. I hope you enjoyed and had fun learning.

===LEGAL STUFF===

Notepad, Batch, Windows, and any other associated programs are property of Microsoft, and were used only to educate and inform the public (you). If you have received any of these programs illegally, Microsoft has received no payment for these striped copies of these programs. Any damage including injury and property damage are not my fault and I take no responsibility for your actions. Please support Microsoft the original creators of the programs by purchasing Windows or any associated program.