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

Username:   Password: 
 RegisterRegister   
 Assigning Values + Importing Multiple Images ?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
meagmack




PostPosted: Sun May 30, 2010 4:45 pm   Post subject: Assigning Values + Importing Multiple Images ?

What is it you are trying to achieve?
<I'm trying to make a blackjack game for my final project>


What is the problem you are having?
<Basically, I'm wondering if there is a way to import the images of all of the cards, and then assign them a value. So the image of the 2 of clubs would have a value of 2 and so on.Making it loads easier to see who won.>


Describe what you have tried to solve this problem
<I've tried using the code below, but it came up with an answer of 14003 when I import the pictures, but it is right when I take out the pictures.. which really doesn't help me at all. So I'm not sure if it is something small that I am doing wrong or if it is even possible. LOL. Guidance and suggestions would be MUCH appreciated.>


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

Turing:


var pic_cards array : 1..52 of int := init (11,2,3,4,5,6,7,8,9,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10)
for i : 1..52
 pic_cards(i):= ("cards"+intstr(i)+".bmp")
end for
%test
put pic_cards(1) + pic_cards(2)

Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Sun May 30, 2010 4:59 pm   Post subject: Re: Assigning Values + Importing Multiple Images ?

A variable can only hold one value. If you overwrite that variable (by, say, placing an image ID in it,) the old value is lost. Either have aseparate and corresponding array for the values, or use a 2 dimensional array (an array that holds other arrays), with one set being values and one set being images.

2D arrays are declared as:

code:

var myArray : array 1 .. 2, 1 .. 52 of int


Which would create a array that holds 2 other arrays, and each of those arrays holds 52 integers.

You access a 2D array in the same way as a normal array, but with an extra subscript:

code:

myArray(1, 4) := 2 %4th element of the 1st array in myArray
myArray(2, 7) := 28 %2nd element of the 2nd array in myArray
TerranceN




PostPosted: Sun May 30, 2010 5:20 pm   Post subject: RE:Assigning Values + Importing Multiple Images ?

Or you could use an array of records with the fields image and value.
meagmack




PostPosted: Sun May 30, 2010 5:33 pm   Post subject: Re: RE:Assigning Values + Importing Multiple Images ?

Thanks everybody, got it figured out now Smile

... or not
is there a certain data type that I should be using ?
i've tried both int and real with no luck on this code

code:
View.Set ("graphics:528;498,position:center;center,nobuttonbar")

var pic_cards : array 1 .. 2, 1 .. 52 of int
for a : 1 .. 2
    for b : 1 .. 52
        pic_cards (a, b) := ("cards" + intstr (a) + ".bmp") % says that this is the wrong data type..
% makes all of the aces worth 11
        if b = 1 or b = 14 or b = 27 or b = 40 then
            pic_cards (a, b) := 11
% makes all of the kings, queens, and jacks worth 10
        elsif b = 11 or b = 12 or b = 13 or b = 24 or b = 25 or b = 26 or b = 37 or b = 38 or b = 39 or b = 50 or b = 51 or b = 52 then
            pic_cards (a, b) := 10

% not finished this part yet
        end if

[/syntax]
TerranceN




PostPosted: Sun May 30, 2010 7:58 pm   Post subject: RE:Assigning Values + Importing Multiple Images ?

Turing:
("cards" + intstr (a) + ".bmp")

is a string, you probably meant
Turing:
Pic.FileNew("cards" + intstr (a) + ".bmp")


I would still recommend that you use types, it keeps your code cleaner and makes it easier to expand.

Also, you can use the mod command and a loop instead of listing every multiple of 13.

Finally, the idea of using a multi-dimensional array is to use one of the indices to access one of the integers (either image or value) so there is no reason for this:
Turing:
for a : 1 .. 2
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  [ 5 Posts ]
Jump to:   


Style:  
Search: