next up previous contents
Next: Second Iteration Up: First Iteration Previous: First Iteration

SUBS

The simplest way to begin designing SUBS is to describe the purpose of each function/SUB with no code.

SUB InitializeDeck
'Initialize cards to their values.
'
END SUB

The next routine is perhaps not easy to write for a beginner, but we have a good example in the book.

SUB ShuffleDeck
'Make a random permutation
'Store it in shared array Order()
'Order(1), Order(2) are distinct random numbers range 1,...n,
END SUB

The next routine interacts with the user. User interaction should ALWAYS be implemented as a separate SUB. As straightforward as it seems, reliable coding requires extensive checking for errors resulting from unpredicted user reactions.

'ask first player
FUNCTION HowManyCards
' Ask user how many cards (s)he requests
' store in variable.
' Check for possible errors in input
' return value if enough cards are left.
END FUNCTION

The following routine is in charge of giving out cards. Since the order of cards was already determined, it seems straightforward. But again complications arise, and this portion will be much easier to handle if coded as a separate SUB

SUB DealCards(n)
' Remember how many cards are left
' Check how many cards are left
' Print out Error message if not enough cards
'Print next n cards
' You have to decide here HOW the cards will appear on screen:
'words? pictures? numbers?
' (In this example, it will be numbers)
END SUB


Send comment