Playing the game is quite fun! I always wanted to make games. But one day I finally made a game. Making graphical games requires a lot of efforts but here I am talking about Question-Answer games. Similar to KBC. After reading this post thoroughly you can make your own game. It will take a maximum of 15 minutes to understand everything.
Note: I am telling you about making a simple Question-Answer game not any advanced game like PUBG! So keep reading if you want to learn.
You will learn:
How we are going to make the Game?
We are going to make this with the help of command prompt. It is the CLI (Command-line interface). We are going to write some codes in notepad and then run them. It much easier than you think, but you have to use your brain. In starting it may be a little bit confusing but after some time everything will be normal. Let’s start.
You must read the description of the commands used in this code in the last of the post.
Code for the Game
echo It is KBC game.
echo you have to answer my question
echo ArE YoU ReAdY??
echo Question 1:
echo What is the full name of Nathuram Godse ?
echo a)Nathuram mahadev Godse b)Nathuram vinayak Godse
echo c)Nathuram raman Godse c)Nathuram prakash Godse
set /p ans=
if %ans% equ b goto q2
if %ans% neq b goto start
echo Question 2
echo Maruti Suzuki is a company of which country??
echo a)Korea b)China
echo c)Sudan c)America
set /p q=
if %q% equ a goto q3
if %q% neq a goto start
echo Question 3
echo How many incarnations did Lord Vishnu Had ?
echo a)12 b)10
echo c)16 d)24
set /p a=
if %a% equ d goto q4
if %a% neq d goto start
echo OH!!!! Your answer seems to be wrong!!!
echo Would you like to try Again y/n ?
set /p yn=
if %yn% equ y goto q1
if %yn% equ n goto exit
echo Thank you for playing our game.
- Copy this code and paste it in notepad.
- Now save the file as “my_first_game.bat” in your desired folder.
- Also, choose the file type as “All files”.
- And hit enter to save.
That’s all. You have created your game. Now go to the folder where you saved it. It must have a wheel sign. Double click to open it.
It merely took 1 minute but understanding the code will take around 15 minutes. I have created a 3 questions game. After understanding the code, you can make any number of questions you want. So, read more for it.
Description of Commands used in-game making
Here is the code beaking of the game. Let’s start with our first line.
It just removes the directories representation in each line. I know you didn’t understand. So you must try it yourself.
Go to the code and change it to “@echo on”, save the file and run the program again. You will see the difference clearly.
It sets the size of the screen to 1000. Here it is around full-screen size. You can change it to 200, 500, 700 or any other number to change the screen size.
“color” is used to change the screen and text color. the combination of number used after color, “0e” in this case, defines the color. “0”, means the number, tell the background color and “e”, means alphabet, defines the text color. Here is the color code for numbers and alphabets:
all the lines starting with this word “echo” will simply display the words exactly, after itself, on the screen. In this case, you will see “Welcome” written on your screen.
it will pause the screen until you press any key. It means your code will not be compiled ahead until you press any key.
You may try it. Remove the pause from the code and run the program again. What happened? Did you see all the line you wrote? NO, cause the screen displayed and removed it all of sudden within a fraction of time. You have to use the “pause” command to pause the screen.
cls stands for “Clear screen”. You have displayed some lines on the screen you want them to be cleared. How? just using cls. It will clear your screen.
Now, try it. Remove the “cls” from code and run it again. You will see all the lines accumulating on screen as you move further. So to keep the screen clear we use “cls”.
“:”, it is used to create a code which can be called by anytime. Let me make it clear. “q1” is just a name given by me. You can use any name. But you must use “:” before that. Everything below this code will be executed when I just type “goto q1”.
set /p ans
it is used to create any variable. Here we have created “ans”. Read further to know how it works?
if %ans% equ b goto q2
Let’s break it down this code line;
- %ans% – Previously declared variable.
- equ – it means Equals to, but you have to use “equ” only. Similarly there is “neq” in the next line, which means not equal to.
- b – It is user input. It means if the users typed “b” then do what is programmed.
- goto q2 – You know how we created “:q1”. similarly, for question 2 we have “:q2”.
So, in one line, it means that ‘if the user typed “b” then goto the “q2” part of the code.’
It is the last type of command used in the code (you can always ask us in the comment section if something is left). Exit defines itself, it just exits the window. Simple.
This was not actually a place to create games. This Coding is known as “Batch Files”. These are the Command prompt (cmd) commands. You can do something cooler than these games on cmd like shutting down your PC with an automatic timer and many more.
Read our guide on “Cmd and Batch Files” hacks and just show off!! in front of your friends.
Give us a moment!
It will hardly take 1 minute to complete our survey. It only consists of 6 short questions. Please complete it so that we can make some great experiences. Click here to proceed.
Please help us to Grow. We try to provide best and reliable data for our users. We cannot do it without your help. You can help us even by telling some suggestions, correction and adding something useful to our Post.