Public paste
Turing Trivia
By: Oxygenn | Date: Oct 21 2006 20:54 | Format: None | Expires: never | Size: 3.94 KB | Hits: 785

  1. unit
  2. class Trivia
  3.     export Start
  4.    
  5.     var FileStream:int
  6.     var HighScores:flexible array 1..1 of string
  7.    
  8.     procedure Init()    
  9.         open : FileStream, "HighScoresTable.hs", get    
  10.     end Init    
  11.    
  12.     procedure DisplayHighScores()        
  13.  
  14.        put "nnn", "":14, "-----------------------------------------------"
  15.        put "":14, "|", "":14, "High Score Table", "":15, "|"
  16.        put "":14, "-----------------------------------------------n", "":14, "|", "":45, "|n",  "":14, "|", "":45, "|"
  17.        
  18.        loop
  19.             get : FileStream, HighScores(upper(HighScores))
  20.             exit when eof(FileStream)
  21.             new HighScores, upper(HighScores) + 1          
  22.        end loop
  23.        
  24.        for i : 1 .. upper(HighScores)
  25.            for j : 1 .. length(HighScores(i))
  26.                if HighScores(i)(j) = "-" then
  27.                   put "":14, "|", "":8, HighScores(i)(1 .. (j - 1)):15, "":5, HighScores(i)(j), "":5, HighScores(i)((j + 1) .. length(HighScores(i))):2, "":9, "|"
  28.                   HighScores(i) := HighScores(i)(1 .. (j - 1)) + " " + HighScores(i)(j) + " " + HighScores(i)((j + 1) .. length(HighScores(i)))
  29.                   exit
  30.                end if
  31.            end for
  32.        end for
  33.        
  34.        put "":14, "|", "":45, "|n", "":14, "|", "":45, "|"
  35.        put "":14, "-----------------------------------------------"
  36.        
  37.     end DisplayHighScores
  38.  
  39.     function GetCategory(category:int):string    
  40.         if category > 5 or category < 1 then
  41.             result "Invalid Category Number: "" + intstr(category) + """
  42.         end if
  43.    
  44.         case category of
  45.             label 1: result "General"
  46.             label 2: result "Equipment"
  47.             label 3: result "Techniques"
  48.             label 4: result "Types of DJs"
  49.             label 5: result "DJ Related Events"
  50.         end case      
  51.     end GetCategory
  52.    
  53.     function GetDifficulty(difficulty:int):string    
  54.         if difficulty > 5 or difficulty < 1 then
  55.             result "Invalid Difficulty Number: "" + intstr(difficulty) + """
  56.         end if
  57.    
  58.         case difficulty of
  59.             label 1: result "Easy"
  60.             label 2: result "Normal"
  61.             label 3: result "Hard"
  62.         end case      
  63.     end GetDifficulty
  64.    
  65.     % GenerateQuestion() prints out a question/answer and then generates 'dummy' answers based on
  66.     % difficulty and category.    
  67.    
  68.     procedure GenerateQuestion(category:int, difficulty:int, question:string, answer:string, fillblank:boolean)
  69.        
  70.        cls
  71.        
  72.        if fillblank = true then
  73.            put "This is a fill in the blank question.n"    
  74.        else
  75.            put "This is NOT a fill in the blank question.n"
  76.        end if
  77.        
  78.        put "Category: ", GetCategory(category)
  79.        put "Difficulty: ", GetDifficulty(difficulty)
  80.        put "n----------------------------------------------"
  81.        put "nn", question, "n"
  82.        
  83.        case Rand.Int(1, 4) of
  84.             label 1:
  85.                 put "nA) ", answer, "nB) ", /* dummyanswer, */ "nC) ", /* dummyanswer, */ "nD) " /* dummyanswer, */
  86.             label 2:
  87.                 put "nA) ", /* dummyanswer, */ "nB) ", answer, "nC) ", /* dummyanswer, */ "nD) " /* dummyanswer, */
  88.             label 3:
  89.                 put "nA) ", /* dummyanswer, */ "nB) ", /* dummyanswer, */ "nC) ", answer,  "nD) " /* dummyanswer, */
  90.             label 4:
  91.                 put "nA) ", /* dummyanswer, */  "nB) ", /* dummyanswer, */ "nC) ", /* dummyanswer, */ "nD) ", answer
  92.        end case
  93.        
  94.     % GetCategory(Rand.Int(1, 5))
  95.    
  96.     end GenerateQuestion
  97.    
  98.     procedure Start()    
  99.         Init()
  100.         DisplayHighScores()
  101.         delay(2000)
  102.         GenerateQuestion(2, 1, "Which of the following is considered advanced equipment?", "Effects processors (delay, reverb, octave, equalizer, chorus, etc). ", false)
  103.     end Start
  104. end Trivia