--Date: December 2000 --Author: R. McCloskey --Description: specification of package supporting the Bowling Game ADT with Bowling_Frames; package Bowling_Games is package BF renames Bowling_Frames; type Game_Type is private; Frames_Per_Game : constant Natural := 12; subtype Frame_Num_Range is Natural range 1..Frames_Per_Game; subtype Frame_Cnt_Range is Natural range 0..Frames_Per_Game; subtype Score_Range is Natural range 0..300; Game_Over, Bad_Frame_Num : exception; --<<<< C o n s t r u c t o r s >>>> function Create return Game_Type; ---------------------------------------------------------- --pre: none --post: Let G be value returned; then Frames_Played(G) = 0 ---------------------------------------------------------- procedure Create( Game : out Game_Type ); ---------------------------------------------------------- --pre: none --post: Frames_Played(Game) = 0 ---------------------------------------------------------- --<<<< O b s e r v e r s >>>> function Frames_Played( Game : Game_Type ) return Frame_Cnt_Range; --------------------------------------------------------------- --pre: none --post: value returned is number of frames in Game that have -- been posted --------------------------------------------------------------- function Is_Over( Game : Game_Type ) return Boolean; --------------------------------------------------------------- --pre: none --post: returns true iff Game is a completed game of bowling -- (i.e., no more frames are to be played) --------------------------------------------------------------- function Frame_of ( Game : Game_Type; Frame_Num : Frame_Num_Range ) return BF.Frame_Type; ----------------------------------------------------------------- --pre: Frame_Num <= Frames_Played( Game ) --post: returns the Frame_Num-th frame of Game --excep: Bad_Frame_Num is raised if precondition not met ----------------------------------------------------------------- function Score_of( Game : Game_Type ) return Score_Range; ------------------------------------------------------- --pre: Is_Over( Game ) --post: returns final score of Game ------------------------------------------------------- function Score_of ( Game : Game_Type; Thru : Frame_Cnt_Range) return Score_Range; ---------------------------------------------------------- --pre: Thru <= Frames_Per_Game - 2 --post: value returned is score through the Thru-th frame. -- If not enough frames have been played to give a -- score through that many frames, give the score -- that would be achieved if all subsequent throws -- failed to knock down any pins. ---------------------------------------------------------- --<<< C o m m a n d s / M o d i f i e r s >>>> procedure Post_Frame ( Game : in out Game_Type; Frame : in BF.Frame_Type ); ------------------------------------------------------------ --pre: not Is_Over( Game ) --post: Letting G be the incoming value of Game: -- Frames_Played( Game ) = Frames_Played( G ) + 1 and -- Frame_of( Game, Frames_Played(Game)) = Frame and, -- for all k in 1..Frames_Played( G ), -- Frame_of( Game, k ) = Frame_of( G, k ). -- In other words, Game and G are the same, except that -- Game has had Frame recorded as its most recent frame. --excep: Game_Over raised if precondition not met -------------------------------------------------------------- --<<< p r i v a t e >>> private type Scorecard_Type is array (Frame_Num_Range) of BF.Frame_Type; type Game_Type is record Frames_Played : Frame_Cnt_Range := 0; Scorecard : Scorecard_Type := (others => BF.Create(2,0,0)); end record; end Bowling_Games;