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

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




PostPosted: Mon Dec 11, 2006 11:02 am   Post subject: turing loop

hey guys! im doing a project for my grade 10 comp science course ...currently im working on a slot machine program and im having trouble looping my project so you can specify if you want to roll again or go back to the menu...

i was wondering if someone could help me do this...

heres my project so far (not all of it b/c some people may copy Wink )



code:


setscreen ("graphics")
setscreen ("graphics:vga")

var fontID : int := Font.New ("Algerian:14")
var key : string (1)
var coins : real
var random, random2, random3 : int
var wager : real
var ans : string

put "Hello, how much money will you be taking with you to the slot machine?"
put "$" ..
get coins

setscreen ("nocursor")

colorback (149)
cls
Font.Draw ("The", 37, 370, fontID, 16)
Font.Draw ("Honeycomb", 1, 350, fontID, 16)
Font.Draw ("Casino", 25, 330, fontID, 16)

%slot machine layout
drawfillbox (100, 0, 530, 100, 43) %bottom light orange box
drawbox (120, 20, 510, 80, 16) %bottom inside outline box
drawfillbox (120, 120, 510, 160, 43) %middle orange box
drawbox (130, 130, 500, 150, 16) %middle inside outline box
drawfillbox (97, 160, 533, 179, 14) %top trapezoid box
drawfillbox (97, 173, 105, 180, 149) %blue box cover yellow
drawfillbox (97, 165, 100, 180, 149) %blue box cover yellow
drawfillbox (97, 175, 107, 180, 149) %blue box cover yellow
drawfillbox (97, 168, 102, 180, 149) %blue box cover yellow
drawfillbox (525, 171, 533, 180, 149) %blue box cover yellow
drawfillbox (529, 166, 533, 180, 149) %blue box cover yellow
drawfillbox (523, 173, 533, 180, 149) %blue box cover yellow
drawfillbox (530, 165, 533, 180, 149) %blue box cover yellow
drawfillbox (103, 101, 528, 119, 14) %bottom trapezoid box
drawfillbox (100, 109, 110, 120, 149) %bottom blue box cover yellow
drawfillbox (100, 112, 113, 120, 149) %bottom blue box cover yellow
drawfillbox (100, 115, 115, 120, 149) %bottom blue box cover yellow
drawfillbox (100, 117, 117, 120, 149) %bottom blue box cover yellow
drawfillbox (100, 117, 118, 120, 149) %bottom blue box cover yellow
drawfillbox (100, 105, 106, 120, 149) %bottom blue box cover yellow
drawfillbox (526, 104, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (524, 106, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (522, 108, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (520, 110, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (517, 112, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (515, 114, 533, 120, 149) %bottom blue box cover yellow
drawfillbox (513, 116, 533, 120, 149) %bottom blue box cover yellow
drawbox (100, 0, 530, 100, 16) %outline bottom box
drawline (100, 100, 120, 120, 16) %bottom left angle
drawline (530, 100, 510, 120, 16) %bottom right angle
drawbox (120, 120, 510, 160, 16) %outline middle box
drawline (95, 160, 535, 160, 16) %top trapezoid bottom line
drawline (95, 160, 110, 180, 16) %top left angle
drawline (535, 160, 520, 180, 16) %top right angle
drawfillbox (110, 180, 520, 395, 43) %orange main box
drawbox (110, 180, 520, 395, 16) %outline main box

drawfillbox (135, 230, 245, 330, 0) %white box #1
drawfillbox (260, 230, 370, 330, 0) %white box #2
drawfillbox (385, 230, 495, 330, 0) %white box #3
drawbox (135, 230, 245, 330, 16) %white box outline #1
drawbox (260, 230, 370, 330, 16) %white box outline #2
drawbox (385, 230, 495, 330, 16) %white box outline #3


colorback (43)
color (16)
locate (22, 45)
put "Money Left: $" ..
locate (22, 58)
put coins ..

locate (23, 45)
put "Wager:      $" ..
get wager
delay (2000)
randint (random, 0, 10)
randint (random2, 0, 10)
randint (random3, 0, 10)

colorback (0)

locate (8, 24)
delay (500)
put random ..
locate (8, 40)
delay (500)
put random2 ..
locate (8, 56)
delay (1000)
put random3 ..

colorback (43)

if random = random2 and %1st # = 2nd # (ex. for a "1 1 1" combo)
        random = random3 and %1st # = 3rd # (ex. for a "1 1 1" combo)
        random2 = random3 then %2nd # = 3rd # (ex. for a "1 1 1" combo)
    locate (22, 58)
    put "      " ..
    delay (500)
    locate (22, 58)   %locate command for the ending coins
    put wager * 5 + coins .. %output for the amount of coins recieved in the end
elsif random = random2 + 1 and %1st # = 2nd # + 1 (ex. for a "1 2 3" combo)
        random = random3 + 2 and %1st # = 3rd # + 2 (ex. for a "1 2 3" combo)
        random2 = random3 + 1 then %2nd # = 3rd # + 1 (ex. for a "1 2 3" combo)
    locate (22, 58)
    put "      " ..
    delay (500)
    locate (22, 58)   %locate command for the ending coins
    put wager * 3 + coins .. %output for the amount of coins recieved in the end
elsif random = random2 - 1 and %1st # = 2nd # - 1 (ex. for a "3 2 1" combo)
        random = random3 - 2 and %1st # = 3rd # - 2 (ex. for a "3 2 1" combo)
        random2 = random3 - 1 then %2nd # = 3rd # - 1 (ex. for a "3 2 1" combo)
    locate (22, 58)
    put "      " ..
    delay (500)
    locate (22, 58)   %locate command for the ending coins
    put wager * 3 + coins .. %output for the amount of coins recieved in the end
elsif random = random3 then %1st # = 3rd # (ex. for a "1 2 1" combo)
    locate (22, 58)
    put "      " ..
    delay (500)
    locate (22, 58) %locate command for the ending coins
    put wager * 2 + coins .. %output for the amount of coins recieved in the end
else %for no winning combination
    locate (22, 58)
    put "      " ..
    delay (500)
    locate (22, 58) %locate command for the ending coins
    put coins - wager .. %output for the amount of coins subtracted in the end
end if

colorback (149)

locate (6, 2)
put "Please press" ..
locate (7, 5)
put "enter." ..
getch (key)

setscreen ("cursor")

colorback (149)

locate (6, 2)
put "            " ..
locate (7, 5)
put "      " ..
delay (1000)

locate (6, 3)
put "Would you" ..
locate (7, 2)
put "like to play" ..
locate (8, 2)
put "again? (y/n)" ..
locate (9, 1)
get ans

Sponsor
Sponsor
Sponsor
sponsor
justin_ba




PostPosted: Mon Dec 11, 2006 11:05 am   Post subject: srry :S

srry guys u may have to fiz the programmers comments on some of them...apparently i didnt have enough space to fit them in
NikG




PostPosted: Mon Dec 11, 2006 11:12 am   Post subject: (No subject)

Loops are pretty simple. All you have to do is put the code you want to repeat in the loop tags.

Take a look at the Turing Walkthrough for more info.
I also suggest looking into functions & procedures.
wtd




PostPosted: Mon Dec 11, 2006 11:58 am   Post subject: (No subject)

Look for patterns in your code. Do numbers repeatedly change in a predictable fashion?
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: