ICGame


Inherits From:
NSObject
Conforms To:
ICGameProtocol
NSCoding
Declared In:
ICGame.h


Class Description

The ICGame class stores the game state.

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.


Method Types

Players
- players
- currentPlayer
- nextPlayer
Countries
- countries
- unallocatedCountries
- currentCountry
- setCurrentCountry:
- incomeForCountries:
- continents
- continentValues
Game State
- gameState
- pickCountries
- isPickingCountries
- donePickingCountries
- isAllocatingArmies
- doneAllocatingArmies
- isPlaying
- victory
- isVictory
Turn State
- turnState
- beginTurn
- isAssigningArmies
- attack
- isAttacking
- fortify
- isFortifying
- done
- isDone
Timer
- startTimer
- stopTimer
- pauseTimer
- unpauseTimer
- takeAction
Miscellaneous
- updateStatistics
- currentCardSetValue
- allowTurningInCards

Instance Methods

allowTurningInCards

- (BOOL)allowTurningInCards

Returns whether the player is allowed to turn in cards after eliminating another player.


attack

- (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.


beginTurn

- (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.


continentValues

- (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.


continents

- (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.


countries

- (NSArray *)countries

The array of all countries in the game.


currentCardSetValue

- (int)currentCardSetValue

The number of armies that a set of cards is worth. Every time cards are turned in, this value increases.


currentCountry

- (ICCountry *)currentCountry

The currently selected country.


currentPlayer

- (ICPlayer *)currentPlayer

The player whose turn it is.


done

- (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.


doneAllocatingArmies

- (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.


donePickingCountries

- (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.


fortify

- (void)fortify

Called when the current player is done attacking. Sets the turn state to TurnStateFortify. Sends the fortify message to the current player.


gameState

- (ICGameState)gameState

Returns an integer that represents the game state. Possible values are GameStatePickCountries, GameStateInitializeArmies, GameStatePlay, and GameStateVictory.


incomeForCountries:

- (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.


isAllocatingArmies

- (BOOL)isAllocatingArmies

Returns whether the game state is GameStateInitializeArmies.


isAssigningArmies

- (BOOL)isAssigningArmies

Returns whether the turn state is TurnStateAssignArmies.


isAttacking

- (BOOL)isAttacking

Returns whether the turn state is TurnStateAttack.


isDone

- (BOOL)isDone

Returns whether the turn state is TurnStateDone.


isFortifying

- (BOOL)isFortifying

Returns whether the turn state is TurnStateFortify.


isPickingCountries

- (BOOL)isPickingCountries

Returns whether the game state is GameStatePickCountries.


isPlaying

- (BOOL)isPlaying

Returns whether the game state is GameStatePlay.


isVictory

- (BOOL)isVictory

Returns whether the game state is GameStateVictory.


nextPlayer

- (ICPlayer *)nextPlayer

Returns the player after the current player in the players array.


pauseTimer

- (void)pauseTimer

Stops the timer but doesn't set it to nil. To resume, call unpauseTimer.


pickCountries

- (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.


players

- (NSMutableArray *)players

The players in the game.


setCurrentCountry:

- (void)setCurrentCountry:(ICCountry *)value

Sets the currently selected country.


startTimer

- (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.


stopTimer

- (void)stopTimer

Stops the timer (and sets it to nil). If the timer should be resumed, use pauseTimer.


takeAction

- (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.


turnState

- (ICTurnState)turnState

Returns an integer representing the turn state. Possible values are: TurnStateAssignArmies, TurnStateAttack, TurnStateFortify, and TurnStateDone.


unallocatedCountries

- (NSMutableArray *)unallocatedCountries

The countries in the game that have not been picked yet.


unpauseTimer

- (void)unpauseTimer

If the timer is paused, unpauses it.


updateStatistics

- (void)updateStatistics

Invalidates the statistics, causing the data to be reloaded.


victory

- (void)victory

Call this method when only one player remains. Sets the game state to GameStateVictory, stops the timer, and beeps.


Version 1.1 Copyright ©2003 by KavaSoft. All Rights Reserved.