< Previous | Contents | Next >

References: Tic-Tac-Toe


The concept of references is simple, but its implications are profound. In this chapter, youll learn about references and how they can help you write more efficient game code. Specifically, youll learn to:

n Create references

n Access and change referenced values

n Pass references to functions to alter argument values or for efficiency

n Return references from a function for efficiency or to alter values


 

Using ReferencesIntroducing the Referencing ProgramCreating ReferencesAccessing Referenced ValuesAltering Referenced ValuesPassing References to Alter ArgumentsIntroducing the Swap ProgramPassing by ValuePassing by ReferencePassing References for EfficiencyIntroducing the Inventory Displayer ProgramUnderstanding the Pitfalls of Reference PassingDeclaring Parameters as Constant ReferencesPassing a Constant ReferenceDeciding How to Pass ArgumentsReturning ReferencesIntroducing the Inventory Referencer ProgramReturning a ReferenceDisplaying the Value of a Returned ReferenceAssigning a Returned Reference to a ReferenceAssigning a Returned Reference to a VariableAltering an Object through a Returned ReferenceIntroducing the Tic-Tac-Toe GamePlanning the GameSetting Up the ProgramThe main() FunctionThe instructions() FunctionThe askYesNo() FunctionThe askNumber() FunctionThe humanPiece() FunctionThe opponent() FunctionThe displayBoard() FunctionThe winner() FunctionThe isLegal() FunctionThe humanMove() FunctionThe computerMove() FunctionThe announceWinner() FunctionSummaryQuestions and AnswersDiscussion QuestionsExercises