Computer Science Canada solitaire help |
Author: | Naveg [ Sun Mar 27, 2005 11:22 am ] |
Post subject: | solitaire help |
ok i need some help with solitaire. I'm using pictures to do all the cards, but i dont know how to allow the user to drag a card with the mouse. I know the basic Mouse commands, but the problem is with the constantly changing screen. In a loop i'd have to keep redrawing the screen minus that card, then draw the card on top. How would i do this? |
Author: | Tony [ Sun Mar 27, 2005 12:01 pm ] |
Post subject: | |
well how were you expecting to draw the screen when no cards are moving? |
Author: | Naveg [ Sun Mar 27, 2005 12:18 pm ] |
Post subject: | |
well normally when you'd move something you have like a set background, then you loop drawing the background and the piece on top. But here the background is always changing. If i take pic(0,0,maxx,maxy) then it includes the piece i'm about to move, but i want that piece to not be part of the background. |
Author: | Tony [ Sun Mar 27, 2005 12:20 pm ] |
Post subject: | |
tony wrote: well how were you expecting to draw the screen when no cards are moving? |
Author: | Naveg [ Sun Mar 27, 2005 12:26 pm ] |
Post subject: | |
the screen starts in an initial blank state, with the back of the deck and white boxes for where the card columns will be, the cards are placed by moving with the mouse |
Author: | Tony [ Sun Mar 27, 2005 12:33 pm ] |
Post subject: | |
Great. Draw all of that minus the card to be moved |
Author: | Naveg [ Sun Mar 27, 2005 12:35 pm ] |
Post subject: | |
is there a way to do that taking pic(0,0,maxx,maxy)? cause otherwise i wouldnt know how to do it, cause as i said, whats on the screen is constantly changing. |
Author: | Tony [ Sun Mar 27, 2005 1:01 pm ] |
Post subject: | |
yes, just take a new picture every time you change something on the screen. |
Author: | Naveg [ Sun Mar 27, 2005 3:39 pm ] |
Post subject: | |
then how do i capture everything except the selected card...my initial question |
Author: | Tony [ Sun Mar 27, 2005 6:31 pm ] |
Post subject: | |
don't draw the selected card when doing the screen capture. |
Author: | Naveg [ Sun Mar 27, 2005 7:16 pm ] |
Post subject: | |
ok, that makes sense |
Author: | Naveg [ Sun Mar 27, 2005 7:17 pm ] |
Post subject: | |
another question, what would be the best way to keep track of the pictures in each column? have an array for each one? also, is there a way to lift a picture off the screen without afftecting whats under it? |
Author: | jamonathin [ Sun Mar 27, 2005 8:32 pm ] |
Post subject: | |
I would say have each colomn as a flexible array, and just assign a value to each card in that column, and when it's time to draw, it draws the appropriate amount, and the appropriate cards. |
Author: | Naveg [ Sun Mar 27, 2005 8:34 pm ] | ||
Post subject: | |||
so like....
where card has been declared as a type with values suit,value,and picture |
Author: | Cervantes [ Sun Mar 27, 2005 8:46 pm ] |
Post subject: | |
No, that's not allowed! Because Turing won't let you use a flexible array within a record, or a multidimensional array with the second dimension being flexible, I think this idea is pretty much dead. Well, you could just make 7 arrays yourself, but that's tedious. |
Author: | Naveg [ Sun Mar 27, 2005 9:08 pm ] |
Post subject: | |
what do you suggest cervantes? |
Author: | Mr. T [ Sun Mar 27, 2005 9:40 pm ] |
Post subject: | |
Cervantes wrote: Well, you could just make 7 arrays yourself, but that's tedious. isnt that Cervantes' suggestion? |
Author: | Naveg [ Sun Mar 27, 2005 9:45 pm ] |
Post subject: | |
thanks for the input Pwned, anyone else have a less tedious suggestion? otherwise i'll take that one |
Author: | jamonathin [ Mon Mar 28, 2005 1:24 pm ] |
Post subject: | |
I say go with the seven arrays. Start basic so you understand how to make the game well, then try some fancy stuff. |
Author: | RaPsCaLLioN [ Mon Mar 28, 2005 4:36 pm ] | ||
Post subject: | |||
Why not still go multi-dimensional. Just set a boundry rather than being flexible. If you're just talkin regular solitaire then last column's max number of turned down cards is 7. And max number facing up would be 13. So max in 1 pile would be 20 (the last pile)
.. and then use a saved number at each location to index the picture. 1-13 = Hearts 14-26 = Diamonds 27-39 = Clubs 40-52 = Spades 0 = no card Are you using 52 different pics for all the cards?! |
Author: | Naveg [ Mon Mar 28, 2005 5:37 pm ] |
Post subject: | |
yes i am, i have an array 1..52 of type card, where card has values suit, value, and picture |
Author: | Naveg [ Mon Mar 28, 2005 6:50 pm ] | ||
Post subject: | |||
so this is my array for the deck of cards:
now what would be the best way to make the columns? should i do it rapscallions way or with 7 separate arrays for the columns. if i do it rapscallions way, what shoud the array be of...card or int? |
Author: | Cervantes [ Mon Mar 28, 2005 7:18 pm ] | ||
Post subject: | |||
Perhaps you could make an array (1 .. 7) of instances of a COLUMN class. Or, if you don't want to do that (it'd be a lot more difficult than using arrays and no classes), I'd go with the non-flexible, 2D array. Vladimir wrote: if i do it rapscallions way, what shoud the array be of...card or int? What information do you need your array to store? If it only needs to store one thing, make it int. If it needs to store more than one thing, make make it of a specific type. Rapscallion's method (if I understand correctly) is to use a 2D array from 1 to 7 for each column and from 1 to 20 for the maximum amount of cards that could ever be in a column. But how do you know which is the face down pile, and which is the face up column? What about this:
Mind you, pile and face_up_column (need a better name) might not necessarily be of typeSpec Card. |
Author: | lordofall [ Mon Mar 28, 2005 7:51 pm ] |
Post subject: | |
umm array of column class is prolly the best idea i think my school had to do the same with dominos tho works like this. Array of 7 column classes each column class should have an array of up to 20 or whatever cards, they can easily handle the 52 cards, with a counter that keeps track of how many cards are in each column ex. class column var cards:array 1..52 of int var size:int := 7 %changes whenever a card is added or subtracted end column and now you can pass how many cards each column has and they won't crash because your programming should stop them from being able to go past the maximum size. (this is to get around flexible arrays) now cards can be an int as earlier explained, and the columns just needs to know how to handle them and u can just keep calling them to get cards, place cards etc. (aka holdingCard:= column -> getCard) you'll prolly want the stacks to be a class and the deck a class too so you can easily add to them or rotate in the case of the deck. |
Author: | Naveg [ Mon Mar 28, 2005 8:54 pm ] | ||
Post subject: | |||
can you explain a bit more clearly what you would do if i have this for the deck
|
Author: | Cervantes [ Mon Mar 28, 2005 8:58 pm ] | ||
Post subject: | |||
the column class wouldn't need to have it's own array of the 52 cards. That should be global, or be part of a deck class (but using a deck class might make things really difficult. Maybe I just suck with classes, but I find it exponentially harder to work with multiple different classes in the same program than with a single class). All the column class would need to do is store the number of the card that is in each of it's spots.
|
Author: | Naveg [ Mon Mar 28, 2005 9:30 pm ] |
Post subject: | |
ok i'm having trouble deciding which method to use. Which one is the simplest and easiest to use, yet functional? |
Author: | RaPsCaLLioN [ Mon Mar 28, 2005 9:48 pm ] |
Post subject: | |
I hate classes. With my method you could add another variable to your type. ie. faceup : boolean - true if faceup - false if facedown or Use an array of variables as a divider of the column. var aiDivides : array 1..7 of int and set each integer to where the last face down card is. Anything above that location is face up, anything = or below is face down. |
Author: | Naveg [ Tue Mar 29, 2005 12:26 am ] |
Post subject: | |
i like your idea, i think i'm going to go ahead with it as long as there are no major problems with using that method thanks guys, youre all a great help |