teaching machines

Final Project : Vampire Assassin

December 20, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

Vampire Assassin for iOS

While this is still a work in progress, and should take me another month to polish up for consumer release… the most important bits are complete enough for a sufficient writeup.

This app is at its core, a player that can buy and sell items from the shop, equip said items in one of 3 slots (Armor,Weapon,Accessory), and use these items to run missions for Blood and Gold, which in turn they can use to buy and equip more powerful items.

 

 

 

 

 

 

 

 

 

Most interesting aspect here is the different (custom) table cell styles.  Each different table cell was created in IB and loaded up within each callback controller like so

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @”MissionCell”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[NSBundle mainBundle] loadNibNamed:@”MissionCell” owner:self options:nil] objectAtIndex:0];

}

and then use tags from the nib file to figure out what object is which so we can access in within the method like so

UIButton *itemButton = (UIButton*)[cell viewWithTag:7];

[itemButton setTitle:@”Attempt” forState:UIControlStateNormal];

Also, since usually when you touch a cell, it picks the entire cell and it doesn’t have a button in it, so since we care when the button is pressed only.. we use

[itemButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

to create a callback for buttons themselves which we can get the calling cell back by using

UITableViewCell *cell = (UITableViewCell*)[[sender superview] superview];

to access the calling cell so we can screw around with it some more! :)

 

They can also build and join clans to increase power

 

They can also fight other players using a client-server model with JSON data exchange

 

 

 

 

 

 

 

 

 

 

The JSON exchange is essentially a serialization of each object.  Ie

allCharacters = (NSDictionary*)[tempString objectFromJSONString];

[[GameManager sharedManager] updateRemoteCharactersWithJSON:[allCharacters copy]];

The objectFromJSONString is a method from JSONKit that can be found at https://github.com/johnezang/JSONKit

The updateRemoteCharactersWithJSON method is essentially a object init method that takes in an NSDictionary and creates a series of Character Objects contained within multiple arrays all within another NSDictionary where the “keys” are essentially the “categories” of each array, ie “Commercial” for missions and “Weapons” for shop, as seen in the screenshots above.

The JSON data that is sent to the server is here

Character={“characterID”:101,”characterCurrentHealth”:10,”characterMaxHealth”:10,”characterSpeed”:0,”characterCurrentEnergy”:10,”characterExp”:0,”characterDefense”:0,”characterLatCoords”:0,”characterLongCoords”:0,”characterName”:”Accer”,”characterRange”:0,”characterGold”:10,”characterPortrait”:”male1.png”,”characterClanID”:10,”characterTitle”:”Bottom Feeder”,”characterMaxEnergy”:10,”characterUID”:”111111111111-11111111111111-1111111-111111111″,”characterAttack”:0,”characterBlood”:100}

and an array of JSON Character objects is returned of all characters that this character can fight.

the PHP script on the server calls the json_decode() and json_encode() methods to serialize and unserialize this data

        $json = $_POST['Character'];
        $json = str_replace("\\", "", $json);
        $json = json_decode($json,true);

You will note the replace function, which must be called since the data is urlencoded due to the “Character =” at the head of the message, and the $json object must be converted to a Content-Type of “application/json encoding”

– Erik

Copyright : Barrage Software LLC