- Inherits From:
- NSObject
- Conforms To:
- ICGameProtocol
- NSCoding
- Declared In:
- ICGame.h
The players array contains between 2 and 6 ICPlayer objects. The currentPlayer object represents the player whose turn it is.
The countries array contains a number of ICCountry objects. The currentCountry object represents the currently selected country. The continents dictionary organizes the countries into separate continents.
The gameState variable stores the overall state of the game: GameStatePickCountries
, GameStateInitializeArmies
, GameStatePlay
, or GameStateVictory
. The turnState variable stores the state of the turn: TurnStateAssignArmies
, TurnStateAttack
, TurnStateFortify
, or TurnStateDone
.
The timer controls the pace of the game. When it is a computer player's turn, the timer tells the player when to place armies or attack.
PlayersCountries
- - players
- - currentPlayer
- - nextPlayer
Game State
- - countries
- - unallocatedCountries
- - currentCountry
- - setCurrentCountry:
- - incomeForCountries:
- - continents
- - continentValues
Turn State
- - gameState
- - pickCountries
- - isPickingCountries
- - donePickingCountries
- - isAllocatingArmies
- - doneAllocatingArmies
- - isPlaying
- - victory
- - isVictory
Timer
- - turnState
- - beginTurn
- - isAssigningArmies
- - attack
- - isAttacking
- - fortify
- - isFortifying
- - done
- - isDone
Miscellaneous
- - startTimer
- - stopTimer
- - pauseTimer
- - unpauseTimer
- - takeAction
- - updateStatistics
- - currentCardSetValue
- - allowTurningInCards
- (BOOL)allowTurningInCards
Returns whether the player is allowed to turn in cards after eliminating another player.
- (void)attack
Called when the current player is done placing armies.
Sets the turn state to TurnStateAttack
.
If the current player is a computer, starts the timer.
- (void)beginTurn
Starts the turn by setting the turn state to TurnStateAssignArmies
.
Sends the assignArmiesFromIncome message to the current player.
If the current player is a computer, starts the timer.
- (NSMutableDictionary *)continentValues
A dictionary of continents, where the key is the continent's name and the value is the number of bonus armies for that continent.
- (NSMutableDictionary *)continents
A dictionary of continents, where the key is the continent's name and the value is an array of countries in the continent.
- (NSArray *)countries
The array of all countries in the game.
- (int)currentCardSetValue
The number of armies that a set of cards is worth. Every time cards are turned in, this value increases.
- (ICCountry *)currentCountry
The currently selected country.
- (ICPlayer *)currentPlayer
The player whose turn it is.
- (void)done
Called when the current player is done fortifying.
Sets the turn state to TurnStateDone
.
If the current player has won this turn, gives them a card.
Stops the timer, selects the next player, and begins a turn again.
- (void)doneAllocatingArmies
Call this method when the last player has finished placing initial armies.
Sets the game state to GameStatePlay
, stops the timer,
selects the first player, and starts the first turn.
- (void)donePickingCountries
Call this method when the last player has finished picking countries.
Sets the game state to GameStateInitializeArmies
.
Selects the first player, and starts the timer.
- (void)fortify
Called when the current player is done attacking.
Sets the turn state to TurnStateFortify
.
Sends the fortify message to the current player.
- (ICGameState)gameState
Returns an integer that represents the game state. Possible values are GameStatePickCountries
, GameStateInitializeArmies
, GameStatePlay
, and GameStateVictory
.
- (int)incomeForCountries:(NSArray *)playerCountries
Given an array of countries that a player owns, returns the number of armies that they should receive at the beginning of a turn. That value is one army for every three countries owned, plus bonus armies for each continent. Players will always earn at least three armies.
- (BOOL)isAllocatingArmies
Returns whether the game state is GameStateInitializeArmies
.
- (BOOL)isAssigningArmies
Returns whether the turn state is TurnStateAssignArmies
.
- (BOOL)isAttacking
Returns whether the turn state is TurnStateAttack
.
- (BOOL)isDone
Returns whether the turn state is TurnStateDone
.
- (BOOL)isFortifying
Returns whether the turn state is TurnStateFortify
.
- (BOOL)isPickingCountries
Returns whether the game state is GameStatePickCountries
.
- (BOOL)isPlaying
Returns whether the game state is GameStatePlay
.
- (BOOL)isVictory
Returns whether the game state is GameStateVictory
.
- (ICPlayer *)nextPlayer
Returns the player after the current player in the players array.
- (void)pauseTimer
Stops the timer but doesn't set it to nil. To resume, call unpauseTimer.
- (void)pickCountries
Sets the game state to GameStatePickCountries
.
Initializes the game board so that all countries are unowned, and selects the first player.
Depending on the user's assign countries preference, randomly picks countries or tells the first player to pick a country.
- (NSMutableArray *)players
The players in the game.
- (void)setCurrentCountry:(ICCountry *)value
Sets the currently selected country.
- (void)startTimer
Called when a computer player's turn begins. Repeatedly calls takeAction until stopTimer is called. As the animationSpeed preference ranges from 0 (slow) to 4 (fast), the time interval will be 1.0 to 0.0 seconds.
- (void)stopTimer
Stops the timer (and sets it to nil). If the timer should be resumed, use pauseTimer.
- (void)takeAction
The game's main timer calls this method. If assigning armies, sends assignInitialArmies to the current player. If attacking, sends attack to the current player.
- (ICTurnState)turnState
Returns an integer representing the turn state. Possible values are:
TurnStateAssignArmies
,
TurnStateAttack
,
TurnStateFortify
, and
TurnStateDone
.
- (NSMutableArray *)unallocatedCountries
The countries in the game that have not been picked yet.
- (void)unpauseTimer
If the timer is paused, unpauses it.
- (void)updateStatistics
Invalidates the statistics, causing the data to be reloaded.
- (void)victory
Call this method when only one player remains.
Sets the game state to GameStateVictory
, stops the timer, and beeps.