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

Username:   Password: 
 RegisterRegister   
 "Clicking" array help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
XXX111




PostPosted: Sun Dec 19, 2010 2:27 pm   Post subject: "Clicking" array help

I'm making a trivia-based multiple choice game where the user always has 4 options to choose from. Since I want to include the same graphics each time, I made separate pictures for each question. Right now, this is how I detect if the user clicks the right "button" (just a specific area of the screen where the picture of the button appears).

Turing:


if x>=10 and x<=30 and y>=100 and y<=200 and mousebutton=1

then delay(200)
put "Correct"
delay(1000)
cls



I could do this for every single question, but is there a better way to do this by using arrays? Also, since the multiple choice answers change, the coordinates of the "button" would have to change as well. Any help is greatly appreciated.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Dec 19, 2010 2:37 pm   Post subject: RE:"Clicking" array help

Keep a 2D array of buttons, where the first dimension is the button number and the second dimension contains the coordinates. Alternatively you could create a type button record and have an array of those. Then it's a matter of looping over the array and checking collision against each button.
TokenHerbz




PostPosted: Sun Dec 19, 2010 5:39 pm   Post subject: RE:"Clicking" array help

using an array of type button would be the ideal way to do this,

with that array you could go threw each question, checking the buttons for the answer to display the results/take next action.
XXX111




PostPosted: Sun Dec 19, 2010 8:43 pm   Post subject: Re: "Clicking" array help

thanks for your answers, but wouldn't creating a record type require turing to read the actual text? My question is displayed as a picture, so Turing won't be able to tell what the question is.
Insectoid




PostPosted: Sun Dec 19, 2010 8:49 pm   Post subject: RE:"Clicking" array help

A record is just a handy way of storing lots of related variables. A 'button' record would be something like this:

Turing:

type button :
    record
        x1, x2, y1, y2 : int
        image : string
    end record

var button1 : button
button1.x1 = 5
button1.y1 = 20
button1.x2 = 55
button2.y2 = 40
button2.image = "button.bmp"


Yeah, the formatting lines up oddly, but that's okay. This allows you to quickly initialize the buttons via a loop (assuming your buttons are drawn in a mathematically-representable way). It's a bit cleaner than a 2D array and is easier to read.
XXX111




PostPosted: Mon Dec 20, 2010 8:49 am   Post subject: Re: "Clicking" array help

Ok I think I get it now! Thanks for all of your help!
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  [ 6 Posts ]
Jump to:   


Style:  
Search: