Computer Science Canada

Randomize

Author:  Mystique [ Fri May 26, 2006 4:48 pm ]
Post subject:  Randomize

Okay, I have tried long and hard at this and have given up and now seek ur help Very Happy

I want the "moles", which I have drawn on Turing to appear randomly on the screen, but on the same spot. So, there are 5 holes and 5 different moles, and from each of them I want them to appear randomly, and sometimes even two or more at a time ( so basically, i want it just like an actual whack- a-mole game) I have tried the following:

code:

loop
    background
    randint (e, 200, 500)
    randint (f, 200, 500)
    mole1
    delay (e)
    delay (f)

    background
    randint (c, 300, 1000)
    randint (d, 300, 1000)
    mole2
    delay (c)
    delay (d)


but this obviously is not random. Can someone plz help me? Praying

Author:  TylerL [ Fri May 26, 2006 5:01 pm ]
Post subject: 

I'd do something like this..

code:
var moleX : array 1 .. 5 of int
var moleY : array 1 .. 5 of int
var num : int

moleX(1) := % first mole x position
moleY(1) := % first mole y position
moleX(2) := % second mole x position
moleY(2) := % second mole y position
moleX(3) := % third mole x position
moleY(3) := % third mole y position
moleX(4) := % fourth mole x position
moleY(4) := % fourth mole y position
moleX(5) := % fifth mole x position
moleY(5) := % fifth mole y position

loop

num := Rand.Int (1,5)

drawmolex(num) %
drawmoley(num) % Draw the mole

delay(#)

end loop

Author:  Uber Tankz [ Fri May 26, 2006 5:38 pm ]
Post subject:  WooT

im down with that.

Author:  Mystique [ Fri May 26, 2006 5:41 pm ]
Post subject: 

I tried it and i get an error message saying:

Illegal picture ID number.

Author:  HellblazerX [ Fri May 26, 2006 6:05 pm ]
Post subject: 

It means Turing did not properly load up the images. Make sure that your images are in the same folder as your code.

Author:  Uber Tankz [ Fri May 26, 2006 6:06 pm ]
Post subject:  post all code

Yo, post all your code so we can see whats going on.

Author:  Mystique [ Fri May 26, 2006 6:20 pm ]
Post subject: 

the moles are in the program itself, in procedures. Here was what i was doing originally:

code:

var a, b, c, d, e, f, g, h, i, j : int

proc background
    drawfillbox (0, 0, maxx, maxy, 68)
    %Top holes
    drawfilloval (280, 310, 75, 55, black)              %hole #1
    drawfilloval (510, 310, 75, 55, black)              %hole #2
    %Bottom holes
    drawfilloval (175, 150, 75, 55, black)              %hole #1
    drawfilloval (400, 150, 75, 55, black)              %hole #2
    drawfilloval (620, 150, 75, 55, black)              %hole #3.
end background


proc mole1
    drawfilloval (175, 145, 50, 50, 53)               %body
end mole1

proc mole2
    drawfilloval (400, 145, 50, 50, 53)               %body
end mole2

proc mole3
    drawfilloval (620, 145, 50, 50, 53)               %body
end mole3

proc mole4
    drawfilloval (510, 305, 50, 50, 53)               %body
end mole4

proc mole5
    drawfilloval (280, 305, 50, 50, 53)               %body
end mole5

loop

    background
    randint (e, 200, 500)
    randint (f, 200, 500)
    mole3
    delay (e)
    delay (f)

    background
    randint (a, 500, 2000)         
    randint (b, 500, 2000)         
    mole1
    mole2
    delay (a)
    delay (b)

    background
    randint (g, 70, 900)
    randint (h, 70, 900)
    mole4
    mole5
    delay (g)
    delay (h)

    background
    randint (c, 300, 1000)
    randint (d, 300, 1000)
    mole2
    delay (c)
    delay (d)

    background
    randint (i, 300, 1000)
    randint (j, 300, 1000)
    mole5
    delay (i)
    delay (j)

end loop


: