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

Current_State := Play; Person := Black; --Black starts<br />

Display( The.Reversi );<br />

while Current_State = Play loop<br />

Now_Play<strong>in</strong>g( The.Reversi, Person );<br />

--Initial board<br />

--Playable game<br />

--set player<br />

loop<br />

--Get move<br />

Get_Move(The.Contestant(Person), X, Y);<br />

Move_Is:=Check_Move(The.Reversi, X, Y);--Validate<br />

exit when Move_Is=Ok or Move_Is=Pass; --OK<br />

end loop;<br />

Add( The.Reversi, X, Y, Move_Is );<br />

--Add move to board<br />

Display( The.Reversi ); --Display new board<br />

Current_State := Status( The.Reversi ); --State of play is<br />

if Current_State = Play then<br />

case Person is<br />

when Black => Person := White;<br />

when White => Person := Black;<br />

end case;<br />

end if;<br />

end loop;<br />

--Is still playable<br />

--next player<br />

--Next move<br />

Announce( The.Contestant(Person), Current_State ); --Result<br />

end Play;<br />

end Class_Game;<br />

9.5.1 Runn<strong>in</strong>g the program<br />

Then to run the game the follow<strong>in</strong>g procedure is used to send the message Play to an <strong>in</strong>stance of the class Game.<br />

with Class_Game;<br />

use Class_Game;<br />

procedure Ma<strong>in</strong> is<br />

A_Game : Game;<br />

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

Play( A_Game );<br />

end Ma<strong>in</strong>;<br />

9.5.2 Example of a typical game<br />

A typical game might be:<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!