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

Username:   Password: 
 RegisterRegister   
 crashes after runnig 12 times
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
person




PostPosted: Mon Jan 17, 2005 9:51 pm   Post subject: crashes after runnig 12 times

for some reason this crashes after u run it 12 times.

import GUI
var win := Window.Open ("position:0;0,graphics:1201;720")
var b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, menubutton, exitb, playb, helpb, buttonstartgame, bs : int
var pictureID, pictureID2, pictureID3, pictureID4, picture, picture2, picture3, pictureWidth, pictureHeight, pictureWidth2, pictureHeight2, s1, s2, s3, s4, s5 : int
var money : int := 45
var p1, p2, p3 : string
var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o : int := 0
pictureID3 := Pic.FileNew ("startline.jpg")
pictureID4 := Pic.FileNew ("finishline.jpg")
pictureID := Pic.FileNew ("back.jpg")

% Procedures
% Title of the Game
procedure title
cls
pictureWidth := Pic.Width (pictureID)
pictureHeight := Pic.Height (pictureID)
picture := Pic.Scale (pictureID, pictureWidth * 3, pictureHeight * 2)
Pic.Draw (picture, 0, 0, picCopy)
var font1 : int := Font.New ("Edwardian Script ITC:50")
Draw.Text ("Racing", 515, 650, font1, 44)
end title
% Hides the Horse buttons and the Menu Button
procedure hide
GUI.Hide (b1)
GUI.Hide (b2)
GUI.Hide (b3)
GUI.Hide (b4)
GUI.Hide (b5)
GUI.Hide (b6)
GUI.Hide (b7)
GUI.Hide (b8)
GUI.Hide (b9)
GUI.Hide (b10)
GUI.Hide (b11)
GUI.Hide (b12)
GUI.Hide (b13)
GUI.Hide (b14)
GUI.Hide (b15)
GUI.Hide (menubutton)
end hide


% Introduction
procedure introduction
hide
GUI.Hide (helpb)
GUI.Hide (buttonstartgame)
GUI.Hide (exitb)
title
locate (20, 1)
var font : int := Font.New ("Coronet:56")
Font.Draw ("Welcome to the Exciting World of Horse Racing!!", 50, 500, font, red)
GUI.Show (menubutton)
var picID1, picID2, picID3, picID4, picID5, pic1, pic2, pic4, pic5, picW1, picW2, picW4, picW5, picH1, picH2, picH4, picH5 : int
picID1 := Pic.FileNew ("h1.jpg")
picID2 := Pic.FileNew ("h2.jpg")
picID3 := Pic.FileNew ("h3.jpg")
picID4 := Pic.FileNew ("h4.jpg")
picID5 := Pic.FileNew ("h5.jpg")
picW1 := Pic.Width (picID1)
picH1 := Pic.Height (picID1)
pic1 := Pic.Scale (picID1, picH1 * 4, picW1 * 4)
picW2 := Pic.Width (picID2)
picH2 := Pic.Height (picID2)
pic2 := Pic.Scale (picID2, picH2 div 3, picW2 div 3)
picW4 := Pic.Width (picID4)
picH4 := Pic.Height (picID4)
pic4 := Pic.Scale (picID4, picH4 div 1.5, picW4 div 1.5)
picW5 := Pic.Width (picID5)
picH5 := Pic.Height (picID5)
pic5 := Pic.Scale (picID5, picH5 div 1.5, picW5 div 1.5)

Pic.Draw (pic1, 370, 50, picCopy)
delay (1000)
Pic.Draw (pictureID, 350, 20, picCopy)
Pic.Draw (pic2, 440, 40, picCopy)
delay (1000)
Pic.Draw (pictureID, 440, 20, picCopy)
Pic.Draw (picID3, 545, 100, picCopy)
delay (1000)
Pic.Draw (pictureID, 445, 20, picCopy)
Pic.Draw (pic4, 430, 20, picCopy)
delay (1000)
Pic.Draw (pictureID, 430, 20, picCopy)
Pic.Draw (pic5, 390, 20, picCopy)
delay (1000)
Pic.Draw (pictureID, 390, 20, picCopy)
end introduction
% Returns to the Menu
procedure mainmenu
hide
title
GUI.Show (buttonstartgame)
GUI.Show (helpb)
GUI.Show (exitb)
end mainmenu
process cr
Music.PlayFile ("cr.MP3")
end cr
process horserun
Music.PlayFile ("horserun.wav")
end horserun
procedure secondMenu
GUI.Show (b1)
GUI.Show (b2)
GUI.Show (b3)
GUI.Show (b4)
GUI.Show (b5)
GUI.Show (b6)
GUI.Show (b7)
GUI.Show (b8)
GUI.Show (b9)
GUI.Show (b10)
GUI.Show (b11)
GUI.Show (b12)
GUI.Show (b13)
GUI.Show (b14)
GUI.Show (b15)
GUI.Show (bs)
GUI.Show (menubutton)
end secondMenu
% Helps User Understand
procedure help
cls
title
locate (20, 1)
var font : int := Font.New ("Mistral:20")
Font.Draw ("The objective of the game is to maximize your number of coins. You begin with 45 coins, and you will have the option of", 100, 400, font, red)
Font.Draw ("betting on any of the 5 horses. You can choose to bet on who will be first, second, or third with their odds written beside the horse", 5, 350, font, red)
Font.Draw ("number. To bet on a horse, just click the horse number. Havefun, and the best of luck to you!", 5, 300, font, red)
GUI.Show (menubutton)
end help
% Decides Which Horse Wins and Shows it
procedure display
var pa, pb, pc, pd, pe : int := 1050
var s6, s7, s8, s9, s10 : int
pictureID2 := Pic.FileNew ("horse.jpg")
pictureWidth2 := Pic.Width (pictureID2)
pictureHeight2 := Pic.Height (pictureID2)
picture2 := Pic.Scale (pictureID2, pictureWidth2 div 6, pictureHeight2 div 6)
pictureWidth := Pic.Width (pictureID)
pictureHeight := Pic.Height (pictureID)
picture := Pic.Scale (pictureID, pictureWidth div 0.6, pictureHeight div 1.2)
s1 := Rand.Int (1, 12)
s2 := Rand.Int (1, 8)
s3 := Rand.Int (1, 5)
s4 := Rand.Int (1, 3)
s5 := Rand.Int (1, 2)
fork horserun
fork cr
loop
s6 := Rand.Int (1, 20)
s7 := Rand.Int (1, 20)
s8 := Rand.Int (1, 20)
s9 := Rand.Int (1, 20)
s10 := Rand.Int (1, 20)
pa := pa - s1 - s6
pb := pb - s2 - s7
pc := pc - s3 - s8
pd := pd - s4 - s9
pe := pe - s5 - s10
Pic.Draw (picture, 105, 200, picCopy)
Pic.Draw (pictureID3, 1035, 200, picCopy)
Pic.Draw (pictureID4, 0, 200, picCopy)
Pic.Draw (picture2, pa, 520, picCopy)
Pic.Draw (picture2, pb, 440, picCopy)
Pic.Draw (picture2, pc, 360, picCopy)
Pic.Draw (picture2, pd, 280, picCopy)
Pic.Draw (picture2, pe, 200, picCopy)
delay (50)
if pa <= 100 and pb > pa and pc > pa and pd > pa and pe > pa then
p1 := "Horse 1 is the Winner!"
elsif pb <= 100 and pa > pb and pc > pb and pd > pb and pe > pb then
p1 := "Horse 2 is the Winner!"
elsif pc <= 100 and pb > pc and pa > pc and pd > pc and pe > pc then
p1 := "Horse 3 is the Winner!"
elsif pd <= 100 and pb > pd and pc > pd and pa > pd and pe > pd then
p1 := "Horse 4 is the Winner!"
elsif pe <= 100 and pb > pe and pc > pe and pd > pe and pa > pe then
p1 := "Horse 5 is the Winner!"
end if
if pa <= 100 and p1 not= "Horse 1 is the Winner!" and (pb < pa or pc < pa or pd < pa or pe < pa) and ((pb > 100 and pc > 100 and pd > 100 and pe < pa) or (pb > 100 and pc > 100 and pe > 100
and pd < pa) or (pd > 100 and pc > 100 and pe > 100 and pb < pa) or (pb > 100 and pe > 100 and pd > 100 and pc < pa)) then
p2 := "Horse 1 is Second"
elsif pb <= 100 and p1 not= "Horse 2 is the Winner!" and (pa < pb or pc < pb or pd < pb or pe < pb) and ((pa > 100 and pc > 100 and pd > 100 and pb > pe) or (pa > 100 and pc > 100 and pe >
100 and pb > pd) or (pd > 100 and pc > 100 and pe > 100 and pb > pa) or (pa > 100 and pe > 100 and pd > 100 and pb > pc)) then
p2 := "Horse 2 is Second"
elsif pc <= 100 and p1 not= "Horse 3 is the Winner!" and (pb < pc or pa < pc or pd < pc or pe < pc) and ((pb > 100 and pa > 100 and pd > 100 and pc > pe) or (pb > 100 and pa > 100 and pe >
100 and pc
> pd) or (pd > 100 and pa > 100 and pe > 100 and pc > pb) or (pb > 100 and pe > 100 and pd > 100 and pc > pa)) then
p2 := "Horse 3 is Second"
elsif pd <= 100 and p1 not= "Horse 4 is the Winner!" and (pb < pd or pc < pd or pa < pd or pe < pd) and ((pb > 100 and pc > 100 and pa > 100 and pd > pe) or (pb > 100 and pc > 100 and pe >
100 and pd
> pa) or (pa > 100 and pc > 100 and pe > 100 and pd > pb) or (pb > 100 and pe > 100 and pa > 100 and pd > pc)) then
p2 := "Horse 4 is Second"
elsif pe <= 100 and p1 not= "Horse 5 is the Winner!" and (pb < pe or pc < pe or pd < pe or pa < pe) and ((pb > 100 and pc > 100 and pd > 100 and pe > pa) or (pb > 100 and pc > 100 and pa >
100 and pe
> pd) or (pd > 100 and pc > 100 and pa > 100 and pe > pb) or (pb > 100 and pa > 100 and pd > 100 and pe > pc)) then
p2 := "Horse 5 is Second"
end if
if pa <= 100 and p1 not= "Horse 1 is the Winner!" and p2 not= "Horse 1 is Second" and ((pe > pa and pb > pa) or (pe > pa and pc > pa) or (pe > pa and pd > pa) or (pb > pa and pc > pa) or (pb
> pa
and pd > pa) or (pc > pa and pd > pa)) then
p3 := "Horse 1 is Third"
exit
elsif pb <= 100 and p1 not= "Horse 2 is the Winner!" and p2 not= "Horse 2 is Second" and ((pe > pb and pa > pb) or (pe > pb and pc > pb) or (pe > pb and pd > pb) or (pa > pb and pc > pb)
or (pa > pb
and pd > pb) or (pc > pb and pd > pb)) then
p3 := "Horse 2 is Third"
exit
elsif pc <= 100 and p1 not= "Horse 3 is the Winner!" and p2 not= "Horse 3 is Second" and ((pe > pc and pa > pc) or (pe > pc and pb > pc) or (pe > pc and pd > pc) or (pa > pc and pb > pc)
or (pa > pc
and pd > pc) or (pb > pc and pd > pc)) then
p3 := "Horse 3 is Third"
exit
elsif pd <= 100 and p1 not= "Horse 4 is the Winner!" and p2 not= "Horse 4 is Second" and ((pe > pd and pa > pd) or (pe > pd and pb > pd) or (pe > pd and pc > pd) or (pa > pd and pb > pd)
or (pa > pd
and pd > pc) or (pb > pd and pd > pc)) then
p3 := "Horse 4 is Third"
exit
elsif pe <= 100 and p1 not= "Horse 5 is the Winner!" and p2 not= "Horse 5 is Second" and ((pd > pe and pa > pe) or (pd > pe and pb > pe) or (pd > pe and pd > pe) or (pa > pe and pb > pe)
or (pa > pe
and pd > pe) or (pb > pe and pd > pe)) then
p3 := "Horse 5 is Third"
exit
end if
end loop
var font : int := Font.New ("Blackadder ITC:36")
Font.Draw (p1, 300, 500, font, red)
Font.Draw (p2, 300, 400, font, red)
Font.Draw (p3, 300, 300, font, red)
delay (8000)
title
Pic.Draw (pictureID3, 1050, 200, picCopy)
Pic.Draw (pictureID4, 0, 200, picCopy)
end display
procedure mon
locate (38, 101)
put "Number of Coins Remaining: ", money
end mon
procedure bets
colourback (2)
locate (36, 1)
put "1:1 - ", a
locate (38, 1)
put "2:1 - ", b
locate (40, 1)
put "4:1 - ", c
locate (42, 1)
put "10:1 - ", d
locate (44, 1)
put "16:1 - ", e
locate (36, 31)
put "2:1 - ", f
locate (38, 31)
put "1:1 - ", g
locate (40, 31)
put "2:1 - ", h
locate (42, 31)
put "4:1 - ", i
locate (44, 31)
put "6:1 - ", j
locate (36, 61)
put "4:1 - ", k
locate (38, 61)
put "2:1 - ", l
locate (40, 61)
put "1:1 - ", m
locate (42, 61)
put "2:1 - ", n
locate (44, 61)
put "4:1 - ", o
for x : 1 .. 10
drawline (220 + x, 0, 220 + x, 190, 44)
drawline (460 + x, 0, 460 + x, 190, 44)
drawline (700 + x, 0, 700 + x, 190, 44)
drawline (0, 190 + x, 710, 190 + x, 44)
drawbox (790 - x, 112 - x, 1150, 127 + x, 44)
end for
var font : int := Font.New ("Serif:18")
Font.Draw ("First Place Racers", 23, 170, font, red)
Font.Draw ("Second Place Racers", 245, 170, font, red)
Font.Draw ("Third Place Racers", 490, 170, font, red)
end bets
procedure nill
a := 0
b := 0
c := 0
d := 0
e := 0
f := 0
g := 0
h := 0
i := 0
j := 0
k := 0
l := 0
m := 0
n := 0
o := 0
end nill
procedure processing
if a > 0 and p1 = "Horse 1 is the Winner!" then
money := money + a * 2
end if
if b > 0 and p1 = "Horse 2 is the Winner!" then
money := money + b * 3
end if
if c > 0 and p1 = "Horse 3 is the Winner!" then
money := money + c * 5
end if
if d > 0 and p1 = "Horse 4 is the Winner!" then
money := money + d * 11
end if
if e > 0 and p1 = "Horse 5 is the Winner!" then
money := money + e * 17
end if
if f > 0 and p2 = "Horse 1 is Second" then
money := money + f * 3
end if
if g > 0 and p2 = "Horse 2 is Second" then
money := money + g * 2
end if
if h > 0 and p2 = "Horse 3 is Second" then
money := money + h * 3
end if
if i > 0 and p2 = "Horse 4 is Second" then
money := money + i * 5
end if
if j > 0 and p2 = "Horse 5 is Second" then
money := money + j * 13
end if
if k > 0 and p3 = "Horse 1 is Third" then
money := money + k * 5
end if
if l > 0 and p3 = "Horse 2 is Third" then
money := money + l * 3
end if
if m > 0 and p3 = "Horse 3 is Third" then
money := money + m * 2
end if
if n > 0 and p3 = "Horse 4 is Third" then
money := money + n * 3
end if
if o > 0 and p3 = "Horse 5 is Third" then
money := money + o * 5
end if
nill
bets
mon
secondMenu
end processing
procedure race
display
processing
end race
procedure userInput
if GUI.GetEventWidgetID = b1 then
a := a + 1
elsif GUI.GetEventWidgetID = b2 then
b := b + 1
elsif GUI.GetEventWidgetID = b3 then
c := c + 1
elsif GUI.GetEventWidgetID = b4 then
d := d + 1
elsif GUI.GetEventWidgetID = b5 then
e := e + 1
elsif GUI.GetEventWidgetID = b6 then
f := f + 1
elsif GUI.GetEventWidgetID = b7 then
g := g + 1
elsif GUI.GetEventWidgetID = b8 then
h := h + 1
elsif GUI.GetEventWidgetID = b9 then
i := i + 1
elsif GUI.GetEventWidgetID = b10 then
j := j + 1
elsif GUI.GetEventWidgetID = b11 then
k := k + 1
elsif GUI.GetEventWidgetID = b12 then
l := l + 1
elsif GUI.GetEventWidgetID = b13 then
m := m + 1
elsif GUI.GetEventWidgetID = b14 then
n := n + 1
elsif GUI.GetEventWidgetID = b15 then
o := o + 1
end if
bets
secondMenu
if GUI.GetEventWidgetID = b1 or GUI.GetEventWidgetID = b2 or GUI.GetEventWidgetID = b3 or GUI.GetEventWidgetID = b4 or GUI.GetEventWidgetID = b5 or GUI.GetEventWidgetID = b6 or
GUI.GetEventWidgetID = b7 or GUI.GetEventWidgetID = b8 or GUI.GetEventWidgetID = b9 or GUI.GetEventWidgetID = b10 or GUI.GetEventWidgetID = b11 or GUI.GetEventWidgetID = b12 or
GUI.GetEventWidgetID = b13 or GUI.GetEventWidgetID = b14 or GUI.GetEventWidgetID = b15 then
money := money - 1
end if
if money <= 0 then
race
if money <= 0 then
for x : 1 .. 675
put "You Lose! " ..
end for
delay (10000)
mainmenu
money := 45
nill
end if
else
mon
end if
end userInput
procedure game
GUI.Hide (helpb)
GUI.Hide (buttonstartgame)
GUI.Hide (exitb)
title
Pic.Draw (pictureID3, 1035, 200, picCopy)
Pic.Draw (pictureID4, 0, 200, picCopy)
userInput
end game
procedure goodBye
for x : 1 .. 181
put "This program was created by Xiao Hao. " ..
end for
delay (5000)
quit
Window.Close (win)
end goodBye
b1 := GUI.CreateButtonFull (140, 140, 0, "Horse #1", userInput, 0, '^S', false)
b2 := GUI.CreateButtonFull (140, 109, 0, "Horse #2", userInput, 0, '^S', false)
b3 := GUI.CreateButtonFull (140, 77, 0, "Horse #3", userInput, 0, '^S', false)
b4 := GUI.CreateButtonFull (140, 45, 0, "Horse #4", userInput, 0, '^S', false)
b5 := GUI.CreateButtonFull (140, 12, 0, "Horse #5", userInput, 0, '^S', false)
b6 := GUI.CreateButtonFull (380, 140, 0, "Horse #1", userInput, 0, '^S', false)
b7 := GUI.CreateButtonFull (380, 109, 0, "Horse #2", userInput, 0, '^S', false)
b8 := GUI.CreateButtonFull (380, 77, 0, "Horse #3", userInput, 0, '^S', false)
b9 := GUI.CreateButtonFull (380, 45, 0, "Horse #4", userInput, 0, '^S', false)
b10 := GUI.CreateButtonFull (380, 12, 0, "Horse #5", userInput, 0, '^S', false)
b11 := GUI.CreateButtonFull (620, 140, 0, "Horse #1", userInput, 0, '^S', false)
b12 := GUI.CreateButtonFull (620, 109, 0, "Horse #2", userInput, 0, '^S', false)
b13 := GUI.CreateButtonFull (620, 77, 0, "Horse #3", userInput, 0, '^S', false)
b14 := GUI.CreateButtonFull (620, 45, 0, "Horse #4", userInput, 0, '^S', false)
b15 := GUI.CreateButtonFull (620, 12, 0, "Horse #5", userInput, 0, '^S', false)
bs := GUI.CreateButtonFull (820, 12, 200, "Start Race!!", race, 0, '^S', false)
menubutton := GUI.CreateButtonFull (1100, 160, 0, "Menu", mainmenu, 0, '^S', false)
helpb := GUI.CreateButtonFull (250, 320, 700, "Help", help, 50, '^S', false)
buttonstartgame := GUI.CreateButtonFull (250, 420, 700, "Start Game", game, 100, '^S', false)
exitb := GUI.CreateButtonFull (250, 250, 700, "Quit Game", GUI.Quit, 0, '^S', false)

% Main Program
title
introduction
loop
exit when GUI.ProcessEvent
end loop
goodBye
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: