
-----------------------------------
Naveg
Sun Mar 27, 2005 11:22 am

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?

-----------------------------------
Tony
Sun Mar 27, 2005 12:01 pm


-----------------------------------
well how were you expecting to draw the screen when no cards are moving?

-----------------------------------
Naveg
Sun Mar 27, 2005 12:18 pm


-----------------------------------
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.

-----------------------------------
Tony
Sun Mar 27, 2005 12:20 pm


-----------------------------------
well how were you expecting to draw the screen when no cards are moving?

-----------------------------------
Naveg
Sun Mar 27, 2005 12:26 pm


-----------------------------------
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

-----------------------------------
Tony
Sun Mar 27, 2005 12:33 pm


-----------------------------------
Great. Draw all of that minus the card to be moved

-----------------------------------
Naveg
Sun Mar 27, 2005 12:35 pm


-----------------------------------
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.

-----------------------------------
Tony
Sun Mar 27, 2005 1:01 pm


-----------------------------------
yes, just take a new picture every time you change something on the screen.

-----------------------------------
Naveg
Sun Mar 27, 2005 3:39 pm


-----------------------------------
then how do i capture everything except the selected card...my initial question

-----------------------------------
Tony
Sun Mar 27, 2005 6:31 pm


-----------------------------------
don't draw the selected card when doing the screen capture.

-----------------------------------
Naveg
Sun Mar 27, 2005 7:16 pm


-----------------------------------
ok, that makes sense

-----------------------------------
Naveg
Sun Mar 27, 2005 7:17 pm


-----------------------------------
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?

-----------------------------------
jamonathin
Sun Mar 27, 2005 8:32 pm


-----------------------------------
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.

-----------------------------------
Naveg
Sun Mar 27, 2005 8:34 pm


-----------------------------------
so like....

var columns: array 1..7 of flexible array 1..1 of card

where card has been declared as a type with values suit,value,and picture

-----------------------------------
Cervantes
Sun Mar 27, 2005 8:46 pm


-----------------------------------
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.

-----------------------------------
Naveg
Sun Mar 27, 2005 9:08 pm


-----------------------------------
what do you suggest cervantes?

-----------------------------------
Mr. T
Sun Mar 27, 2005 9:40 pm


-----------------------------------

 Well, you could just make 7 arrays yourself, but that's tedious.

isnt that Cervantes' suggestion?

-----------------------------------
Naveg
Sun Mar 27, 2005 9:45 pm


-----------------------------------
thanks for the input Pwned, anyone else have a less tedious suggestion? otherwise i'll take that one

-----------------------------------
jamonathin
Mon Mar 28, 2005 1:24 pm


-----------------------------------
I say go with the seven arrays.  Start basic so you understand how to make the game well, then try some fancy stuff.

-----------------------------------
RaPsCaLLioN
Mon Mar 28, 2005 4:36 pm


-----------------------------------
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)

var aiPiles : array 1 .. 7, 1 .. 20 of int

.. 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?!

-----------------------------------
Naveg
Mon Mar 28, 2005 5:37 pm


-----------------------------------
yes i am, i have an array 1..52 of type card, where card has values suit, value, and picture

-----------------------------------
Naveg
Mon Mar 28, 2005 6:50 pm


-----------------------------------
so this is my array for the deck of cards:

type card :
    record
        suit : int
        value : int
        pic : int
    end record

var deck : array 1 .. 52 of card

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?

-----------------------------------
Cervantes
Mon Mar 28, 2005 7:18 pm


-----------------------------------
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.

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:

var column : array 1 .. 7 of
    record
        pile : array 1 .. 7 of Card
        face_up_column : array 1 .. 13 of Card
    end record

Mind you, pile and face_up_column (need a better name) might not necessarily be of typeSpec Card.

-----------------------------------
lordofall
Mon Mar 28, 2005 7:51 pm


-----------------------------------
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.

-----------------------------------
Naveg
Mon Mar 28, 2005 8:54 pm


-----------------------------------
can you explain a bit more clearly what you would do if i have this for the deck

type card :
    record
        suit : int
        value : int
        pic : int
    end record

var deck : array 1 .. 52 of card

-----------------------------------
Cervantes
Mon Mar 28, 2005 8:58 pm


-----------------------------------
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.


class COLUMN_CLASS
    export addCard, removeCard, topCard
    var spot : flexible array 1 .. 0 of int %of card number

    proc addCard (cardNum : int)
        new spot, upper (spot) + 1
        spot (upper (spot)) := cardNum
    end addCard
    proc removeCard
        new spot, upper (spot) - 1
    end removeCard
    function topCard : int
        result spot (upper (spot))
    end topCard
end COLUMN_CLASS

var column : array 1 .. 7 of ^COLUMN_CLASS
for i : 1 .. upper (column)
    new COLUMN_CLASS, column (i)
end for


-----------------------------------
Naveg
Mon Mar 28, 2005 9:30 pm


-----------------------------------
ok i'm having trouble deciding which method to use. Which one is the simplest and easiest to use, yet functional?

-----------------------------------
RaPsCaLLioN
Mon Mar 28, 2005 9:48 pm


-----------------------------------
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.

-----------------------------------
Naveg
Tue Mar 29, 2005 12:26 am


-----------------------------------
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
