/* $VER: TA-Trivia v1.5 (10/11/95) for TransAmiga by John Kratz
   Fidonet 1:260/322.0, Internet jkratz@erc.cat.syr.edu
*/

options results
signal on syntax
signal on error
signal on ioerr

/*************************************************************************/
                        /* Sysop Configurable variables                  */
oneright=0		/* Number of minutes to add for 1 right answers  */
tworight=0		/* Number of minutes to add for 2 right answers  */
threeright=0		/* Number of minutes to add for 3 right answers  */
fourright=5		/* Number of minutes to add for 4 right answers  */
fiveright=5		/* Number of minutes to add for 5 right answers  */
sixright=5		/* Number of minutes to add for 6 right answers  */
sevenright=5		/* Number of minutes to add for 7 right answers  */
eightright=10		/* Number of minutes to add for 8 right answers  */
nineright=20		/* Number of minutes to add for 9 right answers  */
tenright=30		/* Number of minutes to add for 10 right answers */

                        /* Make sure this matches the # question files   */
total=304		/* total number of question files available      */
/*************************************************************************/
ui=userinfo;tr=transmit;gc=getchar;ss=sendstring;si=systeminfo
ui a;handle=result
ui a;name=result
ui o;access=result
si m;timeallowed=(result-3)
bbsidentify 'name';bbsname=result
ver="[31mTA [32mTrivia [34mv1.5"
bbsidentify 'sysop';sysopname=result
userinfo x ; ansi=result
CSI	= '1b'x||'['
CRLF	= '0d'x||'0a'x
FF	= '0c'x
if ansi='ON' then do
	OFF = CSI'0m' ; BO = CSI'1m' ; UL = CSI'4m' ; IT = CSI'3m'
	RED = CSI'31m' ; GREEN = CSI'32m' ; YELLOW = CSI'33m' ; BLUE = CSI'34m'
	PURPLE = CSI'35m' ; CYAN = CSI'36m' ; WHITE = CSI'37m'
   	YELLOWBACK = CSI'43m'
end
else do
	OFF = '' ; BO = '' ; UL = '' ; IT = ''
	RED = '' ; GREEN = '' ; YELLOW = '' ; BLUE = ''
	PURPLE = '' ; CYAN = '' ; WHITE = ''
   	YELLOWBACK = ''
end	
Highscores="BBS:Extras/TATRIVIA/Highscores.txt"
c=0
setnodelocation "Playing the Trivia game!"
sysoplog name 'played the Trivia Game!'
path='BBS:Extras/TaTrivia/'
upath=path"users/"
qpath=path"Questions/"
quest="Questions"
high= path"HighScores.txt"
index=1
check=1
used.1=0

START:
INST:
	cls
	ss GREEN
        tr GREEN BO'TransAmiga Trivia Quizzer by' CYAN 'John Kratz.'GREEN
        tr ''
        tr 'The program will choose randomly among the' YELLOW total RED'trivia quizzes.'
        tr ''
        tr CYAN'Use the numbers [33m1[32m,[33m2[32m,[33m3 [32mand [33m4 [32mto select your answer.'
        tr ''
        tr 'You may quit at any time by typing [33mQ[32m.'
        tr ''        
        address command 'WAIT 2 secs'

TITLESCREEN:
	cls
        tr ''
	tr '[0m[5C[1;31m________________________ ______________________'
	tr '    /[23C//[21C/'
	tr '   /[23C//[21C/'
	tr '  /__________[5C________//________[5C________/'
	tr '[12C/    /[17C/    /'
	tr '[11C/    /[17C/    /'
	tr '[10C/    /[17C/    /'
	tr '[9C[32m/    / ___[13C/    / ________   ___  __    ___   ___   ___'
	tr '[8C/    / /   |[11C/    / /   _   /  /  / |  |  /  /  /  /  /   |'
	tr '[7C/    / /    |[10C/    / /   //  /  /  /  |  | /  /  /  /  /    |'
	tr '[6C/    / /  |  |[9C/    / /   //  /  /  /   |  |/  /  /  /  /  |  |'
	tr '[5C/    / /  /|  |[8C/    / /[6C_/  /  /    |  |  /  /  /  /  /|  |'
	tr '    [34m/    / /  __   |[7C/    / /   /  |   /  /[5C|    /  /  /  /  __   |'
	tr '   /    / /  /  |  |[6C/    / /   /|  |  /  /[6C|   /  /  /  /  /  |  |'
	tr '  /____/ /__/   |__|[5C/____/ /___/ |__| /__/[7C|__/  /__/  /__/   |__|'
	tr '[41C[36mBy [33mJohn Kratz of Amiga Time BBS!'
	tr '[41C[36mInternet[31m: [36mjkratz@erc.cat.syr.edu'
	tr '[42C[32mFidonet[31m: [32m1:260/322.0'
	tr '[42C[37mVersion[31m: [37m'ver'[0m'
	bufferflush
        tr ''
MAIN:
tr '[18C[1;36m[[33mV[36m][31miew High Scores   [36m[[33mP[36m][32mlay TA Trivia' 
if access > 200 then tr '[18C[36m[[33mR[36m][34meset HighScores'
tr '[18C[36m[[33mQ[36m][33muit               [36m[[33mI[36m][37mnstructions - How to Play'
ss '[5C[1;32mYour Choice?[1;36m ' ; gc ;ans=upper(ans) ; call GCCHECK
if ans='P' then do
     cls 
     call STARTOVER
     end
if ans='V' then do
     cls
     call SHOWHIGHS
     continue
     call TITLESCREEN
     end
if ans='I' then do
     cls 
     sendfile 'BBS:Extras/TATrivia/TATRIVIA.DOC'
     continue
     end
if access >= 200 & ans='R' then do
     cls 
     call RESET
     end 
if ans='T' then do
     cls
     systeminfo m ; timeleft = Result
     systeminfo q ; daily = Result
     userinfo u   ; onlinetime = Result
     tr BO YELLOW'Your total online time per day is 'CYAN daily YELLOW' minutes!'
     tr ' You have been online 'RED onlinetime YELLOW' minutes so far today!'
     tr ' You have 'GREEN timeleft YELLOW' minutes left for today!'OFF
     continue
     call TITLESCREEN
     end
if ans='Q' then signal QUIT
if ans='RESULT' then cls ; signal TITLESCREEN
STARTOVER:
	num=1;count=1
	score=0
	timenumb=0
	listnum=random(1,total,66)
GETQUESTIONS:
	listnum=random(1,total,time('s'))
	do i=1 to check
	if used.i=listnum then signal GETQUESTIONS
	end
	used.index=listnum
	check=index
	index=index+1
	if index=276 then do
	   do i=1 to check
	   used.i=0
	end
	index=1
	check=1
	end
	if open('file',qpath||quest||listnum,'R') then do
		do until EOF('file')
			quest.num=readln('file')
				do i=1 to 4
				quest.num.i=readln('file')
				end
			num=num+1
		end
			call close('file')
	end
	else do
		tr "There has been a problem loading the question file"
		exit 10
	end
SHOW:
	cls
	if count=num-1 then signal SHUTDOWN
	tr ""
	tr ""
	ss ''YELLOWBACK BLUE bbsname"'s "RED"Trivia Quiz  "OFF 
	tr " "
	tr " "
	if access >= 200 then do
		ss ''BO GREEN"Question File number:"RED listnum
	end
	tr GREEN" Question number:"RED count
	tr " "
		tr CYAN quest.count YELLOW
		tr ""
			do i=1 to 4
				parse var quest.count.i isans 2 answer
				if isans="!" then theans=i
				if isans~="-" then transmit '' i'' answer
			end
	bufferflush
	tr ''
	tr RED" You have "CYAN score RED" right."
        tr '' 
	ss OFF PURPLE"Your Choice -> " CYAN ; gc
ASKIT:
	guess=upper(result)
	tr CYAN guess
	if guess="1" then signal CONTINUE
	if guess="2" then signal CONTINUE
	if guess="3" & if isans~="-" then signal CONTINUE
	if guess="4" & if isans~="-" then signal CONTINUE
	if guess="Q" then signal SHUTDOWN
        if guess="RESULT" then SIGNAL MAIN2
	if guess="q" then do
		guess=upper(guess)
              	signal SHUTDOWN
	end
        if guess~= "1" or guess ~= "2" or guess ~= "3" or guess ~= "4" or guess ~= "RESULT" then SIGNAL MAIN2
	if guess="###PANIC" then signal exit 10
	if guess="###panic" then signal exit 10
	signal ASKIT
MAIN2:
Query PURPLE"[1FYour Choice ->[36m "
signal ASKIT
CONTINUE:
	if guess=theans then do
		score=score+1
		tr CYAN"  Correct."
	end
	else tr RED"  Sorry, that's wrong."
        address command 'WAIT 1 secs'
	count=count+1
	if count > num then do
		if guess=theans then do
			tr CYAN"Correct."
		end
		else tr RED"Sorry, that's wrong."
                address command 'WAIT 1 secs'
		signal SHUTDOWN
	end
	signal SHOW
GCCHECK:
ans=result
if ans ='###PANIC' then do ; bufferflush ; exit 10 ; end
return
SHOWHIGHS:
call READHIGH
call SHOWFIVE
return
CHECKHI:
call READHIGH
x=0 ; gp=c ; if gp <= 0 then signal L288
L276:
x=x+1 ; if x > 10 then signal L288
z=10 ; if zp.x.2=0 then signal L283
if gp < zp.x.2 then signal L276
L283:
z1=z-1
do y=1 to 3
zp.z.y=zp.z1.y
end y
z=z-1 ; if z~ < x then signal L283
zp.x.1=handle ; zp.x.2=gp ;zp.x.3=date() 
tr "[39mCongratulations! You Are One Of The Top 10 Players!"
call open(f1,HIGHSCORES,'w')
do x=1 to 10
   do y=1 to 3
   call writeln(f1,zp.x.y)
   end y
end x ; call close(f1)
if gs=0 then cls ; call SHOWHIGHS
bufferflush ; Address command 'Wait 2 secs'
return
L288:
timenumb=0
c=0
tr CYAN center("Sorry, You did not make it into the "GREEN"Top Ten"CYAN". Try Again Next Time.[0m",100)
if count > 9 & score = 0 then signal ZERO
SIGNAL ANOTHER
return
READHIGH:
if ~exists(HighScores) then do
   call open(f1,HighScores,'w')
   do x=1 to 10
   call writeln(f1,"Nobody Yet!") ; call writeln(f1,"0") ; call writeln(f1,"None Yet!!!")
   end x ; call close(f1)
end
call open(f1,HighScores,'r')
do x=1 to 10
   do y=1 to 3
      zp.x.y=readln(f1)
   end y
end x ; call close(f1)
return
ZERO:
   newtime = ontime - 15
   settime newtime
   tr '[0m[2J[15C[1;33;44mÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'
   tr '[15Cº       ÜÜÜÜÜÜÜ  ÜÜÜÜÜÜÜ  ÜÜÜÜÜÜÜ   ÜÜÜÜÜÜÜÜ         º'
   tr '[15Cº            /   Û        Û      Ý  Û      Û         º'
   tr '[15Cº           /    Û        Û      Ý  Û      Û         º'
   tr '[15Cº          /     ÛÜÜÜÜ    ÛÜÜÜÜÜÜÝ  Û      Û         º'
   tr '[15Cº         /      Û        Û   \     Û      Û         º'
   tr '[15Cº        /       Û        Û    \    Û      Û         º'
   tr '[15Cº       /        Û        Û     \   Û      Û         º'
   tr '[15Cº       ßßßßßßß  ßßßßßßß  ß      \  ßßßßßßßß         º'
   tr '[15Cº                                                    º'
   tr '[15Cº  ÜÜÜÜÜÜÜ   ÜÜÜÜÜ   ÜÜÜÜÜÜÜÜ   Ü      Ü   ÜÜÜÜÜÜÜÜ  º'
   tr '[15Cº  Û      Ý    Û     Û          Û      Û      Û      º'
   tr '[15Cº  Û      Ý    Û     Û          Û      Û      Û      º'
   tr '[15Cº  ÛÜÜÜÜÜÜÝ    Û     Û          ÛÜÜÜÜÜÜÛ      Û      º'
   tr '[15Cº  Û   \       Û     Û  ÜÜÜÜÜÜ  Û      Û      Û      º'
   tr '[15Cº  Û    \      Û     Û      Û   Û      Û      Û      º'
   tr '[15Cº  Û     \     Û     Û      Û   Û      Û      Û      º'
   tr '[15Cº  ß      \  ßßßßß   ßßßßßßßß   ß      ß      ß      º'
   tr '[15CÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¹'
   tr '[15CºYou [31mlose 15 minutes [33mfor not getting atleast 1 right!º'
   tr '[15CÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼[0m'
   address command 'WAIT 2 secs'
return
SHOWFIVE:
tr '[0m [1;36mÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'
tr ' º               TA [34mTrivia [32mHigh Scores![36m               º'
tr ' º        [33mCurrent Top [36mTen [31mTA [34mTrivia [33mChamps:[11C[36mº'
tr ' º[52Cº'
tr ' º     NAME[10C[32mTOTAL SCORE![8C[34mDATE[9C[36mº'
tr ' º[52Cº'
do x=1 to 10
tr ' º'right('<'||x||'>',4)' [31m '||left(zp.x.1'                   ',20)'[32m'right(zp.x.2,2)' [10C[34m'right(zp.x.3,11)'[36m  º'
end x
tr ' º[52Cº'
tr ' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼[0m'
return
SHUTDOWN:
give=0
si m ; ontime=result
si q ; maxtime=result
if count > 9 & score < 3 then SIGNAL L288
if count > 9 & score > 3 then do
	if score=4 then do
		newtime = ontime + fourright
		settime newtime
		timenumb=fourright
                c=4
	end
	if score=5 then do
                newtime = ontime + fiveright
		settime newtime
		timenumb=fiveright
                c=5
	end
	if score=6 then do
		newtime = ontime + sixright
		settime newtime
		timenumb=sixright
                c=6
	end
	if score=7 then do
		newtime = ontime + sevenright
		settime newtime
		timenumb=sevenright
                c=7
	end
	if score=8 then do
		newtime = ontime + eightright
		settime newtime
		timenumb=eightright
                c=8
	end
	if score=9 then do
		newtime = ontime + nineright
		settime newtime
		timenumb=nineright
                c=9
	end
	if score=10 then do
		newtime = ontime + tenright
		settime newtime
		timenumb=tenright
                c=10
	end
end
if count > 9 & score > 3 then tr GREEN"You have been given "timenumb" extra minutes online for your "score" correct answers."
if timenumb > 0 then do
     si m ; ontime=result
     si q ; maxtime=result
     setnewtime = ontime + timenumb
     tr 'Your OLD time remaining is:' ontime 'minutes'
     tr 'Your New time remaining is:' setnewtime 'minutes'
     if setnewtime > maxtime then do 
        setnewtime = maxtime 
        tr 'Sorry, you can only have 'maxtime 'minutes/day total'
        end
     continue
     settime setnewtime
end
     give=1
     SIGNAL CHECKHI
     if give=0 then ss 	
ANOTHER:
	ss YELLOW"Would you like to try another quiz? "CYAN"("GREEN"y"CYAN"/"RED"N"CYAN") "GREEN;gc;again=upper(result)
	if again="Y" then do tr "Yes";	signal STARTOVER ; end
	tr ""
	tr GREEN"Returning you to "bbsname"."
        cls
	exit 10
RESET:
address command 'delete BBS:Extras/TATRIVIA/Highscores.txt'
Call TITLESCREEN
end
QUIT:
cls
Tr 'Thank you' name 'for playing TA Trivia!'
bufferflush ; exit 10
IOERR:
 tr ''
 tr '*BOOM* Got an IO error. Please notify 'sysop'!'
 SYSOPLOG '*BOOM* Got an IO error in TA Trivia.'
 SYSOPLOG '---> Line: ' SIGL
 BUFFERFLUSH
 EXIT 10
ERROR:
 tr ''
 tr '*BOOM* Got an error. Please notify 'sysop'!'
 tr 'line: ' SIGL '  Severity: ' RC
 SYSOPLOG '*BOOM* Got an error in TA Trivia..'
 SYSOPLOG '---> Line: ' SIGL '  Severity: ' RC
 BUFFERFLUSH
 EXIT 10
SYNTAX:
 tr 'Error in 'ver'.  Line:  'SIGL
 tr 'Error:  'RCALL errortext(RC)
 tr 'Please notify 'sysopname'!'
 tr 'Returning to 'BBSname'...'
 SYSOPLOG 'Error in 'ver'.  Line:  'SIGL
 SYSOPLOG 'Error:  'RCALL errortext(RC)
 BUFFERFLUSH
 EXIT 10