Errrm ok, that code doesn't make much sense to me as I can't see how that works. For example you have a While without a condition, this immediately throws an error at me?!
Also you have height fields in both. So my questions at the moment would be:
1. how does the mouse interaction work? (is it click->drag->drop or click->click to drop?)
2. why are you using the mouse x/y coords with an 'equal to' check of the counter position? Are all the counters 1x1 in dimension?
A couple of other things to note, you don't have any 'End Type' statements, this throws errors up! Also you don't have a 'Next' for your embedded 'For' statement?!
Having said all this, let's see if I can show you an example of the method I was describing. I would work on the basis of using functions to handle these as Types can be accessed anywhere in the program and it makes for neater programming :)
I'll presume that counters are placed on the squares to a maximum height of 4 counters on a square, and that the last counter placed on the square is always the first selected when the mouse if clicked on it.
Also as your not moving the squares around (I presume only the counters move), I will remove the square type as it is not required, i.e. it is represented but not necessary to track.
*phew that took a while :)
I haven't tested it as I obviously don't have anything to test it with but I think the logic should work ok :)
Let me know if you have any questions or can better explain how your game is intending to use this code/data.
Also you have height fields in both. So my questions at the moment would be:
1. how does the mouse interaction work? (is it click->drag->drop or click->click to drop?)
2. why are you using the mouse x/y coords with an 'equal to' check of the counter position? Are all the counters 1x1 in dimension?
A couple of other things to note, you don't have any 'End Type' statements, this throws errors up! Also you don't have a 'Next' for your embedded 'For' statement?!
Having said all this, let's see if I can show you an example of the method I was describing. I would work on the basis of using functions to handle these as Types can be accessed anywhere in the program and it makes for neater programming :)
I'll presume that counters are placed on the squares to a maximum height of 4 counters on a square, and that the last counter placed on the square is always the first selected when the mouse if clicked on it.
Also as your not moving the squares around (I presume only the counters move), I will remove the square type as it is not required, i.e. it is represented but not necessary to track.
Type counter Field sqx ;x square location Field sqy ;y square location Field cheight ; height on square End Type ; FUNCTION: MoveCounter ; ; Pass the FROM square x and y and the TO square x and y ; ; Returns true if successful or false if the square is full (4 counters) ; Function MoveCounter(fromsqx,fromsqy,tosqx,tosqy) ;cf1-cf4 temp var holds pointers to any found counters on the from square Local cf1.counter,cf2.counter,cf3.counter,cf4.counter ;ct1-ct4 temp var holds pointers to any found counters on the to square Local ct1.counter,ct2.counter,ct3.counter,ct4.counter ;ctm is the pointer to the counter that is moving Local ctm.counter ;c.counter is a temp var used for the loops only Local c.counter ;loop through counters to find those on the from square and work out the counter that is moving For c.counter=Each counter ;if the current counter in the loop is on our from square... If c\sqx=fromsqx And c\sqy=fromsqy Then ;determine the height and place it in the relevant cf? var Select c\cheight Case 1 cf1=c Case 2 cf2=c Case 3 cf3=c Case 4 cf4=c End Select EndIf Next ;work out the topmost counter on the from square and place a pointer in ctm.counter If cf4<>Null Then ctm=cf4 ElseIf cf3<>Null Then ctm=cf3 ElseIf cf2<>Null Then ctm=cf2 ElseIf cf1<>Null Then ctm=cf1 EndIf ;loop through counters to find those on the to square For c.counter=Each counter ;if the current counter in the loop is on our to square... If c\sqx=tosqx And c\sqy=tosqy Then ;determine the height and place it in the relevant ct? var Select c\cheight Case 1 ct1=c Case 2 ct2=c Case 3 ct3=c Case 4 ct4=c End Select EndIf Next ;work out the topmost counter on the to square and update the counter that is moving to be the topmost ;NB: if there are already 4 counters on the square then the counter to move can't be moved! If ct1=Null Then ctm\sqx=tosqx ctm\sqy=tosqy ctm\cheight=1 ElseIf ct2=Null Then ctm\sqx=tosqx ctm\sqy=tosqy ctm\cheight=2 ElseIf ct3=Null Then ctm\sqx=tosqx ctm\sqy=tosqy ctm\cheight=3 ElseIf ct4=Null Then ctm\sqx=tosqx ctm\sqy=tosqy ctm\cheight=4 Else ;already 4 on square so return false Return False EndIf ;if we get to here then the counter was successfully moved so we return true Return True End Function
*phew that took a while :)
I haven't tested it as I obviously don't have anything to test it with but I think the logic should work ok :)
Let me know if you have any questions or can better explain how your game is intending to use this code/data.