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

Username:   Password: 
 RegisterRegister   
 Numbers Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: Wed Jan 11, 2006 9:18 pm   Post subject: Numbers Game

heres a simple number guessing game with some bells and whistles please let me know how it is
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Jan 12, 2006 9:15 am   Post subject: (No subject)

I'm glad to see that you're attempting to use procedures, they really are rather powerful creatures. However, right now it's sort of like you're using the NASA Mainframe to type up your grocery list.

We'll start with your 'easy', 'hard' etc. procedures. They're all the same, except for a few changes in variable values. So, would it be unreasonable to combine them all into one procedure, but with those said values assignable by paramters? Of course it would.
I highly recommend The Turing Walkthrough for a list of very relevant tuts. Look up the ones on procedures.

So, basically we'll be doing something to the effect of:
Turing:

% Instead of:
procedure one
   var num : int := 1
   put num
end one
procedure two
   var num : int := 2
   put num
end two
procedure three
   var num : int := 3
   put num
end three

% We'll create one proc that has a single parameter:
procedure nums (numberParameter : int)
   put numberParameter
end nums

% Now, instead of calling:
one
two
three

% We can just call
nums (1)
nums (2)
nums (3)
% Or even
for i : 1..5
   nums (i)
end for


This is all fine and good so far. And you can extrapolate these examples into your own and touch up your proggie. However, we can still enhance these particular ones to make them even more versitile. We'll convert them into functions instead. The usefulness here is that they can be incorporated into a wide variety of other constructs.

Turing:

function nums (numPara : int) : int
   result numPara
end nums

put nums (1)
put "Your number is ", nums (2)
% etc.  So much more than before...


Ok, next point. You need to edit your programme so that it exits! Right now, once one finishes it (win or lose) you get stuck in an infinite loop that does nothing. Never good.
I'll suggest you look through your code, and perhaps remove the GUI for now. GUI just complicates matters more than it helps them, especially Turing's. You're missing a few exit conditions - but this will become a lot clearer once you streamline your code with the dynamic procedures.
Clayton




PostPosted: Thu Jan 12, 2006 4:58 pm   Post subject: (No subject)

i made that infinite loop for a purpose until i could properly finish the end game procedure. i have all of those procs because GUI needs to search for the procedure to go to, hence the procedures.
Delos




PostPosted: Thu Jan 12, 2006 8:45 pm   Post subject: (No subject)

SuperFreak82 wrote:
i made that infinite loop for a purpose until i could properly finish the end game procedure.


Yes, I know that. However, your game does not exit at its conclusion. This defeats the purpose of having such an exit condition. As I said, it's possible, I've already modified your code to do so - now you need to figure that out as well.
Infinite loops are bad. They make computers sick - and you don't want a sick computer on your hands.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: