Computer Science Canada

Trivia Game

Author:  Amarylis [ Thu Mar 08, 2012 10:56 pm ]
Post subject:  Trivia Game

Enjoy whenever you're bored, or use it if you can (though I fail to see how anyone can re-use this.... meh)

Spoiler:

Turing:


/*
 Written by A Prado
 September 20th, 2011
 ICS 3U D1P5


 Trivia game disclaimer:
 This program is a trivia game developed and written entirely by a student of the Grade 11 Programming class of *edited out school name*. All rights to this program are owned by the creator and developer. The original concept and idea
 of the program is credited to the curriculum of the course.
 Copyright Prado 2011
 */


import GUI

var rulesButton, playButton, cancelButton : int := 0
var a : int := 11
var nextButton : array 1 .. a of int
var answer : array 1 .. 4 of int
var nameTextField : int := 0
var pictures : int
var font : int
var count : int := 0
var name : string
var rightAnswer : boolean := false
var correct : int := 0


for i : 1 .. a
    nextButton (i) := 0
end for

for i : 1 .. 4
    answer (i) := 0
end for

View.Set ("graphics:400;300, nobuttonbar, offscreenonly")

procedure WrongAnswer
    Music.Sound (1000, 300)
    Music.SoundOff
end WrongAnswer


procedure NewScreen
    cls
    GUI.SetBackgroundColour (grey)
end NewScreen

procedure StartUp
    NewScreen
    font := Font.New ("Times New Roman:16:bold")
    assert font > 0
    Font.Draw ("Welcome to the \"Rent\" Trivia Game!", 30, maxy - 40, font, black)
    Font.Draw ("______________________________", 30, maxy - 40, font, black)
    Font.Free (font)
    View.Update
end StartUp

procedure Rules
    NewScreen
    StartUp
    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Rules:", 30, 220, font, black)
    Font.Draw ("_____", 30, 220, font, black)
    Font.Free (font)
    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("In this game, you will be given the choice between 4", 30, 190, font, black)
    Font.Draw ("different answers to choose from. Click on the radio", 30, 170, font, black)
    Font.Draw ("buttons to choose your answer", 30, 150, font, black)
    Font.Free (font)
    View.Update
    GUI.Refresh
end Rules

procedure nameText (text : string)
    GUI.SetSelection (nameTextField, 0, 0)
    GUI.SetActive (nameTextField)
    View.Update
end nameText

procedure Answer
    View.Update
    if answer (correct) = GUI.GetEventWidgetID then
        rightAnswer := true
    else
        rightAnswer := false
    end if
end Answer

procedure addScore
    if rightAnswer = true then
        count := count + 1
        Music.PlayFile ("tada.wav")
        rightAnswer := false
    else
        WrongAnswer
    end if
    delay (500)
end addScore

procedure clearRadio
    for i : 1 .. 4
        GUI.Dispose (answer (i))
        answer (i) := 0
    end for
end clearRadio

procedure clearButton (n : int)
    GUI.Dispose (nextButton (n))
    for i : 1 .. a
        nextButton (i) := 0
    end for
end clearButton

procedure FinishScreen
    addScore
    NewScreen

    clearRadio
    clearButton (11)
    GUI.Dispose (cancelButton)

    View.Set ("graphics:400;100,nobuttonbar")
    font := Font.New ("Times New Roman:12:bold")
    NewScreen
    Font.Draw ("Okay, that's the end of the game!", 30, maxy - 30, font, black)
    View.Update
    delay (3000)
    NewScreen
    if count = 10 then
        Font.Draw ("Wow! You got a perfect score! You must be gifted!", 30, maxy - 30, font, black)
        View.Update
        delay (1500)
        Font.Draw ("Or a cheater...", 30, maxy - 50, font, black)
        View.Update
        delay (3000)
        Font.Draw ("...Or a gifted cheater", 30, maxy - 70, font, black)
        View.Update
        delay (4000)

        NewScreen
        colourback (grey)
        locatexy (30, maxy - 45)
        put "Your prize is $1000.00!"
        View.Update
    elsif count >= 7 then
        Font.Draw ("You did pretty well, but I recommend watching", 30, maxy - 30, font, black)
        Font.Draw ("the movie again...", 30, maxy - 50, font, black)
        View.Update
        delay (4000)

        NewScreen
        colourback (grey)
        locatexy (30, maxy - 45)
        put "Your prize is $700.00!"
        View.Update
    elsif count >= 4 then
        Font.Draw ("It's best to actually watch the movie before", 30, maxy - 30, font, black)
        Font.Draw ("you play this...", 30, maxy - 50, font, black)
        View.Update
        delay (4000)

        NewScreen
        colourback (grey)
        locatexy (30, maxy - 45)
        put "Your prize was $400.00!"
        View.Update
    else
        locatexy (30, maxy - 45)
        colourback (grey)
        put "You're just having a bad day, arent you?"
        locatexy (30, maxy - 55)
        put "I'm sorry... You don't get a prize"
        View.Update
    end if
    delay (5000)

    NewScreen
    locatexy (30, maxy - 40)
    put name, ", your final score was ", count
    View.Update

    GUI.Quit
end FinishScreen

procedure Question10
    addScore
    NewScreen

    clearRadio
    clearButton (10)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #10:", 15, maxy - 40, font, 110)
    Font.Draw ("___________", 15, maxy - 40, font, 110)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    Font.Draw ("What is the name of the song that Roger writes for Mimi?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 2
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) \"One Song Glory\"", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) \"Your Eyes\"", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) \"No Day But Today\"", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) \"I Should Tell You\"", answer (3), Answer, 0, 'd')

    nextButton (11) := GUI.CreateButtonFull (15, 50, 30, "Next", FinishScreen, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question10

procedure Question9
    addScore
    NewScreen

    clearRadio
    clearButton (9)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #9:", 15, maxy - 40, font, 63)
    Font.Draw ("__________", 15, maxy - 40, font, 63)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("What song is the line \"I dont own emotion, I rent\" in?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 1
    rightAnswer := true
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) \"What You Own\"", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) \"Rent\"", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) \"I'll Cover You\"", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) \"Take Me For Who I am\"", answer (3), Answer, 0, 'd')

    nextButton (10) := GUI.CreateButtonFull (15, 50, 30, "Next", Question10, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question9

procedure Question8
    addScore
    NewScreen

    clearRadio
    clearButton (8)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #8:", 15, maxy - 40, font, 11)
    Font.Draw ("__________", 15, maxy - 40, font, 11)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("Which character passes away after the song \"Without You\"?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 3
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) Roger Davis", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) Mark Cohen", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) Angel Dumott Schunard", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) Mimi Marquez", answer (3), Answer, 0, 'd')

    nextButton (9) := GUI.CreateButtonFull (15, 50, 30, "Next", Question9, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question8

procedure Question7
    addScore
    NewScreen

    clearRadio
    clearButton (7)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #7:", 15, maxy - 40, font, 43)
    Font.Draw ("__________", 15, maxy - 40, font, 43)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    Font.Draw ("Which two characters are seen as Anarchists?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 1
    rightAnswer := true
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) Maureen Johnston and Tom Collins", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) Mark Cohen and Roger Davis", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) Mimi Marquez and Angel Dumott Schunard", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) Benjamin Coffin III and Joanne Jefferson", answer (3), Answer, 0, 'd')

    nextButton (8) := GUI.CreateButtonFull (15, 50, 30, "Next", Question8, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question7

procedure Question6
    addScore
    NewScreen

    clearRadio
    clearButton (6)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #6:", 15, maxy - 40, font, yellow)
    Font.Draw ("__________", 15, maxy - 40, font, yellow)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("Which of the following was a line of the song \"La Vie Boh?me\"?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 3
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) \"Three hamburgers, two fries, wine and beer\"", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) \"I'm sorry, we dont serve homeless people\"", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) \"And not to mention, of course, hating dear old mom and dad\"", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) \"To going against the brain, going insane\"", answer (3), Answer, 0, 'd')

    nextButton (7) := GUI.CreateButtonFull (15, 50, 30, "Next", Question7, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question6

procedure Question5
    addScore
    NewScreen

    clearRadio
    clearButton (5)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #5:", 15, maxy - 40, font, green)
    Font.Draw ("__________", 15, maxy - 40, font, green)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("During Maureen's protest, what animal was Benny compared to?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 4
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) A cat", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) A cow", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) A snake", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) A dog", answer (3), Answer, 0, 'd')

    nextButton (6) := GUI.CreateButtonFull (15, 50, 30, "Next", Question6, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question5

procedure Question4
    addScore
    NewScreen

    clearRadio
    clearButton (4)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #4:", 15, maxy - 40, font, red)
    Font.Draw ("__________", 15, maxy - 40, font, red)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("What is the name of Roger's late girlfriend?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 2
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) Maureen Johnson", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) April Ericsson", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) Alexi Darling", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) Mimi Marquez", answer (3), Answer, 0, 'd')

    nextButton (5) := GUI.CreateButtonFull (15, 50, 30, "Next", Question5, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question4

procedure Question3
    addScore
    NewScreen

    clearRadio
    clearButton (3)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #3:", 15, maxy - 40, font, magenta)
    Font.Draw ("__________", 15, maxy - 40, font, magenta)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("How did Angel get the $1000.00 on Christmas Eve?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 4
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) She earned it on the street", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) Her parents gave it to her", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) By performing in the Broadway show \"Wicked\"", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) By killing a rich woman's neighbour's dog for her", answer (3), Answer, 0, 'd')

    nextButton (4) := GUI.CreateButtonFull (15, 50, 30, "Next", Question4, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question3

procedure Question2
    addScore
    NewScreen

    clearRadio
    clearButton (2)

    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #2:", 15, maxy - 40, font, brown)
    Font.Draw ("__________", 15, maxy - 40, font, brown)
    Font.Free (font)

    font := Font.New ("Times New Roman:12")
    assert font > 0
    Font.Draw ("In the song \"You'll See\", what does Benny ask of Mark and Roger in return of free rent?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 1
    rightAnswer := true
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) Stop Maureen's protest", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) To evict the homeless living in the building", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) For Mark to write a song about him", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) For Roger to make a movie about him", answer (3), Answer, 0, 'd')

    nextButton (3) := GUI.CreateButtonFull (15, 50, 30, "Next", Question3, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question2

procedure Question1
    View.Set ("graphics:600;400,nobuttonbar,offscreenonly")
    name := GUI.GetText (nameTextField)
    NewScreen
    clearButton (1)
    GUI.Dispose (nameTextField)
    nameTextField := 0
    font := Font.New ("Times New Roman:14:bold")
    assert font > 0
    Font.Draw ("Question #1:", 15, maxy - 40, font, blue)
    Font.Draw ("__________", 15, maxy - 40, font, blue)
    Font.Free (font)
    font := Font.New ("Times New Roman:12")
    Font.Draw ("What is the first song in the movie Rent (2005)?", 15, maxy - 80, font, black)
    Font.Free (font)

    correct := 2
    answer (1) := GUI.CreateRadioButtonFull (15, maxy - 100, "a) \"La Vie Boh?me\"", 0, Answer, 0, 'a')
    answer (2) := GUI.CreateRadioButtonFull (-1, -1, "b) \"Seasons of Love\"", answer (1), Answer, 0, 'b')
    answer (3) := GUI.CreateRadioButtonFull (-1, -1, "c) \"Rent\"", answer (2), Answer, 0, 'c')
    answer (4) := GUI.CreateRadioButtonFull (-1, -1, "d) \"I'll Cover You\"", answer (3), Answer, 0, 'd')

    nextButton (2) := GUI.CreateButtonFull (15, 50, 30, "Next", Question2, 10, 'n', false)
    View.Update
    GUI.Refresh
end Question1

procedure QuitGame
    View.Set ("graphics:400;120, nobuttonbar,offscreenonly")
    NewScreen
    GUI.Refresh
    font := Font.New ("Times New Roman:12:bold")
    assert font > 0
    if nameTextField not= 0 then
        GUI.Dispose (nameTextField)
    end if
    for i : 1 .. a
        if nextButton (i) not= 0 then
            GUI.Hide (nextButton (i))
            GUI.Dispose (nextButton (i))
        end if
    end for
    if playButton not= 0 then
        GUI.Dispose (playButton)
    end if
    if rulesButton not= 0 then
        GUI.Dispose (rulesButton)
    end if
    if cancelButton not= 0 then
        GUI.Dispose (cancelButton)
    end if
    for i : 1 .. 4
        if answer (i) not= 0 then
            GUI.Hide (answer (i))
            GUI.Dispose (answer (i))
        end if
    end for
    Font.Draw ("You surrendered your score to the Ninja Gods", 30, maxy - 30, font, black)
    Font.Draw ("of Scorekeeping when you pressed the 'Quit' button.", 30, maxy - 50, font, black)
    Font.Draw ("Come back when you are serious about playing this", 30, maxy - 70, font, black)
    Font.Draw ("Trivia Game.", 30, maxy - 90, font, black)
    Font.Free (font)
    View.Update
    GUI.Refresh
    GUI.Quit
end QuitGame

procedure NextScreen
    NewScreen
    clearButton (1)
    name := GUI.GetText (nameTextField)
    GUI.Dispose (nameTextField)
    nameTextField := 0
end NextScreen


procedure StartGame
    View.Set("nooffscreenonly")
    NewScreen
    GUI.Dispose (rulesButton)
    GUI.Dispose (playButton)
    rulesButton := 0
    playButton := 0
    GUI.Refresh
    font := Font.New ("Times New Roman:16:bold")
    Font.Draw ("Start-up:", 15, maxy - 40, font, black)
    Font.Draw ("_______", 15, maxy - 40, font, black)
    Font.Free (font)
    font := Font.New ("Times New Roman:12")
    Font.Draw ("Before the game begins, what is your name?", 15, maxy - 70, font, black)
    Font.Free (font)
    nameTextField := GUI.CreateTextField (15, maxy - 120, 200, " ", nameText)
    nextButton (1) := GUI.CreateButtonFull (15, 55, 30, "Next", Question1, 20, '^X', false)
    View.Update
end StartGame

% Beginning of program


StartUp


rulesButton := GUI.CreateButtonFull (15, 50, 30, "Rules", Rules, 10, '^R', false)
playButton := GUI.CreateButtonFull (15, 80, 30, "Play", StartGame, 10, '^P', false)
cancelButton := GUI.CreateButtonFull (15, 20, 40, "Quit", QuitGame, 10, '^Q', false)
View.Update

loop
    exit when GUI.ProcessEvent
    View.Update
end loop




Also uploaded

Author:  Raknarg [ Fri Mar 09, 2012 9:34 pm ]
Post subject:  RE:Trivia Game

Something you might find useful:

Turing:

var questions : array 1 .. 10 of proc x

proc Question1

end Question1

questions (1) := Question1


note that is does not need to be called x. You can even include parameters there; just make sure that the procedure you're using and the arrayed procedure have the same parameters.

Author:  Amarylis [ Fri Mar 09, 2012 9:37 pm ]
Post subject:  RE:Trivia Game

I already handed that in a LOOONG time ago, so it doesn't really matter at this point, but thanks for the tip, I'll be sure to use it next time Smile


: