#import <Foundation/Foundation.h>
#import "RequstData.h"
#import "Clothes.h"
#import "Weapon.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
RequstData *requst = [[RequstData alloc]init];
[requst loadData];
Weapon *weapon = requst.weaponList[0];
NSLog(@"%@ %d",weapon.name,weapon.att);
}
return 0;
}
#import <Foundation/Foundation.h>
@interface Clothes : NSObject
@property NSString *name;
@property int def;
@end
#import "Clothes.h"
@implementation Clothes
- (instancetype)initWithName:(NSString *)name andDef:(int)def
{
self = [super init];
if (self) {
_name = name;
_def = def;
}
return self;
}
@end
#import <Foundation/Foundation.h>
@interface Weapon : NSObject
@property NSString *name;
@property int att;
@end
#import "Weapon.h"
@implementation Weapon
- (instancetype)initWithName:(NSString *)name andAtt:(int)att
{
self = [super init];
if (self) {
_name = name;
_att = att;
}
return self;
}
@end
#import <Foundation/Foundation.h>
@interface Skill : NSObject
@property NSString *name;
@property int att;
@end
#import "Skill.h"
@implementation Skill
- (instancetype)initWithName:(NSString *)name andAtt:(int)att
{
self = [super init];
if (self) {
_name = name;
_att = att;
}
return self;
}
@end
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property NSString *name;
@property int att;
@property int blood;
@property int def;
@end
#import "Person.h"
@class Skill;
@class Weapon;
@class Clothes;
@interface Hero : Person
@property Skill *skill;
@property Weapon *weapon;
@property Clothes *clothes;
- (instancetype)initWithName:(NSString *)name andBlood:(int)blood andAtt:(int)att andDef:(int)def andSkill:(Skill *)heroSkill andWeapon:(Weapon *)heroWeapon andCloth:(Clothes *)heroCloth;
@end
#import "Hero.h"
#import "Skill.h"
#import "Weapon.h"
#import "Clothes.h"
@implementation Hero
- (instancetype)initWithName:(NSString *)name andBlood:(int)blood andAtt:(int)att andDef:(int)def andSkill:(Skill *)heroSkill andWeapon:(Weapon *)heroWeapon andCloth:(Clothes *)heroCloth
{
self = [super init];
if (self) {
self.name = name;
self.blood = blood;
self.att = att;
self.def = def;
_skill = heroSkill;
_clothes = heroCloth;
_weapon = heroWeapon;
}
return self;
}
@end
#import "Person.h"
@class Skill;
@interface Monster : Person
@property Skill *monsterSkill;
- (instancetype)initWithName:(NSString *)name andBlood:(int)blood andAtt:(int)att andDef:(int)def andSkill:(Skill *)monsterSkill;
@end
#import "Monster.h"
#import "Skill.h"
@implementation Monster
- (instancetype)initWithName:(NSString *)name andBlood:(int)blood andAtt:(int)att andDef:(int)def andSkill:(Skill *)monsterSkill
{
if (self) {
self.name = name;
self.blood = blood;
self.att = att;
self.def = def;
_monsterSkill = monsterSkill;
}
return self;
}
@end
#import <Foundation/Foundation.h>
@interface RequstData : NSObject
{
NSArray *clothesData;
NSArray *weaponData;
NSArray *heroSkillData;
NSArray *monsterSkillData;
NSArray *heroData;
NSArray *monsterData;
}
@property (nonatomic)NSMutableArray *clothesList;
@property (nonatomic)NSMutableArray *weaponList;
@property (nonatomic)NSMutableArray *heroSkillList;
@property (nonatomic)NSMutableArray *MonsterSkillList;
@property (nonatomic)NSMutableArray *HeroList;
@property (nonatomic)NSMutableArray *monsterList;
-(void)loadData;
-(NSMutableArray *)weaponList;
-(NSMutableArray *)heroList;
-(NSMutableArray *)monsterList;
-(NSMutableArray *)heroSkillList;
-(NSMutableArray *)clothesList;
-(NSMutableArray *)MonsterSkillList;
@end
#import "RequstData.h"
#import "NSDictionary+ReadFile.h"
#import "Clothes.h"
#import "Weapon.h"
#import "Skill.h"
#import "Hero.h"
#import "Monster.h"
@implementation RequstData
-(void)loadData{
NSDictionary *allData = [NSDictionary readFileWithName:@"GameData"];
clothesData = allData[@"clothes"];
weaponData = allData[@"weapon"];
heroSkillData = allData[@"heroSkill"];
monsterSkillData = allData[@"monsterSkill"];
heroData = allData[@"hero"];
monsterData = allData[@"monster"];
}
#pragma mark -----导入武器
-(NSMutableArray *)weaponList{
_weaponList = [NSMutableArray array];
for (NSDictionary *weaponDic in weaponData) {
Weapon *weapon = [[Weapon alloc]init];
weapon.name = weaponDic[@"name"];
weapon.att = [weaponDic[@"att"] intValue];
[_weaponList addObject:weapon];
}
return _weaponList;
}
#pragma mark -----导入衣服
-(NSMutableArray *)clothesList{
if (_clothesList!=nil) {
return _clothesList;
}
_clothesList = [NSMutableArray array];
for (NSDictionary *clothDic in clothesData) {
Clothes *cloth = [[Clothes alloc]init];
cloth.name = clothDic[@"name"];
cloth.def = [clothDic[@"def"]intValue];
[_clothesList addObject:cloth];
}
return _clothesList;
}
#pragma mark ------英雄技能--
-(NSMutableArray *)heroSkillList{
_heroSkillList = [NSMutableArray array];
for (NSDictionary *heroSkillDic in heroSkillData) {
Skill *heroSkill = [[Skill alloc]init];
heroSkill.name = heroSkillDic[@"name"];
heroSkill.att = [heroSkillDic[@"att"] intValue];
[_heroSkillList addObject:heroSkill];
}
return _heroSkillList;
}
#pragma mark ----怪物技能
-(NSMutableArray *)MonsterSkillList{
_MonsterSkillList = [NSMutableArray array];
for (NSDictionary *monsterSkillDic in monsterSkillData) {
Skill *monsterSkill = [[Skill alloc]init];
monsterSkill.name = monsterSkillDic[@"name"];
monsterSkill.att = [monsterSkillDic[@"att"] intValue];
[_MonsterSkillList addObject:monsterSkill];
}
return _MonsterSkillList;
}
#pragma mark ---英雄
-(NSMutableArray *)heroList{
_HeroList = [NSMutableArray array];
for (NSDictionary *heroListDic in heroData) {
Hero *hero = [[Hero alloc]initWithName:heroListDic[@"name"] andBlood:[heroListDic[@"blood"]intValue] andAtt:[heroListDic[@"att"]intValue] andDef:[heroListDic[@"def"]intValue] andSkill:_HeroList[0] andWeapon:_weaponList[0] andCloth:_clothesList[0]];
[_HeroList addObject:hero];
}
return _HeroList;
}
#pragma mark ---怪物
-(NSMutableArray *)monsterList{
_monsterList = [NSMutableArray array];
for (NSDictionary *monsterDic in monsterData) {
Monster *monster = [[Monster alloc]initWithName:monsterDic[@"name"] andBlood:[monsterDic[@"blood"]intValue] andAtt:[monsterDic[@"att"]intValue] andDef:[monsterDic[@"def"]intValue] andSkill:_monsterList[0]];
[_monsterList addObject:monster];
}
return _monsterList;
}
@end