Game Development Reference
In-Depth Information
The NSArray image stores all of the images that make up the spinning coin animation. By calling
setAnimationImages: on the UIImageView coinView , we indicate that we want this UIIMageView to
cycle though each UIIMage in images to produce the animation effect. Setting the animation duration
to a random value and calling startAnimating creates the spinning effect. At this point in the setup,
the application will look very much like Figure 4-6 shown earlier. We are ready to start accepting
user input. Before we look at that, we should take a closer look at the class CoinsGame so you can
understand how we are representing these 25 coins and their types.
The Model
You have now looked at the setup code, which used UIViews and UIImageViews to create a scene on
the screen that represents the game. You know that the game is composed of 25 coins in a five-by-
five grid. Now we should take a look at the class that is responsible for managing this data, so let's
look at CoinsGame.h , shown Listing 4-13.
Listing 4-13. CoinsGame.h
#import<Foundation/Foundation.h>
#define COIN_TRIANGLE 0
#define COIN_SQUARE 1
#define COIN_CIRCLE 2
struct Coord {
int row;
int col;
};
typedef struct Coord Coord;
CG_INLINE Coord
CoordMake(int r, int c)
{
Coord coord;
coord.row = r;
coord.col = c;
return coord;
}
CG_INLINE BOOL
CoordEqual(Coord a, Coord b)
{
return a.col == b.col && a.row == b.row;
}
@interface CoinsGame : NSObject<NSCoding>{
NSMutableArray* coins;
int remaingTurns;
int score;
int colCount;
int rowCount;
}
 
Search WWH ::




Custom Search