Computer Science Canada

Slot Picture Help

Author:  Scooter341 [ Tue Apr 19, 2005 9:03 pm ]
Post subject:  Slot Picture Help

The code I have right now for selecting the random numbers is:
code:

num1 := Rand.Int (1, 10)

        if num1 >= 1 and num1 <= 3 then
            finalNumber1 := 1
        elsif num1 >= 4 and num1 <= 5 then
            finalNumber1 := 2
        elsif num1 >= 6 and num1 <= 8 then
            finalNumber1 := 3
        elsif num1 = 9 then
            finalNumber1 := 4
        elsif num1 = 10 then
            finalNumber1 := 5
        end if


        num2 := Rand.Int (1, 10)

        if num2 >= 1 and num2 <= 3 then
            finalNumber2 := 1
        elsif num2 >= 4 and num2 <= 5 then
            finalNumber2 := 2
        elsif num2 >= 6 and num2 <= 8 then
            finalNumber2 := 3
        elsif num2 = 9 then
            finalNumber2 := 4
        elsif num2 = 10 then
            finalNumber2 := 5
        end if


        num3 := Rand.Int (1, 10)

        if num3 >= 1 and num3 <= 3 then
            finalNumber3 := 1
        elsif num3 >= 4 and num3 <= 5 then
            finalNumber3 := 2
        elsif num3 >= 6 and num3 <= 8 then
            finalNumber3 := 3
        elsif num3 = 9 then
            finalNumber3 := 4
        elsif num3 = 10 then
            finalNumber3 := 5
        end if

        put "[", finalNumber1, "]" ..
        put "[", finalNumber2, "]" ..
        put "[", finalNumber3, "]"
        put "---------"
        delay (50)
    end for


I can't figure out how to incorporate pictures rather than numbers, say for instance that when finalNumber1 = 1 I want to display a picture of cherries.

Author:  Bacchus [ Tue Apr 19, 2005 9:10 pm ]
Post subject: 

try maing an array to store the picture you want in it
code:
var filepic:array 1..5 of int
filepic(1):=Pic.FileNew("picture\here" etc)
so on
then just use the number you came up with to get that array pic

Author:  Scooter341 [ Thu Apr 21, 2005 8:45 am ]
Post subject: 

I'm sorry but I need you to give an example of how to incorporate that into what i have.

Author:  TheEvilOne [ Thu Apr 21, 2005 9:19 am ]
Post subject: 

What hes saying is this

code:

var filepic:array 1..5 of int


This is an array, each number of the array holds a picture. Like so:

code:

filepic(1) := Pic.FileNew("pictures/sprite1.bmp")
filepic(2) := Pic.FileNew("pictures/sprite2.bmp")
filepic(3) := Pic.FileNew("pictures/sprite2.bmp")
filepic(4) := Pic.FileNew("pictures/sprite2.bmp")
filepic(5) := Pic.FileNew("pictures/sprite2.bmp")

or ...
code:

for i : 1 .. 5
    filepic(i) := Pic.FileNew("pictures/sprite"+intstr(i)+".bmp")
end for


Then at the end of all your if statements, that check which number finalNumber will be you do this:
code:

Pic.Draw(filepic(finalNumber1),x,y,picCopy)
Pic.Draw(filepic(finalNumber2),x,y,picCopy)
Pic.Draw(filepic(finalNumber3),x,y,picCopy)


you can also use picMerge if youre using Pic.SetTransparentColor

anything else?

Author:  Scooter341 [ Thu Apr 21, 2005 10:25 am ]
Post subject: 

oh.....alright. thanks for clearing that up for me man.

Author:  Martin [ Thu Apr 21, 2005 10:35 am ]
Post subject: 

code:

num1 := Rand.Int (1, 10)

        if num1 >= 1 and num1 <= 3 then
            finalNumber1 := 1
        elsif num1 >= 4 and num1 <= 5 then
            finalNumber1 := 2
        elsif num1 >= 6 and num1 <= 8 then
            finalNumber1 := 3
        elsif num1 = 9 then
            finalNumber1 := 4
        elsif num1 = 10 then
            finalNumber1 := 5
        end if


Read through this code block. First, you generate an integer from one to ten. Is it ever going to be less than 1? Of couse not, so why do you check? Now, the next comparison checks to see if it's greater than or equal to 4 or less than or equal to 5. Now, if it gets to that comparison, the number is obviously already greater than three, so therefor it HAS to be greater than or equal to 4. And so on. Get rid of the useless comparisons.

Author:  Scooter341 [ Thu Apr 21, 2005 11:07 am ]
Post subject: 

my code now looks like this:

code:

%Pictures
filepic (1) := Pic.FileNew ("cherries.jpg")
filepic (2) := Pic.FileNew ("apple.jpg")
filepic (3) := Pic.FileNew ("melon.jpg")
filepic (4) := Pic.FileNew ("bar.jpg")
filepic (5) := Pic.FileNew ("skull.jpg")

%Game Play
if num1 >= 1 and num1 <= 3 then
            finalNumber1 := 1
        elsif num1 >= 4 and num1 <= 5 then
            finalNumber1 := 2
        elsif num1 >= 6 and num1 <= 8 then
            finalNumber1 := 3
        elsif num1 = 9 then
            finalNumber1 := 4
        elsif num1 = 10 then
            finalNumber1 := 5
        end if


        num2 := Rand.Int (1, 10)

        if num2 >= 1 and num2 <= 3 then
            finalNumber2 := 1
        elsif num2 >= 4 and num2 <= 5 then
            finalNumber2 := 2
        elsif num2 >= 6 and num2 <= 8 then
            finalNumber2 := 3
        elsif num2 = 9 then
            finalNumber2 := 4
        elsif num2 = 10 then
            finalNumber2 := 5
        end if


        num3 := Rand.Int (1, 10)

        if num3 >= 1 and num3 <= 3 then
            finalNumber3 := 1
        elsif num3 >= 4 and num3 <= 5 then
            finalNumber3 := 2
        elsif num3 >= 6 and num3 <= 8 then
            finalNumber3 := 3
        elsif num3 = 9 then
            finalNumber3 := 4
        elsif num3 = 10 then
            finalNumber3 := 5
        end if

        Pic.Draw (filepic (finalNumber1), 100, 200, picCopy)
        Pic.Draw (filepic (finalNumber2), 175, 200, picCopy)
        Pic.Draw (filepic (finalNumber3), 250, 200, picCopy)
       delay(50)


but the Turing environment keeps crashing and coming up with an access violation error.


: