We have finally reached the
checkTable
method. As you recall, this is called by the update
method after the balls have come to rest after a shot. This is where the rest of the game interacts with the rules engine, so we will take this method in pieces.
Filename: OPPlayfieldLayer.m
(checkTable
, part 1)
-(void) checkTable { NSInteger currPlayer = [rules currentPlayer]; BOOL isValidFirst = NO; BOOL isValidSink = NO; BOOL isLastBall = NO; BOOL isTableScratch = NO; BOOL isScratch = NO; BOOL replaceBalls = NO; BOOL isPlayerChange = NO; BOOL isValidLastBall = NO; BOOL playerLoses = NO; isValidFirst = [rules isLegalFirstHit:firstHit]; isValidSink = [rules didSinkValidBall:ballsSunk]; isTableScratch = [rules isTableScratch]; isLastBall = [rules didSinkLastBall:ballsSunk]; isScratch = [rules didSinkCueBall:ballsSunk]; isValidLastBall = [rules isValidLastBall:ballsSunk withBallsOnTable:[self ballSpritesOnTable...