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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

9.5 Implementation of the ma<strong>in</strong> class Game<br />

Us<strong>in</strong>g the design carried out above, the specification of the class Game is :<br />

with Class_Board, Class_Player, Class_Counter;<br />

use Class_Board, Class_Player, Class_Counter;<br />

package Class_Game is<br />

type Game is private;<br />

procedure play( The:<strong>in</strong> out Game );<br />

private<br />

type Player_Array is array(Counter_Colour) of Player;<br />

type Game is record<br />

Reversi : Board; --The play<strong>in</strong>g board<br />

Contestant : Player_Array;<br />

end record;<br />

end Class_Game;<br />

and the implementation is as follows:<br />

package body Class_Game is<br />

procedure Play( The:<strong>in</strong> out Game ) is --Play reversi<br />

Current_State : State_Of_Game; --State of game<br />

Person : Counter_Colour; --Current player<br />

X, Y : Integer; --Move<br />

Move_Is : Move_Status; --Last move is<br />

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

Set_Up( The.Reversi );<br />

--Set up board<br />

Set( The.Contestant(Black), Black ); --Set player black<br />

Set( The.Contestant(White), White ); --Set player white<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!