Hello everyone on steemit!
I've made kind of a Pokémon game written in batch and i would like to share it with you! In this post i'm going to break down the code as well as leaving the entire code for the ones who would like to try the game out.
I know this is not a good game at all, but i'm still pretty new to programming and this is the best i've made so far. I'm also pretty young.
To those who don't know, batch is a programming language used in Windows CMD or Command Prompt. This is what i have used and am using to make games. That means this wont work in OSX (Mac/macbooks), although i'm not sure about Linux.
So let's get started!
The first lines of code is basically me setting up how the window is going to look, and after those settings take effect, it will send the player to the menu:
I think it is very obvious for everyone what most of these lines do, the tricky ones would be "@echo off" and "setlocal EnableDelayedExpansion". "@echo off" is basically the command that every batch project is starting with. It will allow us to print text on the screen later on. If i'm being honest, i have no idea what "setlocal EnableDelayedExpansion" actually does, but everyone seems to have it in their games so i did too, hehe.
After setting everything up, i start to make the menu. This is a good time to tell you that in batch, since you are making everything in a command prompt window, you will not be able to make any graphics. Well, you can, but that is very difficult and it won't turn out great. So here's the menu code:
This is where things start to get a little more complicated. I will do my best to explain everything.
":start" is the tag for that section of code. If you think about batch games as a book, that is basically one page. In batch, you program everything in order of what will happen, so that is basically a page, and when we say "goto (page)" it will take us to that "tag".
The lines where i put "::" infront of a word, are comments. Those comments show me where i create some variables that we are going to use in the game. The variables i put inside of these are the hp for the pokemons who will fight eachother, and the limit for how many times an attack can be used. After that, it is back to some pretty basic code. I welcome the player and give them the choice to either play single player against an ai or to play with a friend.
"echo" is what "@echo off" allows us to do, wich is to print some text on the screen. "echo." gives us a blank line.
"set /p" gives the player the ability to type something on screen, in this case, either "1" or "2" depending on how many players there are. The "if" commands are what they say, if the player types a 1 then it will go to 1 player mode and if the player puts in a 2 then the game will go to 2 player mode.
The "cls" command means Clear Screen and is used to wipe old text away for a new page. Let's move on to the next section of code!
This tag, or page, is where the game takes us if there is only one player. On this page i only have some dialogue between the competition leader and the commentator of the competition, and after that i clear the screen for the next page and send the player to the next page. The next 4 pages are basically the same code with different text printed on the screen, so i'm going to skip those in this post.
This next picture is the "playing field" page of the game. Basically, this is where the battle itself will take place.
I start out by clearing the screen from the last page. Then once again, we have the "if" command, wich i explained what it does earlier. In the same line, we have a new command, called "leq". This means lesser than, and is used to tell the game that when one of the pokemons HP is lesser than 0, it will with the help of another command on another tag, decide which pokémon is the winner.
After that, i have built a player field out of text, with the help of the "echo" and "echo." commands. It is nothing spectacular, basically some boxes containing information (pokemons, attacks, hp). But it is the best i could do.
I then give the player the option to choose wich attack to use. To do that i display the attacks in the biggest box, and then i put the "/p" command to give the player the ability to choose. Then once again, i use the if command to tell the computer what attack the player has chosen. This works the same way as the main menu did. I will now show you how the attacks work:
On this page, as on many others, i start off by clearing the screen. One thing i should mention is when a word or sentence is inside of two "%" it is a variable. So an example could be %variable%. We created this variable in the start of this post.
In the second line, we basically tell the computer that if we have used thunderbolt 2 times already, we can't use it again and nothing will happen. But if we haven't used it 2 times already, it will still work.
In the 3rd and 4th line, we run into a new command. That command is called "set /a". It looks like "set /p" and is almost the same thing i think, but we use "set /a" to change the value of a variable. In the 3rd line we use it to change the value of squirtles hp, wich is the pokémon we are fighting. We do that by changing squirtles hp by a random number within the range of 30 to 15. This is the system we use to make critical hits and weak hits, as you would see in a normal pokémon game. Well, atleast that´s how it is supposed to work, but it always goes within 50 to 15, wich is really weird. But don't forget i'm new to programming, i am just here to show you my work.
Anyways, in the 4th line we use "set /a" again, but this time to change the value of the thunderboltlimit, wich is 2 by standard, but this command changes it by -1 every time. So if i use it one time, the value will change from 2 to 1, and when i have used the attack 2 times it will be 0, wich the second line reacts to and blocks the attack out so we can't use it anymore. After that we just print out how many more times we can use the attack again, so when we use it for the first time it will say that we can use it once more, and after two uses it will say 0 more times.
And at the end we send the player to "sqattack" wich is the tag or page where squirtle will attack us. There are 2 more attack pages, but they are basically the same thing but i change how much damage they deal, so i will skip those in this post.
This page is basically the same thing, but in the game we won't see it. It will instead just change the value of our own HP without showing a new page. The mechanics here are the same as in the other attack windows, but i thought i would just include the enemy attack too so you could see how that is made.
Finally, these are the pages that will pop up if you win or lose. If your hp goes below 0 you will be taken to the defeat page, if your opponents hp goes below 0 you will be taken to the win page. In these pages we basically just print out a text, pause the game and when the player presses any button it will close the game.
We will now get started on the two player mode. It is similar, but with a sh*tload more variables. I will tell you about the bigger differences, but leave the pages that are very similar out. Remember, the whole code will be at the bottom + the instructions on how to "activate" the game or whatever you are supposed to call it.
A big difference is in the beginning of the two player mode.
On this screen we create two variables, wich hold the hp of the players. Then we create two more, wich hold names of the players, and let the players set the value (we let the player choose a name basically.)
On this page, we create a sh*tload of variables, wich hold the attacks of every pokémon in the game. The pokémons in the 2 player mode are Squirtle, Mankey, Piplup, Pikachu and Charmander. We then let player1 choose a pokémon. Based on what pokémon player1 chooses, the attacks will be set on the playing board.
On the next page, it is the exact same thing but with player2 instead, so let's just go ahead and skip that.
This is the playingboard for player 1. It is basically the same as on singleplayer mode, but everything inside the boxes are variables instead of just text. It displays the exact same way ingame, though.
The next page is the same thing but with player 2´s variables instead. So again, we are going to skip that.
Actually, that's pretty much it. The attack pages are the same as in singleplayer mode, so i'm not going to show that again, simply because i'm lazy :) Thank you to everyone who has read this far! It means alot.
As i promised, here comes the entire code:
https://docs.google.com/document/d/1hU9UgbJMzOiQ_a5LfxwH5NwglUu2j6i6sBUxdlGN0Es/edit?usp=sharing
(The boxes on the playfield might get messed up but the game will still work)
And to play the game, you need to open up notepad. My computer is set to swedish but i think you should be able to follow these steps.
Copy the entire code from the drive document and paste it into notepad. Then press "save as" and name it pokemon.bat, then press "Text Documents" under the File name, and select "all files". Then press save and you're done! Make sure you save it on your desktop.
Thank you all for reading this, and have a wonderful day.
//AlfonsL
✅ @alfonsl, I gave you an upvote on your post! Please give me a follow and I will give you a follow in return and possible future votes!
Thank you in advance!