< Previous | Contents | Next >

Classes: Critter Caretaker


Object-oriented programming (OOP) is a


image

different way of thinking about

programming. Its a modern methodology thats used in the creation of the vast majority of games (and other commercial software, too). In OOP, you define different types of objects with relationships to each other that allow the objects to interact. Youve already worked with objects from types defined in libraries, but one of the key characteristics of OOP is the ability to make your own types from which you can create objects. In this chapter, youll see how to define your own types and create objects from them. Specifically, youll learn to:

n Create new types by defining classes

n Declare class data members and member functions

n Instantiate objects from classes

n Set member access levels

n Declare static data members and member functions


 

Defining New TypesIntroducing the Simple Critter ProgramDefining a ClassDefining Member FunctionsInstantiating ObjectsAccessing Data MembersCalling Member FunctionsUsing ConstructorsIntroducing the Constructor Critter ProgramDeclaring and Defining a ConstructorCalling a Constructor AutomaticallySetting Member Access LevelsIntroducing the Private Critter ProgramSpecifying Public and Private Access LevelsDefining Accessor Member FunctionsDefining Constant Member FunctionsUsing Static Data Members and Member FunctionsIntroducing the Static Critter ProgramDeclaring and Initializing Static Data MembersAccessing Static Data MembersDeclaring and Defining Static Member FunctionsCalling Static Member FunctionsIntroducing the Critter Caretaker GamePlanning the GamePlanning the PseudocodeThe Critter ClassThe main() FunctionSummaryQuestions and AnswersDiscussion QuestionsExercises