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

Username:   Password: 
 RegisterRegister   
 Concentration Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Illusion




PostPosted: Sat Jun 10, 2006 7:58 pm   Post subject: Concentration Help

I know that the Rand.Int of tileLocation chooses any number between 80 and 480, but how do I get the tiles to only show at the locations of (80, 160, 240, 320, 400, 480)?

code:
var tileLocation : array 1 .. 6 of int := init (80, 160, 240, 320, 400, 480)
var fileName : array 1 .. 18 of int := init (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)

for x : 1 .. 36
    var randFileName : int
    var randx, randy : int
    Rand.Int (randFileName, fileName (1), fileName (18))
    randx := Rand.Int (tileLocation (1), tileLocation (6))
    randy := Rand.Int (tileLocation (1), tileLocation (6))
    Pic.ScreenLoad (intstr (randFileName) + ".JPG", randx, randy, picCopy)
end for
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jun 10, 2006 8:30 pm   Post subject: (No subject)

If you want to pick a random element of your tileLocation array,
code:

tileLocation (Rand.Int (1, 6))

or better yet,
code:

tileLocation (Rand.Int (lower (tileLocation), upper (tileLocation)))


But why do you even need a tileLocation array? All you're trying to do is pick a random multiple of 80 between 80 and 480.
code:

Rand.Int (1, 6) * 80


Also, your code has a syntax error on this line:
code:

    Rand.Int (randFileName, fileName (1), fileName (18))

Rand.Int is a function, not a procedure, and it takes two arguments, not three. Rand.Int should be used in preference to the procedure, randint.
Illusion




PostPosted: Sat Jun 10, 2006 9:36 pm   Post subject: (No subject)

ooh, okay. Thanks. Smile

btw, how would i make the tiles not repeat itself more than 2 times, in other words, only showing 2 times on the grid?
Delos




PostPosted: Sat Jun 10, 2006 11:35 pm   Post subject: (No subject)

I'd suggest creating a 'tile' type with as much information attributed to it as necassary, for instance:
code:

type tile :
   record
      x, y : int   % Location
      fileName : int
      drawCount : int  % How many times it's been drawn
   end record


Then have an initialize function:
code:

function initialize (_x, _y, _fileName : int) : tile
   var temp : tile
   temp.x := _x
   temp.y := _y
   temp.fileName := _fileName
   temp.drawCount := 0   % Has not been drawn yet, so default value is 0.
   result temp
end initialize

var myTile : tile := initialize (80, 80, 3)
% or something like:
var the_tiles : array 1..18 of tile
for i : 1 .. upper (the_tiles)
   the_tiles (i) := initialize (Rand.Int (lower (tileLocation), upper (tileLocation)), Rand.Int (lower (tileLocation), upper (tileLocation)), fileName (i))
   % Or whatever values you like...
end for


Whenever you draw a tile from thence, add one to the drawCount; and of course have a stipulation in the draw proc to only draw when drawCount is less than 2...or something thereabouts.

Disclaimer: None of this code is tested, so it might be missing a few brackets or something ^^;. I don't know if the format I set up is in any way reflective of your own programming needs - so don't feel constrained by it. Simply understand the concepts of using types and initialization functions, in conjunction with arrays. From there, it's up to you to add the details.
In short - this was just a brief example.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: