/*
项目名称: 玩转三国
类型: 策略性游戏
上次更新时间: 无
游戏功能: 群雄逐鹿,玩家选择操作一个君主,招募武将,发展城市,统一全国
游戏操作: 按游戏提示,进行操作
创建游戏内容: 1).城市:荆州,许昌,合肥, 君主(只显示君主所属武将,暂不显示君主): 刘备,曹操,孙坚 武
将: 关羽,夏侯惇,黄盖
2).占领全部城市为最终胜利,武将死亡为最终失败,每次战斗后,胜利方血量回满,城市归胜利武将占领,成为胜利武将君主的领土
3).战斗的胜负和血量,武力有关
4).失败可以选择重新开始
下期更新内容: 1>.君主出场,增加武将
2>.增加技能系统
3>.多人对战??????(待定)
目的: 利用已学的知识,做一个小模型,以便复习以前的知识和应用已学的知识;并逐渐丰满游戏.
开始只是连个图形都没有的简单玩具游戏,希望毕业那天成为一个真正的游戏
作者: 李言
日期: 2015.7.15
*/
// 温馨提醒: 游戏时,请每次输入一个字符,然后敲回车键
文件4): GM.h
/**
* 系统行为的实现: 实现一些系统的方法
*/
#import "GM.h"
#import "General.h"
#import "City.h"
@implementation GM
// 城市和武将对象的创建
+ (id)systemInitGeneral:(General *)MySelf andCity:(City *)city1 andCity:(City *)city2 andCity:(City *)city3{
// 创建并初始化关羽
static General *guanYu;
guanYu = [[General alloc] initWithGeneralName:@"关羽" andMonarch:@"刘备" andForce:118 andBlood:1150 andSkillValue:50 andDefendCity:city1 andCityNum:1];
// 创建并初始化夏侯惇
General *xiaHouDun = [[General alloc] initWithGeneralName:@"夏侯惇" andMonarch:@"曹操" andForce:101 andBlood:1020 andSkillValue:47 andDefendCity:city2 andCityNum:1];
// 创建并初始化黄盖
General *huangGai = [[General alloc] initWithGeneralName:@"黄盖" andMonarch:@"孙坚" andForce:98 andBlood:1000 andSkillValue:51 andDefendCity:city3 andCityNum:1];
// 初始化荆州
city1 = [city1 initWithCityName:@"荆州" andDefendGeneral:guanYu];
// 初始化许昌
city2 = [city2 initWithCityName:@"许昌" andDefendGeneral:xiaHouDun];
// 初始化合肥
city3 = [city3 initWithCityName:@"合肥" andDefendGeneral:huangGai];
// 选择武将,后输出武将属性,返回武将
int flag4 = 1;
while (flag4) {
char flag1, ch;
NSLog(@"请选择武将:a.关羽,b.夏侯惇,c.黄盖");
scanf("%c", &flag1);
scanf("%c", &ch);
switch (flag1) {
case 'a' :
case 'A':
MySelf = guanYu;
NSLog(@"您选择了武将关羽!");
[MySelf print];
flag4 = 0;
break;
case 'b' :
case 'B':
MySelf = xiaHouDun;
NSLog(@"您选择了武将夏侯惇!");
[MySelf print];
flag4 = 0;
break;
case 'c' :
case 'C':
MySelf = huangGai;
NSLog(@"您选择了武将黄盖!");
[MySelf print];
flag4 = 0;
break;
default:
NSLog(@"没有该武将,请重新输入!");
break;
}
}
return MySelf;
}
@end
文件5): General.h
/**
* 武将类的属性变量声明
* 声明:武将名,所属君主,武力,血量,技能值,所在城市,拥有城市数量
*/
#import <Foundation/Foundation.h>
#import "GeneralProtocol.h"
@class City;
@interface General : NSObject <GeneralProtocol>
// 武将实例变量的声明和实现
@property (nonatomic, strong) NSString * generalName; // 姓名
@property (nonatomic, assign) float force; // 武力
@property (nonatomic, assign) float blood; // 血量
@property (nonatomic, assign) float skillValue; // 技能值
@property (nonatomic, weak) City *defendCity; // 所在城市
@property (nonatomic, strong) NSString *monarch; // 所属君主
@property (nonatomic, assign) int cityNum; // 拥有城市数量
@end
文件6): General.m
/**
* 武将类方法的实现
* 因为武将遵守武将方法的协议,这里可以实现协议里的方法
*
* @return
*/
#import "General.h"
#import "City.h"
@implementation General
// 攻城方法的实现
- (void)attackCity:(City *)city{
int win = [self fightWithOtherGeneral:city.defendGeneral];
if (win == 1) {
NSLog(@"%@战胜了%@", self.generalName, city.defendGeneral.generalName);
NSLog(@"%@进攻%@获得了胜利,占领了%@", self.generalName, city.cityName, city.cityName);
self.defendCity = city;
city.defendGeneral = nil;
self.cityNum++;
}else if (win == -1){
NSLog(@"%@进攻%@失败,%@战死了,", self.generalName, city.cityName, self.generalName);
self.cityNum = 0;
}else
NSLog(@"这个城市已经是您的领地了哦!");
}
// 武将战斗过程
- (void)battleProcessWithOther:(General *)general{
NSLog(@"%@ 血量:%.0f VS %@ 血量:%.0f", self.generalName, self.blood, general.generalName, general.blood);
}
// 武将交战方法的实现
- (int)fightWithOtherGeneral:(General *)general{
NSLog(@"战斗开始!!!");
[self battleProcessWithOther:general];
int win = 0;
if (self.monarch != general.monarch) {
float tempBlood = self.blood;
for (int i=0; i<200; i++) {
self.blood -= general.force/10.0;
general.blood -= self.force/10.0;
switch (i) {
case 20:
NSLog(@"第一回合");
[self battleProcessWithOther:general];
break;
case 40:
NSLog(@"第二回合");
[self battleProcessWithOther:general];
break;
case 60:
NSLog(@"第三回合");
[self battleProcessWithOther:general];
break;
case 80:
NSLog(@"第四回合");
[self battleProcessWithOther:general];
break;
}
if (self.blood<0) {
win = -1;
break;
}else if (general.blood<0){
win = 1;
self.blood = tempBlood;
break;
}
}
}else
win = 0;
return win;
}
// 武将初始化方法的实现
- (id)initWithGeneralName:(NSString *)generalName andMonarch:(NSString *)monarch andForce:(float)force andBlood:(float)blood andSkillValue:(float)skillValue andDefendCity:(City *)defendCity andCityNum:(int)cityNum{
if (self = [super init]) {
_cityNum = cityNum;
_monarch = monarch;
_generalName = generalName;
_force = force;
_blood = blood;
_skillValue = skillValue;
_defendCity = defendCity;
}
return self;
}
// 实现输出武将属性方法
- (void)print{
NSLog(@"所属君主:%@,武力%.0f,生命%.0f,技能值%.0f,所在城市:%@,拥有城市:%d", self.monarch, self.force, self.blood, self.skillValue, self.defendCity.cityName, self.cityNum);
}
@end
文件7) City.h
/**
* 城市类属性和方法的声明
* 属性: 城市名称,驻扎的武将,所属君主
* 方法: 城市初始化方法
*/
#import <Foundation/Foundation.h>
@class General;
@interface City : NSObject
// 城市属性变量的声明和实现
@property (nonatomic, strong) NSString *cityName; // 城市名称
@property (nonatomic, strong) General *defendGeneral; // 防守武将
@property (nonatomic, strong) NSString *monarch; // 城市君主
// 城市初始化
- (id)initWithCityName:(NSString *)cityName andDefendGeneral:(General *)defendGeneral;
@end
文件8): City.m
/**
* 城市类方法的实现
*/
#import "City.h"
@implementation City
// 城市初始化方法实现
- (id)initWithCityName:(NSString *)cityName andDefendGeneral:(General *)defendGeneral{
if (self = [super init]) {
_cityName = cityName;
_defendGeneral = defendGeneral;
}
return self;
}
@end
|
|