How to Make a Simple Batch Game (trivia!)
by Mistersalt in Circuits > Computers
19505 Views, 9 Favorites, 0 Comments
How to Make a Simple Batch Game (trivia!)
HI
Today i'm gonna show you how to make a trivia game with Batch. Since batch is kind of limited, some awesome features that you may be thinking of may not come true. That's just how it goes. Hopefully my steps, to you, are simple and easy to understand.
Making the Main Page
Ok, like all games, they have a main page(menu). Use all your text pictures-making skills and make it nice and beautiful. Ok, for those who have not much skill in this batch script, input this code:
Firstly, start with a @echo off (duh)
@echo off
Then, add a title
@echo off
title The Trivia Game
Now, add the main title(that will be shown on the screen) and a label
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
Your script should now look like this^
Now, add the selection part. This is slightly trickier
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto PLAY
if %input%==b goto instructions
You will use the selection code you used here for all the questions.
Ok, thats basically it for this step.
Making a Score System
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto PLAY
if %input%==b goto instructions
This should be your script so far.
Ok, lets get into some explanation.
1. What is set /p?
Ok, in simpler terms, is kind of like setting up a question.
2. If? What is 'if'?
'If' checks a condition. So 'if' the input is a, it will transport you to the label 'a'. Getting it so far?
3. What's with the percentage marks?
If a word is surrounded with these percentage marks, then that means it is a variable.
Now, this step I am going to explain how to make a score system. A bit tricky to the novice scripter.
Firstly, we shall use a 'set a/'
set a/
Then we shall type in a bit more to the 'set /a', as shown below. The score we will set is how many questions done. This will be abbreiviated to 'qdone'
set a/ qdone=0
Pretty simple. Next, I will show you how to add points to the 'qdone'. We shall use two labels. The first label is the question.
:Q1
echo ----------------------------------------
echo What is a boat?
echo ----------------------------------------
echo [a-A water vehichle] [b-A land vehicle]
echo [c-A truck] [d-An animal]
set p/ input=ANSWER?
if %input%==a goto score1
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error
:score 1
set a/ qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q2
Ok, thats basically it. Let's get into explanation.
1.How does the set a/ qdone=%qdone%+1 work?
Well, its like resetting the variable, except adding 1 more point.
2. What is the bold for, on the goto error?
Well, i'd just like to point it out.If the command that was entered is invalid, it will go to the error label (that you will make)
Finalizing
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto Q1
if %input%==b goto instructions
goto error
Ok, back to the main menu. We will now add the extra labels that are required (error, instructions, wrong)
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto PLAY
if %input%==b goto instructions
goto error
:error
echo Dingbat! Thats an invalid command.
pause
goto Main
:instructions
echo Type instructions here
pause
goto Main
:wrong
echo Sorry, but...
echo YOU LOSE!!
pause
goto Main
:Q1
echo ----------------------------------------
echo What is a boat?
echo ----------------------------------------
echo [a-A water vehichle] [b-A land vehicle]
echo [c-A truck] [d-An animal]
set p/ input=ANSWER?
if %input%==a goto score1
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error
:score 1
set a/ qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q2
:Q2
(Put question here)
Okay, thats basically it. Now, this step is UBER IMPORTANT
save it as a BAT file, so say your game is called trivia save it as trivia.bat
That's basically it! Add more questions, and a winning screen, and your done!
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto Q1
if %input%==b goto instructions
goto error
Ok, back to the main menu. We will now add the extra labels that are required (error, instructions, wrong)
@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto PLAY
if %input%==b goto instructions
goto error
:error
echo Dingbat! Thats an invalid command.
pause
goto Main
:instructions
echo Type instructions here
pause
goto Main
:wrong
echo Sorry, but...
echo YOU LOSE!!
pause
goto Main
:Q1
echo ----------------------------------------
echo What is a boat?
echo ----------------------------------------
echo [a-A water vehichle] [b-A land vehicle]
echo [c-A truck] [d-An animal]
set p/ input=ANSWER?
if %input%==a goto score1
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error
:score 1
set a/ qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q2
:Q2
(Put question here)
Okay, thats basically it. Now, this step is UBER IMPORTANT
save it as a BAT file, so say your game is called trivia save it as trivia.bat
That's basically it! Add more questions, and a winning screen, and your done!