Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing Multiple Windows updating problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
richard_xia




PostPosted: Fri Sep 28, 2012 2:05 pm   Post subject: Turing Multiple Windows updating problem

What is it you are trying to achieve?
Create a quiz in school.


What is the problem you are having?
When you answer the first question wrong it asks if you want to try again. If you select yes then it dosen't clear the yes no buttons. Also when you type
the letters do not appear. Also. If you answer the first question right then the second question does not appear unless you click somewhere else on the
screen or another window then click back the original window.

Describe what you have tried to solve this problem
When I click one window then go back to another then the problem is solved.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


var a, b, c, d : int
var winID1 : int
var winID2 : int
var winID3 : int
var font : int
var mousex, mousey, mouseb : int
var x, y : int
var answer : string := "Alan"
var line : string
font := Font.New ("sans serif:20:bold")
winID1 := Window.Open ("graphics:400;400;buttonbar;position:top;right")
winID2 := Window.Open ("graphics:800;800;buttonbar;position:top;left")
winID3 := Window.Open ("graphics:400;200;nobuttonbar;position:bottom;right")
var picture : int
var points : int := 0
var picID, picID2, picID3, picID4 : int
var count : int := 0
var t: int := 0
Window.Select (winID1)
Font.Draw ("Write your answers here", 10, 350, font, green)
delay (100)
drawfillbox (0, 0, maxx, maxy, black)
Window.Select (winID2)
Font.Draw ("I will display your questions here", 000, 335, font, blue)
delay (100)
drawfillbox (0, 0, maxx, maxy, 9)
Window.Select (winID3)
Font.Draw ("I will count your points", 00, 115, font, purple)
delay (100)
drawfillbox (0, 0, maxx, maxy, green)

Window.Select (winID2)
drawfillbox (0, 0, maxx, maxy, 9)

setscreen ("offscreenonly")
fcn button (x, y : int, text : string) : boolean
    var clicked := false
    if (x - 200 < mousex & mousex < x + 800 & y + 300 < mousey & mousey < y + 800) then
        Draw.FillBox (x - 200, y + 300, x + 800, y + 800, green)
        if (mouseb = 1) then
            clicked := true
        end if
    end if
    Font.Draw ("Click to Start", x + 200, y + 600, font, 7)
    Draw.Box (x - 200, y + 300, x + 800, y + 800, 7)
    result clicked
end button
fcn yes (x, y : int, text : string) : boolean
    var clicked :boolean := false
    drawfillbox (50, 80, 170, 180, black)
    setscreen ("offscreenonly")
    Font.Draw ("Yes", 80, 130, font, white)
    View.Update
    if ((50 < mousex) and (mousex < 170) and (80 < mousey) and (mousey < 180)) then
        %if ((mousex > 50) & (mousey > 80)) then
        if (mouseb = 1) then
            clicked := true
        end if
    end if
    result clicked
end yes
fcn no (x, y : int, text : string) : boolean
    var clicked := false
    drawfillbox (230, 80, 350, 180, black)
    setscreen ("offscreenonly")
    Font.Draw ("No", 260, 130, font, white)
    View.Update
    if ((230 < mousex) and (mousex < 350) and (80 < mousey) and (mousey < 180)) then
        if (mouseb = 1) then
            clicked := true
        end if
    end if
    result clicked
end no
fcn google (x, y : int, text : string) : boolean
    var clicked := false
    if ((110 < mousex) and (mousex < 330) and (0 + t < mousey) and (mousey < 100 + t)) then
        if (mouseb = 1) then
            clicked := true
        end if
    end if
    result clicked
end google
proc correct
    cls
    Font.Draw ("Correct!", 150, 200, font, green)
    Window.Select (winID3)
    Font.Draw ("Score:" + intstr (points), 125, 100, font, yellow)
end correct


%%%%%start
loop
    mousewhere (mousex, mousey, mouseb)

    if (button (100, 100, "asgasg")) then
        cls
        exit
    end if

    View.Update
end loop
loop
    count := count + 1
    Window.Select (winID2)
    Font.Draw ("QUESTION 1", 300, 600, font, red)
    Font.Draw ("There are 365 days in a year", 250, 550, font, black)
    Font.Draw ("There are 86 400 seconds in a day", 250, 500, font, black)
    Font.Draw ("There are 1000 milliseconds in a second", 250, 450, font, black)
    Font.Draw ("What was the first name", 250, 400, font, black)
    Font.Draw ("of the inventor of turing?", 250, 350, font, black)
    Font.Draw ("(click the black window)", 250, 300, font, green)

    Window.Select (winID1)
    get line
    if line = "alan" then
        points := points + 1
        correct
        exit
    end if
    if count > 4 then
        put "You have tried too many times, moving on!"
        delay (700)
        exit
    end if
    if line = "Alan" then
        points := points + 1
        correct
        exit
    else
        Window.Select (winID1)
        Font.Draw ("INCORRECT", 150, 200, font, red)
        delay (700)
        cls
        Draw.Box (0, 0, maxx, maxy, black)
        Font.Draw ("Would you like to play again?", 0, 200, font, red)
        delay (700)
        loop
            mousewhere (mousex, mousey, mouseb)
            if (yes (0, 0, " ")) then
               
                cls

                Window.Select (winID2)
                exit

            end if
            if (no (0, 0, " ")) then
                quit
            end if
        end loop
    end if
    cls
end loop
Window.Select (winID2)
drawfillbox (0, 0, maxx, maxy, yellow)
Font.Draw ("QUESTION 2", 300, 600, font, red)
Font.Draw ("Which of the following", 250, 550, font, black)
Font.Draw ("is the correct color scheme", 250, 500, font, black)
Font.Draw ("of the google logo?", 250, 450, font, black)
Window.Select (winID1)
cls
picID := Pic.FileNew ("Google.Jpg")
Pic.Draw (picID, 110, 0, picCopy)
Pic.Free (picID)
picID2 := Pic.FileNew ("Googlefake.Jpg")
Pic.Draw (picID2, 110, 100, picCopy)
Pic.Free (picID2)
picID3 := Pic.FileNew ("googlefake2.Jpg")
Pic.Draw (picID3, 110, 200, picCopy)
Pic.Free (picID3)
picID4 := Pic.FileNew ("Googlefake3.Jpg")
Pic.Draw (picID4, 110, 300, picCopy)
Pic.Free (picID4)
loop
    mousewhere (mousex, mousey, mouseb)
if (google (0,0, " ")) then
quit
end if
    mousewhere (mousex, mousey, mouseb)
if (google (0,0, " ")) then
quit
end if
end loop




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Sep 28, 2012 6:22 pm   Post subject: Re: Turing Multiple Windows updating problem

maybe
richard_xia @ Fri Sep 28, 2012 2:05 pm wrote:

setscreen ("offscreenonly")
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
QuantumPhysics




PostPosted: Sat Sep 29, 2012 9:15 am   Post subject: RE:Turing Multiple Windows updating problem

Also this is a long piece of code perhaps next time just put it in a file attachment?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: