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

Username:   Password: 
 RegisterRegister   
 Storing images in an array?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mikey90




PostPosted: Thu Jan 25, 2007 2:56 pm   Post subject: Storing images in an array?

Hello...I need some help. I'm creating a guessing game which display images and someone has to guess what the images is from...I will provide multiply choice answers. Could someone tell me how to store images in an array?
Sponsor
Sponsor
Sponsor
sponsor
DemonZ




PostPosted: Thu Jan 25, 2007 3:09 pm   Post subject: Re: Storing images in an array?

Sure its not a problem at all, all you gotta do is create a variable as an array like so:
code:

var pictures : array 1 .. 10 of int

After that there are a couple of options here, you can use a for loop to store all of the same images, or you can manually insert the pictures one by one in the different array slots like so:
code:

pictures (1) := Pic.FileNew ("picture.bmp", 0, 0, picCopy)
pictures (2) := Pic.FileNew ("picture2.bmp", 0, 0, picCopy)
...........
% and so forth


But there is another way to do this, name all of your pictures under one name for example pics, then give each of them a number when you name them ex "pics 1, pics 2, pics 3, ...., and so forth" then you can code your program to sotre each individual picture like this:
code:

var pictures : array 1 .. 10 of int

for i : 1 .. 10
pictures (i) := Pic.FileNew ("pics " + instr (i) + ".bmp"
end for


This way, you are storing all the images that you want in the array using a for loop, this takes less time and is easier to work with

If you have any questions just ask ill help explain to you.
DemonZ




PostPosted: Thu Jan 25, 2007 3:14 pm   Post subject: Re: Storing images in an array?

Here is a short program I made for you that will solve your problems of storing images
code:

var pictures : array 1 .. 10 of int

for i : 1 .. 10
pictures (i) := Pic.FileNew ("pics " + instr (i) + ".bmp")
end for
mikey90




PostPosted: Thu Jan 25, 2007 3:23 pm   Post subject: RE:Storing images in an array?

Alright .... just one more question. If I am giving the user a multiple choice question and I only want to display one image until the user gets it right what should I do? To give the user 3 options.
mikey90




PostPosted: Thu Jan 25, 2007 3:23 pm   Post subject: RE:Storing images in an array?

And thanks for helping me out
DemonZ




PostPosted: Thu Jan 25, 2007 3:43 pm   Post subject: Re: Storing images in an array?

No problem, as for the displaying image one by one, If you have controls in your game, heres what you do: First you display the question and the choices, plus the picture, then after youll have either "get answer" that will wait until the user has typed in his letter for which answer he like to choose, you might wanna have all of your questions stored in an array and the multiple choice answers in an array as well, after that, youll have an if statement that will check if the answer is right, if it is then youll display the next picture, if it isnt, its up to you what you wanna do, have game over or repeat the question. Here a little code that might help you solve your problem:
code:

for i: 1 .. 10
Pic.Draw (pictures (i), 0, 0, picCopy) % displaying picture
question (i) % displaying question
% displaying multiple choices
choice1 (i)
choice2 (i)
choice3 (i)
choice4 (i)
% Displaying question, picture, and answers
get UserAnswer
if UserAnswer = choice1 (i) then
put "GOOD JOB"
end if



Hope this helps
mikey90




PostPosted: Thu Jan 25, 2007 3:56 pm   Post subject: RE:Storing images in an array?

Could you outline how I can combine storing the pictures in the array and then displaying them with multiple choice answers?
DemonZ




PostPosted: Thu Jan 25, 2007 4:08 pm   Post subject: Re: Storing images in an array?

here some code:
code:

var pictures : array 1 .. 10 of int
var question : array 1 .. 10 of string
var choice1 : array 1 .. 10 of int
var choice2 : array 1 .. 10 of int
var choice3 : array 1 .. 10 of int
var choice4 : array 1 .. 10 of int
var answer : int

for i : 1 .. 10
pictures (i):= Pic.FileNew ("pics " + instr (i) + ".bmp"
end for

for i : 1 .. 10
Pic.Draw (pictures (i), 0, 0, picCopy)
put question (i)
put choice1 (i), choice2 (i), choice3 (i), choice4 (i)
get answer
% Then you do your if statement to check if answer is right
end for
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Thu Jan 25, 2007 4:17 pm   Post subject: Re: Storing images in an array?

DemonZ, you basically just did his project for him...

While we're at it:

Turing:

var pictures : array 1 .. 10 of int
var question : array 1 .. 10 of string
var choice1 : array 1 .. 10 of int
var choice2 : array 1 .. 10 of int
var choice3 : array 1 .. 10 of int
var choice4 : array 1 .. 10 of int


Would be much better off as a record:

Turing:

var questions : array 1 .. 10 of
    record
        picture : int
        question : string
        answer : string
        choice : array 1 .. 4 of string
    end record


Check out the records and types tutorial in the Turing Walkthrough to figure out how that works Wink
mikey90




PostPosted: Thu Jan 25, 2007 4:25 pm   Post subject: RE:Storing images in an array?

Im gonna try and get it to work...thanks for helping me.
mikey90




PostPosted: Thu Jan 25, 2007 4:26 pm   Post subject: RE:Storing images in an array?

Can I use jpeg and how do I put choices?
DemonZ




PostPosted: Fri Jan 26, 2007 10:52 am   Post subject: Re: Storing images in an array?

your right freakman, I think i helped a bit too much, sorry but your gonna have to do the rest for yourself, just go into turing documentation to look up some things on jpgs or go onto the tutorials and learn something there, I helped u enough, sorry no more help, but your welcome
zedx_26




PostPosted: Sun Jan 28, 2007 4:58 pm   Post subject: Re: Storing images in an array?

I Got a question what would intstr(i) do in uploading picture command
CodeMonkey2000




PostPosted: Sun Jan 28, 2007 5:02 pm   Post subject: RE:Storing images in an array?

intstr converts an integer value into a string value.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: