Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Time for action – adding a World class


To implement our World class, we need to use the following steps:

  1. Add a new Objective-C class called World, which is derived from NSObject.

  2. To add a level property from the int type, do the following:

    • Add a static variable called level in World.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;
  3. Repeat step 2 for the properties gold, hitpoints, and damage.

  4. We also need a levelMax property, but this one does not have a setter.

  5. We need to import the Assets.h file inside the World.m file.

  6. Add a static reset method that needs to be declared in World.h. It should look like the following piece of code:

    +(void) reset
    {
        level = 1;
        levelMax = 3;
        gold = 200;
        damage = [(NSNumber *) [Assets dictionaryFromJSON...