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

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




PostPosted: Wed Oct 27, 2004 4:21 pm   Post subject: Slot Macine help

I am having trouble with my slot machine program. I have the pictures moving but I am having trouble getting them to stop when i want. At the moment they do about 1 rotation. What is wrong?

code:
setscreen ("graphics: 340;180")
var background : int := Pic.FileNew ("SlotMachine.bmp")
var pic1 : int := Pic.FileNew ("Banana.bmp")
var pic2 : int := Pic.FileNew ("Grape.bmp")
var pic3 : int := Pic.FileNew ("Orange.bmp")
var pic4 : int := Pic.FileNew ("Banana.bmp")
var pic5 : int := Pic.FileNew ("Grape.bmp")
var pic6 : int := Pic.FileNew ("Orange.bmp")
var pic7 : int := Pic.FileNew ("Banana.bmp")
var pic8 : int := Pic.FileNew ("Grape.bmp")
var pic9 : int := Pic.FileNew ("Orange.bmp")
var square1 : int := Pic.FileNew ("Square.bmp")
var square2 : int := Pic.FileNew ("Square.bmp")
var square3 : int := Pic.FileNew ("Square.bmp")
var t, r, q1, q2, q3 : int := 1
var y : array 1 .. 9 of int

randint (t, 2000, 4000)
randint (q1, 7, 9)
randint (q2, 5, 7)
randint (q3, 3, 5)

for z : 1 .. 9
    y (z) := 0
end for

proc draw
    Pic.Draw (pic1, 62, 81 + y (1), picUnderMerge)
    Pic.Draw (pic2, 62, 200 + y (2), picUnderMerge)
    Pic.Draw (pic3, 62, 319 + y (3), picUnderMerge)
    Pic.Draw (pic4, 142, 81 + y (4), picUnderMerge)
    Pic.Draw (pic5, 142, 200 + y (5), picUnderMerge)
    Pic.Draw (pic6, 142, 319 + y (6), picUnderMerge)
    Pic.Draw (pic7, 224, 81 + y (7), picUnderMerge)
    Pic.Draw (pic8, 224, 200 + y (8), picUnderMerge)
    Pic.Draw (pic9, 224, 319 + y (9), picUnderMerge)
end draw

Pic.SetTransparentColor (background, white)
Pic.SetTransparentColor (pic1, white)
Pic.SetTransparentColor (pic2, white)
Pic.SetTransparentColor (pic3, white)
Pic.SetTransparentColor (pic4, white)
Pic.SetTransparentColor (pic5, white)
Pic.SetTransparentColor (pic6, white)
Pic.SetTransparentColor (pic7, white)
Pic.SetTransparentColor (pic8, white)
Pic.SetTransparentColor (pic9, white)

Pic.Draw (background, 0, 0, picCopy)



loop
    Pic.Draw (square1, 61, 82, picCopy)
    Pic.Draw (square2, 140, 82, picCopy)
    Pic.Draw (square3, 219, 82, picCopy)
    draw
    y (1) := y (1) - q1
    y (2) := y (2) - q1
    y (3) := y (3) - q1
    y (4) := y (4) - q2
    y (5) := y (5) - q2
    y (6) := y (6) - q2
    y (7) := y (7) - q3
    y (8) := y (8) - q3
    y (9) := y (9) - q3
    delay (20)
    if y (3) < -250 and y (1) < -100 then
        y (1) := 110
        y (2) := 110
    end if
    if y (3) < -319 then
        y (3) := 45
    end if
    if y (6) < -250 and y (4) < -100 then
        y (4) := 110
        y (5) := 110
    end if
    if y (6) < -319 then
        y (6) := 45
    end if
    if y (9) < -250 and y (7) < -100 then
        y (7) := 110
        y (8) := 110
    end if
    if y (9) < -319 then
        y (9) := 45
    end if
    r := r + 1

    if r > t and y (1) = 79 or y (1) = 80 or y (1) = 81 or y (1) = 82 or y (1) = 83 or y (2) = 79 or y (2) = 80 or y (2) = 81 or y (2) = 82 or y (2) = 83 or y (3) = 79 or y (3) = 80 or y (3) = 81 or y (3) = 82 or y (3) = 83 then
        q1 := 0
    end if
    if r > t and y (4) = 79 or y (4) = 80 or y (4) = 81 or y (4) = 82 or y (4) = 83 or y (5) = 79 or y (5) = 80 or y (5) = 81 or y (5) = 82 or y (5) = 83 or y (6) = 79 or y (6) = 80 or y (6) = 81 or y (6) = 82 or y (6) = 83 then
        q2 := 0
    end if
    if r > t and y (1) = 79 or y (1) = 80 or y (1) = 81 or y (1) = 82 or y (1) = 83 or y (8) = 79 or y (8) = 80 or y (8) = 81 or y (8) = 82 or y (8) = 83 or y (9) = 79 or y (9) = 80 or y (9) = 81 or y (9) = 82 or y (9) = 83 then
        q3 := 0
    end if
end loop


After I get this figured out I will add all the money stuff.



Slot Machine.rar
 Description:
Everything needed for the program to run.

Download
 Filename:  Slot Machine.rar
 Filesize:  137.41 KB
 Downloaded:  143 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Oct 27, 2004 4:48 pm   Post subject: (No subject)

eh... instead of having a dozen if or whatever statement, why not just check for low/high bounds?
code:

if y(1)>=79 and y(1) <=83 then
...


as for the single rotation -
code:

 q1 := 0


you're just stopping your rotating piece instantly (on the first pass I would assume)

I'd do something like
code:

if q1>0 then
q1 -= 10
else
q1 := 0
end if

Slow down the rotation by 10 units (or whatever suits) on each loop pass, so that the rotation slows down gradually.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Juxsta




PostPosted: Sat Oct 30, 2004 7:09 pm   Post subject: (No subject)

Thnx for the reply. How would i get the program to stop wehn a user presses Esc anytime during the game? Here is my new code:

code:
import GUI
setscreen ("graphics: 340;210")
var background : int := Pic.FileNew ("SlotMachine.jpg")
var pic1 : int := Pic.FileNew ("Banana1.bmp")
var pic2 : int := Pic.FileNew ("Grape.bmp")
var pic3 : int := Pic.FileNew ("Orange.bmp")
var pic4 : int := Pic.FileNew ("Banana1.bmp")
var pic5 : int := Pic.FileNew ("Grape.bmp")
var pic6 : int := Pic.FileNew ("Orange.bmp")
var pic7 : int := Pic.FileNew ("Banana1.bmp")
var pic8 : int := Pic.FileNew ("Grape.bmp")
var pic9 : int := Pic.FileNew ("Orange.bmp")
var square1 : int := Pic.FileNew ("Square.bmp")
var square2 : int := Pic.FileNew ("Square.bmp")
var square3 : int := Pic.FileNew ("Square.bmp")
var q1, q2, q3 : int := 1
var bet, winnings, balance : int := 0
var key : string (1)
var y : array 1 .. 9 of int
var d, e, button, spin, font1 : int
var balance1, bet1, winnings1 : string
var maxbet : boolean := false
balance := 100
for z : 1 .. 9
    y (z) := 0
end for

font1 := Font.New ("Sans Serif:14")

View.Set ("offscreenonly")


put "You will receive $100 in your balance."
put "You can bet $1 to $10 by pressing the 'bet one' button or to go directly to $10, press 'bet max'"
put "If you would like to exit prematurly, press esc."
put "Press any key to continue." ..
View.Update
getch (key)
View.Update

proc draw
    Pic.Draw (background, 0, 0, picCopy)
    Pic.Draw (pic1, 75, 81 + y (1), picUnderMerge)
    Pic.Draw (pic2, 62, 200 + y (2), picUnderMerge)
    Pic.Draw (pic3, 62, 319 + y (3), picUnderMerge)
    Pic.Draw (pic4, 153, 81 + y (4), picUnderMerge)
    Pic.Draw (pic5, 142, 200 + y (5), picUnderMerge)
    Pic.Draw (pic6, 142, 319 + y (6), picUnderMerge)
    Pic.Draw (pic7, 235, 81 + y (7), picUnderMerge)
    Pic.Draw (pic8, 224, 200 + y (8), picUnderMerge)
    Pic.Draw (pic9, 224, 319 + y (9), picUnderMerge)
    Font.Draw (winnings1, 267, 61, font1, 12)
    Font.Draw (balance1, 16, 14, font1, 12)
    Font.Draw (bet1, 75, 61, font1, 12)
end draw
Pic.SetTransparentColor (background, white)
Pic.Draw (background, 0, 0, picCopy)

loop
    spin := 0
    loop
        Mouse.Where (d, e, button)
        Text.Locate (1, 1)
        if button = 0 then
            balance1 := intstr (balance)
            bet1 := intstr (bet)
            winnings1 := intstr (winnings)
            Pic.Draw (background, 0, 0, picCopy)
            Font.Draw (balance1, 16, 13, font1, 12)
            Font.Draw (bet1, 75, 61, font1, 12)
            Font.Draw (winnings1, 267, 61, font1, 12)
            View.Update
        else
            if d > 94 and d < 137 and e > 24 and e < 51 then
                winnings := 0
                if bet > 19 then
                    bet := 20
                else
                    bet := bet + 1
                    balance := balance - 1
                end if
                balance1 := intstr (balance)
                bet1 := intstr (bet)
                winnings1 := intstr (winnings)
                cls
                Pic.Draw (background, 0, 0, picCopy)
                Font.Draw (balance1, 16, 13, font1, 12)
                Font.Draw (bet1, 75, 61, font1, 12)
                Font.Draw (winnings1, 267, 61, font1, 12)
                delay (150)
                View.Update
            elsif d > 169 and d < 201 and e > 23 and e < 51 then
                spin := 1
                balance1 := intstr (balance)
                bet1 := intstr (bet)
                winnings1 := intstr (winnings)
                Font.Draw (balance1, 16, 13, font1, 12)
                Font.Draw (bet1, 75, 61, font1, 12)
                Font.Draw (winnings1, 267, 61, font1, 12)
                View.Update
            elsif d > 223 and d < 265 and e > 23 and e < 51 and maxbet = false then
                winnings := 0
                if bet > 20 then
                    bet := 20
                else
                    bet := 20
                    balance := balance - 20
                end if
                balance1 := intstr (balance)
                bet1 := intstr (bet)
                winnings1 := intstr (winnings)
                cls
                Pic.Draw (background, 0, 0, picCopy)
                Font.Draw (balance1, 16, 14, font1, 12)
                Font.Draw (bet1, 75, 61, font1, 12)
                Font.Draw (winnings1, 267, 61, font1, 12)
                delay (150)
                View.Update
                maxbet := true
            end if
            exit when spin > 0
        end if
    end loop
    randint (q1, 50, 70)
    randint (q2, 40, 60)
    randint (q3, 30, 50)
    loop
        cls
        draw
        View.Update
        if q1 > 1 then
            q1 -= 1
        elsif q1 = 1 then
            if y (1) <= 10 and y (1) >= 5 then
                q1 := 0
            elsif y (2) <= -116 and y (2) >= -121 then
                q1 := 0
            elsif y (3) <= -235 and y (3) >= -240 then
                q1 := 0
            end if
        elsif q1 = 0 then
            q1 := 0
        else
            q1 := 1
        end if
        if q2 > 1 then
            q2 -= 1
        elsif q2 = 1 then
            if y (4) <= 10 and y (4) >= 5 then
                q2 := 0
            elsif y (5) <= -116 and y (5) >= -121 then
                q2 := 0
            elsif y (6) <= -235 and y (6) >= -240 then
                q2 := 0
            end if
        elsif q1 = 0 then
            q1 := 0
        else
            q2 := 1
        end if
        if q3 > 1 then
            q3 -= 1
        elsif q3 = 1 then
            if y (7) <= 10 and y (7) >= 5 then
                q3 := 0
            elsif y (8) <= -116 and y (8) >= -121 then
                q3 := 0
            elsif y (9) <= -235 and y (9) >= -240 then
                q3 := 0
            end if
        elsif q1 = 0 then
            q1 := 0
        else
            q3 := 1
        end if

        exit when q1 = 0 and q2 = 0 and q3 = 0

        y (1) := y (1) - q1
        y (2) := y (2) - q1
        y (3) := y (3) - q1
        y (4) := y (4) - q2
        y (5) := y (5) - q2
        y (6) := y (6) - q2
        y (7) := y (7) - q3
        y (8) := y (8) - q3
        y (9) := y (9) - q3

        delay (20)

        if y (3) < -250 and y (1) < -100 then
            y (1) := 110
            y (2) := 110
        end if
        if y (3) < -319 then
            y (3) := 45
        end if
        if y (6) < -250 and y (4) < -100 then
            y (4) := 110
            y (5) := 110
        end if
        if y (6) < -319 then
            y (6) := 45
        end if
        if y (9) < -250 and y (7) < -100 then
            y (7) := 110
            y (8) := 110
        end if
        if y (9) < -319 then
            y (9) := 45
        end if
        exit when q1 = 0 and q2 = 0 and q3 = 0
    end loop
    if y (1) <= 10 and y (1) >= 5 and y (4) <= 10 and y (4) >= 5 and y (7) <= 10 and y (7) >= 5 then
        winnings := bet * 4
    elsif y (2) <= -116 and y (2) >= -121 and y (5) <= -116 and y (5) >= -121 and y (8) <= -116 and y (8) >= -121 then
        winnings := bet * 3
    elsif y (3) <= -235 and y (3) >= -240 and y (6) <= -235 and y (6) >= -240 and y (9) <= -235 and y (9) >= -240 then
        winnings := bet * 2
    end if
    balance := balance + winnings
    maxbet := false
    spin := 0
    bet := 0
    balance1 := intstr (balance)
    bet1 := intstr (bet)
    winnings1 := intstr (winnings)
    Pic.Draw (background, 0, 0, picCopy)
    Font.Draw (balance1, 16, 14, font1, 12)
    Font.Draw (bet1, 75, 61, font1, 12)
    Font.Draw (winnings1, 16, 14, font1, 12)
    delay (500)
    View.Update
end loop
Leftover




PostPosted: Sun Oct 31, 2004 11:25 pm   Post subject: (No subject)

I'm no Turing pro, but I believe if you make a variable and put these lines in your loop:

code:

get variable
exit when (variable = "q")


It should exit when the user presses the q key. I'm not sure how to do the other keys, I know the ascii value of the Esc key is 27 but I don't know how to make it take that. Hope this helps.
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: