Page 2 of 2

Re: Snakes and ladders game

Posted: Sun Jan 25, 2015 12:18 pm
by SparkOut
NRobb2 wrote:Basically I have created the board currently by using lots of image fields, and setting their location 1 by 1 in the code. However, I need to have used a 2D array somewhere in my project for it to be at Advanced Higher, and we have not yet been taught 2D arrays so I have very little ideas as to where this could be included within snakes and ladders.
Arrays in LiveCode are "associative tables" so you are not restricted to numerical indexing. However, numerical indexing of 10 rows with 10 columns each is a perfect use case here.
Space 1 is the square on row 1, column 1. You can refer to it in an array of your choosing with numerical indexing thus:
tBoardLocA[1][1]
Space 47 is the square on row 4, column 4 (oddly enough... Because the board numbers go back and forth in snakes and ladders). However, depending on what you are storing in the array (eg the space location) you could possibly ignore that and just as easily say it is array reference tBoardLocA[4][7].
If you

Code: Select all

put "200,300" into tBoardLocA[4][7]
and have the right location stored in all of the array indices you can (for instance)

Code: Select all

move image "player1.PNG" to tBoardLocA[4][7] in 3 seconds
Of course you would want to break the move up into stages and check if the edge of the board is reached and needs to move up a row.
Having said all that, although a grid of 10 x 10 is a perfect use case for a 2d array, I think I would do it differently in this situation, but there is no reason you can't.

Re: Snakes and ladders game

Posted: Thu Jan 29, 2015 11:01 am
by NRobb2
Ah thanks spark :D That makes so much more sense now :D Our teacher is going over 2D arrays today, so will hopefully be able to continue with my project when i get in from school!

Re: Snakes and ladders game

Posted: Sat Feb 07, 2015 4:22 pm
by NRobb2
Quick question about the rescaling of the card/stack. Am I able to fix the card to a specific size (a size different to all other cards in the stack) in LiveCode Community 7.0??. All cards currently appear as the same size which is an issue as on my title page there is now a large amount of blank space.

Re: Snakes and ladders game

Posted: Sat Feb 07, 2015 4:47 pm
by Klaus
Hi NRobb2,

size of stack = size of ALL cards in that stack! 8)
You can if course set the stack dimensions "on preopencard" and restore it again "on closecard" for specific cards!

And you can of course also create an extra stack only for your title page with the correct dimensions :D


Best

Klaus

Re: Snakes and ladders game

Posted: Sat Feb 07, 2015 5:54 pm
by NRobb2
Ah thanks Klaus :D however, is there any way that I can have this new mainstack hidden until a 'Game Play' button is pressed? So that when the user loads the game up there will not be two stacks visible. I know how to hide the stacks when the user presses a button, but not when there is no specific event causing it. Oh and how do link the two stacks together so they save in the same place?

Re: Snakes and ladders game

Posted: Sun Feb 08, 2015 2:14 pm
by Klaus
Hi NRobb2,

do this:
1. Make a separate stack for your "Title card" and turn THAT one into the standalone!
I supposed the button "Start game" will be on that card, right?

2. Make the actual GAME stack a substack of the above mentioned stack.
That way only stack 1. will open when you start the standalone and in teh script of the "Start game" button
you can hide the "Title" stack and go to your GAME stack.

Know what I mean?


Best

Klaus

Re: Snakes and ladders game

Posted: Sun Feb 08, 2015 4:15 pm
by NRobb2
That works brilliantly! Thanks for your help Klaus :D Much apreciated :D

Re: Snakes and ladders game

Posted: Sun Feb 22, 2015 7:05 pm
by NRobb2
how can I rotate an image in live code??

Re: Snakes and ladders game

Posted: Sun Feb 22, 2015 8:02 pm
by Klaus
NRobb2 wrote:how can I rotate an image in live code??
Maybe very slowly?
Sorry, just kidding! :D

You want to:
...
set the angle of img "your image here" to 90
## or any degree from 0 - 359
...


Best

Klaus

Re: Snakes and ladders game

Posted: Sun Mar 08, 2015 11:49 am
by NRobb2
My program is more or less finished now, I just have a couple of things to change. Is there anyway that I can move from one procedure to another within a button? I know that you can get:

Code: Select all

If the result = cancel then exit to top
or variations of that. I am looking for something like:

Code: Select all

If total_player1 = 81 then go to procedure spin_dice_player2
. We have never been taught this so I do not know if it is even possible. This is basically for if counter 1 has reached the final square and another 1 has not then counter 1's dice will no longer be spun. This is all within the 1 button.

Thanks

Re: Snakes and ladders game

Posted: Sun Mar 08, 2015 1:55 pm
by Klaus
Did setting the angle work for you some time ago? 8)

Re: Snakes and ladders game

Posted: Sun Mar 08, 2015 1:58 pm
by NRobb2
It certainly did 8)

Re: Snakes and ladders game

Posted: Sun Mar 08, 2015 2:12 pm
by Klaus
AHA! 8)

Do like this:

Code: Select all

...
If total_player1 = 81 then 

   ## Call new procedure:
   spin_dice_player2

   ## Then exit current handler:
   exit name_of_current_handler
end if
...