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

Username:   Password: 
 RegisterRegister   
 assign pics to variables
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Biohazzrd




PostPosted: Tue Apr 04, 2006 4:25 pm   Post subject: assign pics to variables

Ok i have to make a blackjack game, Imade the cards and assigned their values but I can't figure out how to make them represented by a picture
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Tue Apr 04, 2006 4:32 pm   Post subject: (No subject)

code:
var pic : int
pic := Pic.FileNew ("filename")


all picture values are in int, so you need an int variable to hold it. Is that what you're trying to ask, or are you asking how to draw them:

code:
Pic.Draw (pic, 1, 1, PicMerge)


The last parameters states what mode to draw in: PicMerge, PicCopy, PicXOR, and PicUnderMerge
RedRogueXIII




PostPosted: Wed Apr 05, 2006 4:47 pm   Post subject: (No subject)

For Picture Sets I would suggest using arrays to hold pictures.
code:

var hearts, clubs, spades : array 0..(max#of pics) of int
for i: 1.. upper(hearts)
    hearts(i):=Pic.FileNew("heartcard1.bmp")
end for


Its just easier to call different pictures.

If you don't know about arrays then look through this tutorial for more about them.
http://www.compsci.ca/v2/viewtopic.php?t=8808
Cervantes




PostPosted: Wed Apr 05, 2006 7:25 pm   Post subject: (No subject)

RedRogueXIII wrote:
For Picture Sets I would suggest using arrays to hold pictures.
code:

var hearts, clubs, spades : array 0..(max#of pics) of int
for i: 1.. upper(hearts)
    hearts(i):=Pic.FileNew("heartcard1.bmp")
end for


Four parallel arrays? Parallel arrays are usually a bad idea. Use a two dimensional array 1 .. 13 of array 1 .. 4 of int, or an array 1 .. 13 of a record (that defines the suit), or an array 1 .. 52 of pointer to Card (of Card objects).
RedRogueXIII




PostPosted: Thu Apr 06, 2006 6:25 pm   Post subject: (No subject)

I only meant to declare four different arrays in one line to sort easier by name. Not four parallel arrays instead of going :
code:

var hearts : array 0..(max#of pics) of int
var clubs : array 0..(max#of pics) of int
var spades : array 0..(max#of pics) of int


and by (max#of pics) I'm mean how many he wants in that particular set of pictures.

::: BTW I don't play cards so I'm not that familiar at all with them.
Cervantes




PostPosted: Thu Apr 06, 2006 6:45 pm   Post subject: (No subject)

RedRogueXIII wrote:
I only meant to declare four different arrays in one line to sort easier by name. Not four parallel arrays instead of going :
code:

var hearts : array 0..(max#of pics) of int
var clubs : array 0..(max#of pics) of int
var spades : array 0..(max#of pics) of int


I don't understand what you're saying. This code is the same as the initial code. You've made parallel arrays.

Parallel arrays are multiple arrays that are meant to be used together to store data on similar objects. For example, I might have 10 asteroids in a game of asteroids. I have to store data about their x and y coordinates, so I might do this:
code:

var asteroid_x : array 1 .. 10 of int
var asteroid_y : array 1 .. 10 of int

This is NOT good. What if you blew up an asteroid? You'd have to remove an element from both arrays, and you'd have to make certain that you removed the right one from both arrays: if something got mucked up (say you only removed an element from one array) then all your y coordinates would get matched against the wrong x coordinates.

The solution goes like this. We need to store an array of data for asteroids; each asteroid needs two integers to define its position. We can create our own data type (like int, string, boolean, etc., except custom). To do this, we use type and record
code:

type coord :
    record
        x : int
        y : int
    end record
var my_ship : coord
my_ship.x := 100
my_ship.y := 150
var asteroid : array 1 .. 10 of coord
for i : 1 .. 10
    asteroid (i).x := Rand.Int (0, maxx)
    asteroid (i).y := Rand.Int (0, maxy)
end for

Now when we blow up an asteroid and want to delete it from the array, it is a simple matter of deleting a single element. No worrying about deleting multiple elements from multiple arrays, and hoping that the right data is being deleted. The data for each asteroid is bound together.

For more information, see the Records Tutorial.
RedRogueXIII wrote:

::: BTW I don't play cards so I'm not that familiar at all with them.

Then maybe I should point out that there is a fourth suit: diamonds. Wink
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: