Time for action – adding a World class
To implement our World
class, we need to use the following steps:
Add a new Objective-C class called
World
, which is derived fromNSObject
.To add a
level
property from theint
type, do the following:Add a static variable called
level
inWorld.h
, as shown in the following line of code:static int level;
Add a static getter with the same name that returns the static variable, as shown in the following line of code:
+(int) level;
Add a static setter (
setLevel
) that sets the static variable, as shown in the following line of code:+(void) setLevel:(int)value;
Repeat step 2 for the properties
gold
,hitpoints
, anddamage
.We also need a
levelMax
property, but this one does not have a setter.We need to import the
Assets.h
file inside theWorld.m
file.Add a static
reset
method that needs to be declared inWorld.h
. It should look like the following piece of code:+(void) reset { level = 1; levelMax = 3; gold = 200; damage = [(NSNumber *) [Assets dictionaryFromJSON...