next up previous contents
Next: SUBS Up: Example: designing an automatic Previous: Example: designing an automatic

First Iteration

   Once we realize what are the natural steps the real person would go through, the program is very easy to design. Here is the program(!)

'PROGRAM: GIVECARD.BAS
InitializeDeck
ShuffleDeck
'ask first player
n=HowManyCards
DealCards(n)
'ask second player
n=HowManyCards
DealCards(n)

What remains is only to decide what each step should do, and how the information about the cards will be stored. Since storing the information determines how it is passed between subprograms, we begin with determining this part.

We may want to use an array Deck(52) which will be of ``user defined" type. The advantage of this approach is that we may modify the information we w ``store" with each card with minimal changes in the program itself.

DEF TYPE Cards
Suite as string
Value as integer ' we may want string here, too!
End type

Afterwards we may declare two shared arrays

Dim Shared Deck(52) as cards
DIM Shared Order(52)
Shared means that every SUB in the program can access values of Order(j), and Deck(j). The first card dealt will be Deck(Order(1)). The definition of type says that its value is Deck(Order(1)).value and its suit is Deck(Order(1)).suit.





Send comment