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 135<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | X | X | X | | |<br />

---------------------------------<br />

| | | | O | X | X | | |<br />

---------------------------------<br />

| | | | | | X | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | X | X | X | | |<br />

---------------------------------<br />

| | | | X | X | X | | |<br />

---------------------------------<br />

| | | | X | | X | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

| | | | | | | | |<br />

---------------------------------<br />

Player X has 6 counters -<br />

Player O has 1 counters<br />

Please enter move X row column: 6 4<br />

Player X has 8 counters -<br />

Player O has 0 counters<br />

Player X has won<br />

9.6 Implementation of the other classes<br />

The ma<strong>in</strong> program is implemented us<strong>in</strong>g the classes described earlier. The package Pack_Screen is responsible<br />

for handl<strong>in</strong>g the mach<strong>in</strong>e specific action of clear<strong>in</strong>g the screen. Us<strong>in</strong>g an ANSI term<strong>in</strong>al, its implementation is as<br />

follows:<br />

package Pack_Screen is<br />

procedure Screen_Clear; --Home clear screen<br />

procedure Screen_Home; --Home no clear screen<br />

private<br />

Esc: constant Character := Character'Val(27);<br />

end Pack_Screen;<br />

The implementation of this package uses ANSI escape sequences to implement these procedures. If an ANSI<br />

compatible term<strong>in</strong>al is not available, the bodies of these procedures can be changed to implement an appropriate<br />

alternative.<br />

with Text_Io; use Text_Io;<br />

package body Pack_Screen is<br />

procedure Screen_Clear is<br />

beg<strong>in</strong><br />

Put( Esc & "[2J" );<br />

end Screen_Clear;<br />

procedure Screen_Home is<br />

beg<strong>in</strong><br />

Put( Esc & "[0;0H");<br />

end Screen_Home;<br />

end Pack_Screen;<br />

--Term<strong>in</strong>al dependent I/O<br />

--Clear screen<br />

--Escape sequence<br />

--Home<br />

--Escape sequence<br />

The specification of the class Counter is as follows:<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!