====================================================================== Faculty of Applied Science and Engineering, University of Toronto CSC181: Introduction to Computer Programming, Fall 2000 Tutorial Notes, Week 10 ====================================================================== ----------------- Summary of Topics ----------------- - Modules ------------ Introduction ------------ Consider the game of Scrabble. How would you decompose this game into modules? Here's a possible breakdown: Game, Board, Player and Tray. ---- Game ---- Data: - A Board. - A set of n Players, where n can be a number from 1 to 4. - A bag of tiles. Operations: - initialize(n): Initializes this game for n players, where n can be a number from 1 to 4. - start(): Starts the game. - dispense(n, p): Dispenses n tiles to player p. ----- Board ----- Data: - A grid of squares, each of which may contain one tile. Operations: - initialize(): Initializes this board to an empty board. - place(l, p, o): Places the sequence of letters l at position p with orientation o. Returns the score for this move. ------ Player ------ Data: - A score. - A Tray of tiles. Operation: - move(l, b, p, o): Places the sequence of letters l on Board b at position p with orientation o. The letters in l are removed from this player's tray of tiles, and replaced by letters which this player takes from the bag. The score for the move is added to this player's score. ---- Tray ---- Data: - A set of n tiles, where n is a number from 0 to 7. Operations: - add(t): Adds tile t to this tray. - remove(t): Removes tile t from this tray.