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

Username:   Password: 
 RegisterRegister   
 Help with variable setting ... can they do this?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
basketball4ever




PostPosted: Sun Jan 16, 2005 12:27 am   Post subject: Help with variable setting ... can they do this?

K so basically i'm doing snakes & Ladders the game. Pretty simple.... but i want to make it more simple... meaning... i want to set certain points of the squares as a variable.

K so u have no clue what i'm talking about... so i'll explain more in depth
Theres 50 squares.... divided on the screen... i want to label each one from numbers 1-50 in the code. Thus square number 1 = 1 square number 2 =2. Doing this, a player can roll a random integer... if they roll a 5, i can write the code that currentposition := currentposition +5 ... thus they're on square #6 if they started at 1.

The problem i'm having... is setting a variable for each square. More in depthly.... i need a (x,y) for each square. Since each player will have oval shaped pieces... i only need the center point.

So lets say i want square #1 at the point 50,50 and #2 be at 150,50... and so on.
Sponsor
Sponsor
Sponsor
sponsor
TheZsterBunny




PostPosted: Sun Jan 16, 2005 12:40 am   Post subject: (No subject)

hrm

you could use a 2D array and some formulas to calculate where they are on the board.

I believe there is a turing tut. on arrays. read up!

-Z
basketball4ever




PostPosted: Sun Jan 16, 2005 12:43 am   Post subject: (No subject)

o crap... would this work

var position1:int:=1

loop
x = (random roll thing)
delay(1000)
position1:=position1 + x
end loop
Neo




PostPosted: Sun Jan 16, 2005 12:51 am   Post subject: (No subject)

Yes it would.
basketball4ever




PostPosted: Sun Jan 16, 2005 12:56 am   Post subject: (No subject)

Now NEXT and FAR MORE IMPORTANT problem... how can i set "1" as a variable for square #1...
Neo




PostPosted: Sun Jan 16, 2005 12:58 am   Post subject: (No subject)

basketball4ever wrote:
Now NEXT and FAR MORE IMPORTANT problem... how can i set "1" as a variable for square #1...


What do you mean?
basketball4ever




PostPosted: Sun Jan 16, 2005 1:07 am   Post subject: (No subject)

ooo wait... would this work

if position1 := 1 then
place1x:=50
place1y:=50
elsif position1 :=2 then
place1x:=150
place1y:=50
and wen i set where the circle (the player) is... i'll subsitute the coordinates with place1y and place1x...
Cervantes




PostPosted: Sun Jan 16, 2005 7:20 pm   Post subject: (No subject)

Sure, but that's going to be one needlessly big if statement. Zster's method would be the most effective method. Read up on those arrays! I guarantee you, they are simple, though they may look daunting.
If you absolutely insist against using a 2D array, at least spare yourself the trouble and use a case structure.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: