Create game |
Introduction
Did you understand that the easy Notepad program on your computer is actually a very mighty programming tool? That's right, and it is also very very simple to discover. In this article I'm going to display you how to make a easy game using only the Notepad program and a programming dialect called "Batch."
Batch is a dialect that sprints mainly out of your Windows order punctual. Now, it's not even close to
Not only is it useful, but it can furthermore be used to conceive amazing text-based sport! What is a text-based game you ask? It's a game (a very easy one) in which the client interacts through the use of text and choice-making.You will learn how to set up positions in which the characters will have to make alternatives about how they desire to approach the problem.
A couple of Quick Reminders
I desire to proceed over a couple of quick things before we get in to the genuine cipher. The first thing is that all of your instructions should be kept on distinct lines. So after you kind certain thing in, and are done with what is going to be on that line, hit the "enter" button on your keyboard to move to the next line.
The second thing I want to mention is that batch files read from peak to base. This means that when you run a batch document, all of your cipher at the peak will be interpreted and will run before your code at the base. This concept is what allows some of the things I'm going to educate you, to work. If for example you location a "echo" order and in the next line location a "cls" order, all of your text will be rubbed out without your contestant getting to read it (this will make more sense subsequent on).
If you ever have a problem and your game isn't working rightly, make sure you go back and double-check that you haven't made any of these errors.
Starting Up Notepad
Let's
start by opening up Notepad:
Click on
your start menu icon and go to "All Programs." A list of all the
programs on your computer should appear, along with a file called
"Accessories." Go in to the accessories folder and you should find
Notepad, click on it to begin.
You
should find Notepad in the Accessories folder.
Code!
Now
you're ready to begin typing your first lines of code, as well as learning you
first commands. Commands are each of the words that we type in to the program
that have a function; such as the echo, or pause commands.
@echo off, echo, echo. and pause
The first
commands I'm going to teach you are very simple, however, they play an
important part in the coding process (especially if you're making a game!).
@echo off - This command is used to remove
all of the unnecessary text that can interfere with your game. It should always
be added first; once it is added to a file, it does not have to be typed in
again.
echo - echo is used to display regular
text in your game. For example you can type: "echo Hello
adventurer!", and the people playing your game will see is "Hello
adventurer!" (So long as you typed in @echo off).
echo. - echo. (with a period) is used
to create a blank line in your game. This can be useful in keeping your text
uncluttered.
pause - This command is used when you
want your players to take a break, and is used most often when you want to give
them time to read some text. When you use this code it shows up as "Press
any key to continue . . ." Your players can then press any key, when they
are ready, in order to continue playing.
This is
what your game should look like. Notice the long spaces between the text? This
was done with the "echo." command. Also, note the pause command at
work toward the bottom.
This is
what your game should NOT look this. When you don't add "@echo off"
this is what happens.
color 71
and "My Game" in the title bar.
cls, exit, title, and color
Ok, this
next set of commands are all really simple as well, but are nice to have.
cls - cls is a command that I use a
lot. It stands for "clear screen", and what it does is remove all of
the text that has been made in the command prompt window (ergo, making the screen
blank). This is a good tool when you want to keep your game looking clean and
in order.
exit - This does exactly what it
sounds like, it closes the game. You should only use this when the characters
reach the end of the game, or if you want the game to close when they die or
make a wrong decision.
title - title displays whatever you
type after it in the title bar of the command prompt window.
color - color is a really fun command,
and can be used to liven up your game. When you add the color code, followed by
a space and a specific set of numbers or letter, you can change the colors of
the command prompt window. For a list of the available colors see the picture
below or open up the command prompt and type in "color/?".
You can
access the command prompt by going back in to the accessories folder in the
start menu. It should be in the same list as Notepad.
This is
what you will get if you type "color/?" in to the command prompt.
This is
about what you should be capable of doing at this point.
Let's Take A Break
Let's
stop for a second and look at what we have so far. I've shown you several basic
commands, and have taught you how to use them. Remember that each command
should go on a different line (so hit "enter" after you finish with
each command). Take a look at the picture to the right, so that way you can be
sure that you know about what your file should look like.
goto
The
"goto" command is simple, once you get to know it. The command is
used when you want a player to jump to a different section of your game, such
as when they make a certain decision.
It works
this way:
You enter
the "goto" command on a separate line, or at the end of an
"if" statement (which we will go over later). You then specify a
variable which will become the name of the destination. The name can be
anything you want, and consists of the word(s) you type after "goto".
To
specify your destination:
Move to a
new line of code, directly above where you want your player to start. Type a
colon ':' followed by the name of the destination.
example
of a goto command.
set /p and if
These
commands are the most advanced commands that I am going to teach you. They both
have to be set up a specific way and also work with several other, smaller
commands in order to function correctly.
set /p variable= - This command
is used when you want your player to insert a variable (a varying answer). This
could be anywhere from their name to the name of a weapon or even the answer to
one of the choices you have given them. Often times this variable will be
referenced later, and therefore must be given a name. The name can be whatever
you want it to be (but remember that you may be typing it in a lot when making
your game). I think it would be easiest if I gave you some pictures showing you
how to create variables.
set /p
name=
See how I
use the "echo" command to ask my player what his name is? I then go
ahead and type:
set /p
name=
This is
where my player will type his name. "name" In this line is my
variable. In a sense what we are doing is setting (set) a variable (name)
to equal (=) whatever the user types.
We can
reference this variable later by placing the name of the variable within two of
the '%' symbols. For example:
echo
Hello %name%, my name is Tom.
This will
feed whatever the player typed in, back to him in the form of text.
Here is
what happens when a player types in his name, then you feed that name back to
him with the echo command.
if - this
command is used when we create if/then statements. We can use it in conjunction
with "set /p" in order to create choices for are players.
- Ask the player a question with the "echo" command. Make sure to clearly state their options.
- Give them the ability to enter an answer with the "set /p" command.
- Create "if" statements that allow the players' choices to have consequences, and that allow the story to continue.
"if"
statements are used with "equ" and "neq" which mean
"equals" and "doesn't equal", respectively.
This is
how your statements should look:
:start
echo YES
or NO?
set /p variable=
if
%variable% equ YES goto situation1
if
%variable% equ NO goto situation2
if
%variable neq YES goto start
All of
this code means that if the player types in "YES" he will be sent to
"situation1"; if he types in "NO" he will be sent to
"situation2"; if he types in neither "YES" or
"NO" he will be sent back to the start of the question.
Remember
when I said earlier that the order you write your code matters? If you typed in
the "neq YES" code before the "equ NO" code, your player
would never be able to make it to "situation 2".
Here is a
good example of how you can use "set /p", "goto", and
"if" all together.
Saving
The last
thing I need to show you how to do is to save your file. Once you are all done,
click the "file" button at the top of the screen, then click on
"Save As." This will display a window where you can then create a
name for you game and save it wherever you would like. However, you need to
make sure that you save it as a Batch (.bat) file and not as a regular text
file (.txt).
To do
this, after you type in the name of your game add .bat behind it. You
then need to go to "Save as type" and select "All Files."
Then
you're done! All you have to do is hit the "save" button.
Remember,
you can edit your game at any time by right clicking on the batch file and
selecting "edit."
Select
"All Files", then click the save button to finish.
Do full trick very carefully and its sure done.
No comments:
Post a Comment