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

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




PostPosted: Wed Dec 20, 2006 7:26 pm   Post subject: Slot Machine

Hey, i gotta make a slot machine game, any ideas on what i should do, and, are you able to put pictures in if statements. Ex if "(picture of 7) then coins:= +20 or sumthing, also are you able to make pictures go randomly for the slot part. Im fairly new at turing and any help will be appreciated. Thx
Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Wed Dec 20, 2006 7:55 pm   Post subject: (No subject)

Here's a small Turing program I made, look at the comments and try to understand it:
code:

var x : int := 10 %x position of fruits
var cnt : int := 0 %Counter
var slots : int %used as a junk variable to keep a random number
var stops : array 1 .. 3 of int %Three variables to keep track of what you landed on
var key : array char of boolean

loop
    Input.KeyDown (key)
    randint (slots, 1, 3) %makes slots a random number from 1 to 3
    if key (KEY_ENTER) then
        if slots = 1 then
            Draw.FillOval (x, 10, 10, 10, yellow) %represents a lemon
        elsif slots = 2 then
            Draw.FillOval (x, 10, 10, 10, red) %cherry
        elsif slots = 3 then
            Draw.FillOval (x, 10, 10, 10, blue) %blueberry
        end if
        x += 20 %pushes the oval over
        cnt += 1
        stops (cnt) := slots %stores the random number into a variable
        delay (250)
        put "Random Number: ", slots
    end if
    if cnt = 3 then
        Input.Pause
        if stops (1) = 1 and stops (2) = 1 and stops (3) = 1 then %checks if all 3 random numbers are 1
            put "LEMONS WON!!!!"
        elsif stops (1) = 2 and stops (2) = 2 and stops (3) = 2 then %checks if all 3 random numbers are 2
            put "CHERRY WON!!!"
        elsif stops (1) = 1 and stops (2) = 3 and stops (3) = 3 then %checks if all 3 random numbers are 3
            put "BLUEBERRY WON!!!"
        end if
        Input.Pause
        x := 10 %resets the x position
        cnt := 0 %resets the counter
        cls
    end if
end loop


For the importing of a picture look here.
TokenHerbz




PostPosted: Wed Dec 20, 2006 8:03 pm   Post subject: (No subject)

i gotta make a slot machine game... So its for school yes?

You learn nothing from copy paste code, so i suggest you ignor prince pwn code.

Firstly, You can randomizse pictures, and use if's with them.

Secondly, i'd suggest you look threw turing walkthrew

http://www.compsci.ca/v2/viewtopic.php?t=8808
Steel




PostPosted: Wed Dec 20, 2006 8:12 pm   Post subject: (No subject)

Thankz Smile
Prince Pwn




PostPosted: Wed Dec 20, 2006 8:19 pm   Post subject: (No subject)

TokenHerbz wrote:

You learn nothing from copy paste code, so i suggest you ignor prince pwn code.


i learned by copy and pasting code.
Steel




PostPosted: Wed Dec 20, 2006 8:26 pm   Post subject: (No subject)

hmm what does the dot mean in like

draw.Fill oval

because i know you could also just do drawfilloval.
Prince Pwn




PostPosted: Wed Dec 20, 2006 8:38 pm   Post subject: (No subject)

No major difference. If you navigate your hard drive to your Turing installation folder, "Turing/Support/predefs/" you will find a few Turing files that are all noticeable such as "Dir", "Draw", and "Pic" that are all .tu files.

When you use Draw.FillOval, it opens the "Turing/Support/predefs/" and looks inside the Draw.tu file and further executes the code inside that Draw.tu according to what you put inside your ().

Saying drawfilloval has the same result, but doesn't look for "Turing/Support/predefs/".
ericfourfour




PostPosted: Wed Dec 20, 2006 9:55 pm   Post subject: (No subject)

Actually Draw. means it is a member of the Draw module. It is loaded on the memory at run time so there is no searching through folders involved. It takes the same speed for each. Draw. is recommended because it is easier to understand and helps you out later on.
Sponsor
Sponsor
Sponsor
sponsor
Hackmaster




PostPosted: Wed Dec 20, 2006 10:23 pm   Post subject: (No subject)

your problems are really easy to solve, and they can probably be done with the help of the Turing Walkthrough, or some other tutorial based on it. but whatever. I'll give you a hand.

because you are fairly basic, I will keep it simple.


for the random part, all you need to do is make a simple randint statement:

code:


randint (var, 1, 10)



if you've never seen this before, I will tell you what it's about:

randint is the command to start it all. "var" is the variable you will be giving the random integer to. 1 and 10 are the limits of the randomization, so, if I put 1, 10, it means I will have a random number from 1-10. easy-peasy, right?

then, all you do is have an if statement (or case, whatever you prefer) which puts a certain picture up on the screen depending on what number was rolled, something like this, maybe :

code:


if var = 1 then

      DrawPic ( "lucky_7.jpg" , 100, 100, 2)

elsif var = 2 then

      DrawPic ( "cherries.jpg", 100, 100, 2)

% Add more if statements pertaining to displaying pics depending on roll.

end if



something like that. alright? hope this helped!
ericfourfour




PostPosted: Wed Dec 20, 2006 10:53 pm   Post subject: (No subject)

Hackmaster wrote:
for the random part, all you need to do is make a simple randint statement:
code:
randint (var, 1, 10)

Simple but deadly. Don't use randint. It teaches bad programming practise. Instead use the function (not procedure) Rand.Int.

code:
var num := Rand.Int (1, 10)

code:
put Rand.Int (1, 10)
Hackmaster




PostPosted: Wed Dec 20, 2006 10:57 pm   Post subject: (No subject)

finickty, finicktey.. jeez...

really, it doesn't matter. use what you like. what is the differece between one command and putting a dot there?

well, it may teach you about module refrence, but you adapt to that as time goes on. I said this way because he is new, and thus doesn't (in my opinion) need to care about little details like this for now.
ericfourfour




PostPosted: Wed Dec 20, 2006 11:03 pm   Post subject: (No subject)

There is more of a difference between Rand.Int and randint than a dot.

Rand.Int is a function returning an integer.

randint is a procedure that takes in a variable (the exact location) and assigns the value to it internally.

Which one do you have more control over?

This has been discussed countless times and the dot is hardly the issue between the two.
Clayton




PostPosted: Wed Dec 20, 2006 11:06 pm   Post subject: (No subject)

The difference between Rand.Int and randint is a lot more than just a dot. Rand.Int is a function, it creates a value, it in no way modifys the program around it unless you specifically tell it to. randint on the other hand is a procedure, a procedure that takes a variable argument and mercilessly changes its value within the procedure. This is generally regarded as bad programming practice and should be avoided at all costs, as you have no idea what's happening to your precious varible within that procedure.
Hackmaster




PostPosted: Wed Dec 20, 2006 11:12 pm   Post subject: (No subject)

I understand that guys... but it isn't really me you are appealing to.

the only reason I said to do randint is because that's what they teach in the schools. (in my experience.)

I'm just trying to make it simpler... but on second thought... when typing, there isn't much of a difference between randint and Rand.Int.

Fine! that's fine... you win... Embarassed
Steel




PostPosted: Thu Dec 21, 2006 4:00 pm   Post subject: (No subject)

Thanks guys Smile your help is greatly appreciated. When the program is done ill try to post it here, and i think you are both right lol, all i gotta do now is learn how to put the pics in, but i could prob find that in tutorial thx again
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  [ 15 Posts ]
Jump to:   


Style:  
Search: