Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

A simple trivia game I made


  • Please log in to reply
5 replies to this topic

#1 JohnBobSmith

JohnBobSmith

  • Members
  • 13 posts
  • OFFLINE
  •  
  • Local time:07:39 PM

Posted 23 May 2013 - 03:54 PM

Hello! I got my laptop problems fixed. Turns out it was actually overheating. However, since I am also interested in programming, here is a simple game I made! Copy and paste this code into notepad and save as trivia.bat.

 

@echo off
color 0a
title JohnBobSmith's TRIVIA
echo.
echo - - - - - - - - - - - - - - -
echo.
echo Welcome to JohnBobSmith's TRIVIA!!
echo.
echo - - - - - - - - - - - - - - -
echo.
echo Copyright JohnBobSmith. You cannot use any part of this code for any purpose!
echo.
echo Hit enter then after the commmand feature pops up press A to play or B to see
echo instructions! After making your choice, press enter again. 
pause
set /p input=COMMAND?
if %input%==a goto Q1
if %input%==b goto instructions
:instructions
echo Press the number of your choice. Then, press enter. You will be told if you got it right or wrong. Then press any button to continue to the next question! Press any button to start!
pause
goto Q1

:Q1
cls
echo Where do the wookies live?
echo 1 Couruscant
echo 2 The death star
echo 3 Kashyyyk
set /p starwars=choice1~3
if %starwars%==1 goto incorrect
if %starwars%==2 goto Incorrect
if %starwars%==3 goto correct
:Correct
cls
echo You got it right!!
pause
goto Q2
:Incorrect
cls
echo Sorry you got it wrong!!
pause
goto Q2

:Q2
cls
echo Who is the captain of the millenium falcon?
echo 1 darth vader
echo 2 han solo
echo 3 luke skywalker
set /p captain=choice1~3
if %captain%==1 goto Incorrect1
if %captain%==2 goto Correct1
if %captain%==3 goto Incorrect1
:Correct1
cls
echo you got it right!!
pause
goto Q3
:Incorrect1
cls
echo sorry you got it wrong!!
pause
goto q3

:Q3
cls
echo What typ of spaceship luke's starfighter?
echo 1 Z-95
echo 2 X-wing
echo 3 luke skywalker
set /p luke=choice1~3
if %luke%==1 goto Incorrect2
if %luke%==2 goto Correct2
if %luke%==3 goto Incorrect2
:Correct2
cls
echo you got it right!!
pause
goto Q4
:Incorrect2
cls
echo sorry you got it wrong!!
pause
goto Q4

:Q4
cls
echo How many arms does general grevious have?
echo 1 Four
echo 2 Nine
echo 3 None
set /p arms=choice1~3
if %arms%==1 goto correct3
if %arms%==2 goto incorrect3
if %arms%==3 goto incorrect3
:Correct3
cls
echo you got it right!!
pause
goto q5
:Incorrect3
cls
echo sorry you got it wrong!!
pause
goto q5

:Q5
cls
echo Where is the rebel base located in episode 5? 
echo 1 Naboo
echo 2 Narnia
echo 3 Hoth
set /p base=choice1~3
if %base%==1 goto incorrect4
if %base%==2 goto Incorrect4
if %base%==3 goto correct4
:Correct4
cls
echo You got it right!!
pause
goto Q6
:Incorrect4
cls
echo Sorry you got it wrong!!
pause
goto Q6

:Q6
cls
echo What are the names of Darth Vaders children?
echo 1 han solo and chewbaca
echo 2 darth maul and qui-gon jin
echo 3 Luke Skywalker and Princess Leia
set /p children=choice1~3
if %children%==1 goto incorrect5
if %children%==2 goto incorrect5
if %children%==3 goto correct5
:Correct5
cls
echo you got it right!!
pause
goto q7
:Incorrect5
cls
echo sorry you got it wrong!!
pause
goto q7

:Q7
cls
echo Who is count dooku
echo 1 One of the Chancellors former aprentices
echo 2 Obi wan's aprentice
echo 3 A secret police agent
set /p dooku=choice1~3
if %dooku%==1 goto correct6
if %dooku%==2 goto incorrect6
if %dooku%==3 goto Incorrect6
:Correct6
cls
echo you got it right!!
pause
goto Q8
:Incorrect6
cls
echo sorry you got it wrong!!
pause
goto Q8

:Q8
cls
echo What is the death star?
echo 1 a moon
echo 2 a space station the size of a planet with a gaint lazer capable of destroying planets!!!
echo 3 the emporer's flagship
set /p dstar=choice1~3
if %dstar%==1 goto Incorrect7
if %dstar%==2 goto Correct7
if %dstar%==3 goto Incorrect7
:Correct7
cls
echo you got it right!!
pause
goto Q9
:Incorrect7
cls
echo sorry you got it wrong!!
pause
goto Q9

:Q9
cls
echo Who were the clones from episode 2 cloned from
echo 1 Boba Fett
echo 2 han solo
echo 3 Obi wan kenobi
set /p boba=choice1~3
if %boba%==1 goto correct8
if %boba%==2 goto incorrect8
if %boba%==3 goto Incorrect8
:Correct8
cls
echo you got it right!!
pause
goto Q10
:Incorrect8
cls
echo sorry you got it wrong!!
pause
goto Q10

:Q10
cls
echo Where do the gungans live?
echo 1 Naboo
echo 2 Dagobah
echo 3 Mustafar
set /p worlds=choice1~3
if %worlds%==1 goto correct10
if %worlds%==2 goto incorrect10
if %worlds%==3 goto incorrect10
:Correct10
cls
echo you got it right!!
pause
goto win
:Incorrect10
cls
echo sorry you got it wrong!!
pause
goto win
:win
cls
echo Conratulations! You have made it to the end!
pause

 

SInce I am a starwars fan I made it about starwars. Enjoy! tell me if you find any bugs. Also tell me what you think of some basic batch coding such as this!


Edited by JohnBobSmith, 24 May 2013 - 10:29 AM.


BC AdBot (Login to Remove)

 


#2 hispaladin

hispaladin

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:08:39 PM

Posted 23 May 2013 - 04:58 PM

Ummm..... I must say you have one question wrong, (at least from the movies) the clones were cloned from Jango Fett, Boba Fett was a clone that Jango raised as his son.  :luke:   I am a bit of a starwars fan myself (but not quite a hard core fan)

 

Oh and I am quite impressed with the code, well done.


Edited by hispaladin, 23 May 2013 - 04:59 PM.


#3 JohnBobSmith

JohnBobSmith
  • Topic Starter

  • Members
  • 13 posts
  • OFFLINE
  •  
  • Local time:07:39 PM

Posted 23 May 2013 - 06:51 PM

Ah yes that is correct. My bad, lol. Im glad you like the code. Once I figured out the code it became fairly easy to make.  



#4 AceInfinity

AceInfinity

  • Members
  • 30 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Canada
  • Local time:06:39 PM

Posted 24 May 2013 - 11:20 PM

This is not bad at all, but still not the greatest:
 
 
if %input%==a goto Q1
if %input%==b goto instructions
 
You may want to include the /i switch in case the user inputs a capital A or B here.
 
goto Q1 is actually redundant here:
goto Q1

:Q1
 
Same thing with lines like this:
if %starwars%==3 goto correct
:Correct
 
This could be shortened massively though with a few batch functions. I would be careful with your casing though, that will get you into trouble under the right circumstances.

For your check:
if %starwars%==1 goto incorrect
if %starwars%==2 goto Incorrect
if %starwars%==3 goto correct
You should also only need to check if the input is not the right answer, and not all of the incorrect "answers."

Edited by AceInfinity, 24 May 2013 - 11:23 PM.

mvp.png
Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


#5 AceInfinity

AceInfinity

  • Members
  • 30 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Canada
  • Local time:06:39 PM

Posted 25 May 2013 - 12:17 AM

Take a look at this for example:
:: Developed by Ace - (c) 2013
@echo off & setlocal enabledelayedexpansion
call :Initialize
:: Usage = call :DisplayQuestion {Correct Ans} {Dummy Ans} {Dummy Ans} {Dummy Ans}
call :DisplayQuestion "What special decibel number is equivalent to twice the perceived loudness?" "+3 decibels" "+2 decibels" "+5 decibels" "+1 decibels"
call :DisplayQuestion "What special decibel number is equivalent to twice the perceived loudness?" "+3 decibels" "+2 decibels" "+5 decibels" "+1 decibels"
call :DisplayQuestion "What special decibel number is equivalent to twice the perceived loudness?" "+3 decibels" "+2 decibels" "+5 decibels" "+1 decibels"
call :DisplayQuestion "What special decibel number is equivalent to twice the perceived loudness?" "+3 decibels" "+2 decibels" "+5 decibels" "+1 decibels"
call :DisplayQuestion "What special decibel number is equivalent to twice the perceived loudness?" "+3 decibels" "+2 decibels" "+5 decibels" "+1 decibels"
call :DisplayResults
echo.
pause & goto :eof

:Initialize
set TotalNumQuestions=0
set TotalCorrect=0
goto :eof

:DisplayQuestion
set Q=%1
echo !Q!
call :DisplayAnswers %2 %3 %4 %5
set /p userInput=Your answer: 
if /i %userInput%==%correctAns% (
	set /a TotalCorrect+=1
	echo Correct!
) else (
	echo Incorrect...
)
set /a TotalNumQuestions+=1
echo.
goto :eof

:DisplayAnswers
set index=0
set chars=ABCD
set Ans1=%1
set Ans2=%2
set Ans3=%3
set Ans4=%4
:NotAllSelected
set /a r=!random! %% 4 + 1
set _Ans=!Ans%r%!
if defined _Ans (
	if %r%==1 set correctAns=!chars:~%index%,1!
	echo. !chars:~%index%,1!. %_Ans:"=%
	set /a index+=1
)
set Ans!r!=
set Answers=!Ans1!!Ans2!!Ans3!!Ans4!
if defined Answers goto :NotAllSelected
goto :eof

:DisplayResults
echo Results: You got %TotalCorrect% out of a total of %TotalNumQuestions% questions correct^^!
if %TotalCorrect%==%TotalNumQuestions% echo Congratulations on answering all of the questions correctly^^!^^!^^! & color A
goto :eof
What this does is it randomizes the quesitons, but you are re-using the same code for each question and set of answers passed to the function. It also dynamically tally's your score out of the total number of questions and randomizes the order of the answers given.

~Ace

mvp.png
Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


#6 JohnBobSmith

JohnBobSmith
  • Topic Starter

  • Members
  • 13 posts
  • OFFLINE
  •  
  • Local time:07:39 PM

Posted 27 May 2013 - 11:23 PM

I dont quite understand that code but I will be sure to learn how that all works! Thanks a bunch, i was wondering how to make a score system too! 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users