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

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




PostPosted: Mon Nov 12, 2007 6:39 am   Post subject: Visual DICE program

Hi,

I'd like to modify my simple dice program to display the correct BMP files to match the random seed. I'm not sure how to set up the array of pictures:

code:


% The Visual DICE program.
var die1 : int := Pic.FileNew ("1dice.bmp")
var die2 : int := Pic.FileNew ("2dice.bmp")
var die3 : int := Pic.FileNew ("3dice.bmp")
var die4 : int := Pic.FileNew ("4dice.bmp")
var die5 : int := Pic.FileNew ("5dice.bmp")
var die6 : int := Pic.FileNew ("6dice.bmp")
var d1:int
var d2:int


/* var pics : array 0 .. 6 of int
        var sprite: int
        for i : 1 .. 6
            pics (i) := Pic.FileNew (intstr (i) + "dice" + ".bmp")
            if Error.Last not= 0 then
                put "Error loading image: ", Error.LastMsg
                return
            end if
        end for



% Pic.SetTransparentColor (pic, brightred)  */

setscreen ("graphics:768;512")
setscreen ("offscreenonly")


randint (d1, 1, 6)
randint (d2, 1, 6)



% put d1,d2

for x : 100 .. 500
    cls
   
   
    % Pic.Draw (strint("die" + intstr(d1)), x, 100, picMerge)
    Pic.Draw (die1, x, 100, picMerge)
    Pic.Draw (die2, x, 200, picMerge)
    put d1,d2
    View.Update
    delay (1)
end for






The pictures display fine. However, I'm have trouble modifying Pic.Draw (die2, x, 200, picMerge). I'm starting to think that a procedure is the best what to manage which of the 6 die appears.....
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Nov 12, 2007 8:19 am   Post subject: RE:Visual DICE program

I don't know what you're trying to say. You need to tell us more. How are you having trouble modifying that line? What exactly are you trying to do?
iceman




PostPosted: Tue Nov 13, 2007 7:16 am   Post subject: Re: Visual DICE program

I want to use the random seed to determine which dice appear. I need to modify the following line : Pic.Draw (die1, x, 100, picMerge). For example, if the random seed for die # 1 is 5 then the die1 parameter of Pic.Draw() should be changed to die5. Initially, I thought that an array could manage the visual dice program but it appears that I need to use a procedure and pass the random seed values (ex. d1, d2) to the procedure to determine which pictures are displayed.

code:

Pseudocode
============
proc dice(d1,d2)
case d1
if d1 = 1 then
  pic.Draw(die1, x,100,picMerge)
else if d1 = 2 then
...
else if d1 = 6 then
   pic.Draw(die6, x,100,picMerge)
endif

case d2
if d2 = 1 then
  pic.Draw(die1, x,100,picMerge)
else if d1 = 2 then
...
else if d2 = 6 then
   pic.Draw(die6, x,100,picMerge)
endif
end case







What do you think?
Mazer




PostPosted: Tue Nov 13, 2007 9:03 am   Post subject: RE:Visual DICE program

First, you're using "random seed" incorrectly. The random seed is used by the random number generator to pick the next "random number" (it's not actually random, I won't get into details). By default, when your Turing program is started the generator will be seeded using the current system time so that no two runs of your program will turn out exactly the same (if using random numbers) unless they both begin at the same second.

Finally, just make an array of pictures for the dice.

code:

var dicePics : array 1 .. 6 of int
% do your Pic.FileNew for each picture here

die1 := Rand.Int(1, 6)
die2 := Rand.Int(1, 6)

Pic.Draw(dicePics(die1), ...
Pic.Draw(dicePics(die2), ...


EDIT: And I'm not sure you understand how to use case. Read a tutorial on that.
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: