18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Case study: Design of a game 129<br />

A controller of the game (games master) asks each player <strong>in</strong> turn for a move. When a move is received from a<br />

player the board is asked to validate the move. If this is a valid move the counter of the current player is added<br />

to the board. The board is displayed and the new state of the board is evaluated. This process is repeated until<br />

either the board is filled or neither player can make a move. The player mak<strong>in</strong>g the last move is asked to<br />

announce the result of the game.<br />

The major objects and verbs identified are:<br />

<strong>Object</strong>s (nouns)<br />

board<br />

game<br />

cell<br />

counter<br />

player<br />

game<br />

Messages (verbs)<br />

add<br />

announce<br />

ask<br />

evaluated<br />

capture<br />

display<br />

validate<br />

The follow<strong>in</strong>g messages are sent to <strong>in</strong>dividual objects:<br />

board<br />

Display a representation of the board.<br />

Add a counter to the board.<br />

Evaluate the current state of the board.<br />

Validate a proposed move.<br />

player<br />

Announce the result of the game.<br />

Ask for the next move.<br />

cell<br />

Add a counter <strong>in</strong>to a cell on the board.<br />

counter<br />

Display a representation of the counter.<br />

Play<br />

Play the game.<br />

It is more appropriate to deal with classes than to deal with objects. For example, Board is the class to which<br />

the object board belongs. Us<strong>in</strong>g this approach the messages sent to these classes can be ref<strong>in</strong>ed <strong>in</strong>to the<br />

follow<strong>in</strong>g list:<br />

Class Message Responsibility of method<br />

Board Add Add a counter <strong>in</strong>to the board.<br />

Check_Move<br />

Check if a player can drop a counter<br />

<strong>in</strong>to a column.<br />

Contents<br />

Return the contents of a cell.<br />

Display<br />

Display a representation of the board.<br />

Now_play<strong>in</strong>g<br />

Say who is now play<strong>in</strong>g on the board.<br />

Set_Up<br />

Populate the board with the <strong>in</strong>itial<br />

contents.<br />

Status<br />

Evaluate the current state of the<br />

board.<br />

Player Announce Announc<strong>in</strong>g that the player has either<br />

won or drawn the game.<br />

Get_Move<br />

Get the next move from the player.<br />

My_Counter<br />

Return the counter that the player<br />

plays with.<br />

Set<br />

Set a player to play with a particular<br />

counter.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!