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

Username:   Password: 
 RegisterRegister   
 Help with simplifying code.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jainarihant




PostPosted: Wed May 14, 2003 7:05 pm   Post subject: Help with simplifying code.

Quote:
import GUI in "gui"
% variables
var windowID : int := Window.Open ("graphics:345;200, title:Lucky Seven")
var fontID : int := Font.New ("Verdana:40")
var gameEnd : boolean := false
var total : int := 100


randomize

% sets bgcolor to grey
colorback (28)
cls

% prints total money amount on title bar
colorback (25)
locate (2, 2)
put "Winnings : $", total
% prints lucky seven on bottom of screen
Font.Draw ("Lucky Seven", 1, 1, fontID, black)


% draws and clears number windows
procedure numberWindows (fillColor : int)
var boxx : int := 120
for i : 1 .. 3
Draw.Box (boxx, 90, boxx + 50, 170, black)
Draw.Fill (boxx + 10, 100, fillColor, black)
boxx := boxx + 60
end for
end numberWindows

% when 'Spin' button is pressed
procedure Spin
% 3 random numbers
var number : array 1 .. 3 of int
% font x value of numbers
var fx : int := 130
% calls setup procedure to clear number windows
numberWindows (31)
% chooses 3 random numbers and displays them in number windows
for i : 1 .. 3
randint (number (i), 0, 9)
Font.Draw (intstr (number (i)), fx, 95, fontID, 18)
fx += 60
end for
if number (1) = 7 and number (2) = 7 and number (3) = 7 then
% if user gets 3 sevens
% adds 100 bucks to total winnings
total := total + 100
locate (2, 2)
put " "
locate (2, 2)
put "Winnings : $", total
sound (900, 300)
% flashes the lucky seven logo
for i : 1 .. 10
Font.Draw ("Lucky Seven", 1, 1, fontID, 14)
delay (100)
Font.Draw ("Lucky Seven", 1, 1, fontID, 3)
delay (100)
end for
Font.Draw ("Lucky Seven", 1, 1, fontID, 7)
elsif number (1) = 7 or number (2) = 7 or number (3) = 7 then
% if user gets one seven
% adds 10 bucks to total
total := total + 10
locate (2, 2)
put " "
locate (2, 2)
put "Winnings : $", total
sound (700, 200)
else
% no sevens, loses 10 bucks
total := total - 10
locate (2, 2)
put " "
locate (2, 2)
put "Winnings : $", total
end if
end Spin

% when 'Exit' button is pressed
procedure Exit
gameEnd := true
end Exit


numberWindows (31)

% draws buttons
var buttonSpin : int := GUI.CreateButton (40, 140, 0, "Spin", Spin)
var buttonExit : int := GUI.CreateButton (40, 90, 0, "Exit", Exit)

loop
exit when gameEnd = true
exit when GUI.ProcessEvent
end loop

% closes window
Window.Close (windowID)





Could i make this program any simpler , or cut down on length ! .. Thank you .. !

MOD EDIT: Topic has been changed. Do not make general topics. Read our topic policy at the top of the forum. -Asok
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Wed May 14, 2003 7:08 pm   Post subject: (No subject)

taking out the comments will cut down the length Laughing
jainarihant




PostPosted: Wed May 14, 2003 7:13 pm   Post subject: (No subject)

Yea , I know hehe , but i need that cuz the teacher want them !!
Tony




PostPosted: Thu May 15, 2003 9:27 am   Post subject: (No subject)

so just keep everything... why shorten the program?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




PostPosted: Mon May 19, 2003 6:17 pm   Post subject: (No subject)

or you can just declare a couple of variables at the same time that'll save you 5 or six lines
nate




PostPosted: Mon May 19, 2003 6:48 pm   Post subject: virtical spaces

well for some of the program u could get rid of some of the virtical spacing. Other than what every1 else has already said i think thats it!

-Nate
Catalyst




PostPosted: Mon May 19, 2003 7:12 pm   Post subject: (No subject)

u use
code:

locate (2,2)

alot

u might want to do somethin like this
code:

proc loc22 (s:string)
locate (2,2)
put s
end loc22
tum_twish




PostPosted: Tue May 20, 2003 7:43 pm   Post subject: (No subject)

u could put the Font.Draws in one procedure, so u dont call'em manytimes
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  [ 8 Posts ]
Jump to:   


Style:  
Search: