C语言小游戏,笑傲江湖之鸿蒙
首先先放几张运行图
因为代码比较多,我先讲比较重要的:
1.从图中我们就可以看出控制台的名称变了,这里用的函数如下:
void set_title(char *title)
{
SetConsoleTitle(title); //windows.h自带函数
}
然后直接在main()里面调用就可以了
set_title("笑傲江湖之鸿蒙");
2.要做界面优化,其实这就和光标有关,只要控制光标的位置,就能控制从什么位置打印出来,所以只要写控制光标的代码就行了。
void set_position(int x,int y) //参数是光标坐标,这里说一下COORD是<windows.h>里自带的坐标函数,还有就是坐标和数组的横向和纵向刚好相反
{
HANDLE winHandle; //句柄
COORD pos={x,y}; //定义一个位置
winHandle=GetStdHandle(STD_OUTPUT_HANDLE); //将控制台窗口赋值给定义的句柄
SetConsoleCursorPosition(winHandle,pos); //设置光标位置
}
3.为了界面更加好看,我们需要改变颜色的函数
void set_color(int upcolor,int backcolor)
{
HANDLE winHandle; //句柄
winHandle=GetStdHandle(STD_OUTPUT_HANDLE); //将控制台窗口赋值给定义的句柄
//设置文字颜色
SetConsoleTextAttribute(winHandle,upcolor+backcolor*0x10);//设置控制台文本属性
}
/*改变控制台颜色(前景色、背景色)
0-黑色,1-蓝色,2-绿色,3-浅绿色,4-红色,5-紫色,6-黄色,7-白色,8-灰色,9-淡蓝色,
10-淡绿色,11-淡浅绿色,12-淡红色,13-淡紫色,14-淡黄色,15-亮白色
举例:set_color(12,0)
*/
4.清屏函数,其实下面这个方法也能清屏,不过会把所有清掉
system("cls");
当我们想灵活的清屏时可以用自己写的函数
void cclear(int x,int y,int hang) //x是X轴,y是Y轴,hang是行数
{
int i,j;
for(i=0;i<hang;i++)
{
set_position(x,y+i);
for(j=0;j<76;j++) //其实清屏可以理解为输入很多空格也就是“” “”,里面数据可以自己灵活修改
printf(" ");
}
}
接下来就是全部的代码了
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#define sep "------------------------------------------------------------------------------"
#define left 20 //左边距
#define map_start 3 //地图开始Y坐标
#define map_end 11 //地图结束Y坐标
#define most 12 //信息界面开始Y坐标
#define info_end 18 //信息界面结束Y坐标
int number=1; //注册的玩家数量
int X=3,Y=5; //玩家所在位置初始化
//游戏道具-武器,上衣,下装,鞋子,药品,
typedef enum daoju_type
{
hands,chothes,pants,shoes,eats1,eats2,eats3
}Daoju_type;
typedef struct _daoju
{
int id; //道具编号
char name[30]; //道具名称
char level[20]; //道具品质
int number; //道具数量
double price; //道具价格
Daoju_type type; //道具类型
union{//联合-多选一
int attack; //如果是武器,对应攻击力
int defence; //如果是防具,就对应防御力
int powerhp; //增加血量
int powermp; //增加法力值
int exp; //增加经验
};
char desc[200]; //道具描述
}Daoju;
//地图枚举-门派,城池,宝地
typedef enum map_type
{
menpai,cheng,shan
}Map_type;
//地图结构
typedef struct _map
{
int id; //地图编号
char name[20]; //地图名字
int minlevel; //玩家进入的最低等级
COORD coord; //地图坐标,COORD是windows.h自带结构
Map_type type;
union{
char name1[10]; //多选一,地图属性
char name2[10];
char name3[10];
};
char desc[500]; //地图描述
}Map;
//背包结构
typedef struct _bag
{
int id; //背包所属玩家
int num; //背包道具数量
int maxs; //背包最大容量
Daoju daoju_s[12]; //装备
}Bag;
//玩家结构
typedef struct _player
{
int id; //玩家编号
char name[25]; //玩家姓名
char password[25]; //玩家密码
int level; //玩家等级
int rucheng; //玩家入城令数量
int attack; //玩家攻击力
int defence; //玩家防御力
int hp; //玩家最大血量
int nowhp; //玩家当前血量
int mp; //玩家最大法力值
int nowmp; //玩家当前法力值
double money; //玩家金币
Bag bag; //玩家背包
}Player;
//怪物结构
typedef struct _monster
{
int id; //怪物编号
char name[25]; //怪物名字
char level[20]; //怪物级别
COORD coord; //怪物级别
int hp;
int diaoluo; //怪物掉落道具编号
int exp; //杀死后获得经验
int money; //杀死后获得金币
}Monster;
//初始化道具
Daoju daojus[]={
{0,"入城令","【道具】",1000,1000,hands, .attack=3,"进入城池必备道具。"},
{1,"朴刀","【白装】",100,1000,hands, .attack=3,"介于单手或双手的武器,可以简单防身!"},
{2,"短弓","【白装】",100,1000,hands, .attack=3,"远程武器,可用于射雁!"},
{3,"青铜剑","【绿装】",50,2000,hands, .attack=6,"由青铜炼制的古剑,削铁如泥,极度锋利!"},
{4,"墨羽扇","【绿装】",50,2000,hands, .attack=6,"谈笑风生,是身份的象征!"},
{5,"丈八蛇矛","【蓝装】",30,5000,hands, .attack=10,"这一支丈八蛇矛,矛尖有如白蛇吐信,重达五十多斤的矛身,在黑色的锦絮飞舞中横扫战场,挑敌破甲,矛尖向敌阵一投,便有一名敌将被刺死在丈八蛇矛之下,是令敌将闻风丧胆的象征。"},
{6,"青龙偃月刀","【蓝装】",30,5000,hands, .attack=10,"在传说中,天下第一铁匠只选月圆之夜打造青龙偃月刀。快完工时,骤然之间风起云涌,从空中滴下1780滴鲜血。"},
{7,"方天画戟","【紫装】",10,10000,hands, .attack=20,"方天戟上以画、镂等作为装饰,又称方天画戟。方天画戟属于重兵器,和矛,枪等轻兵器不同。方天戟使用复杂,功能多,需要极大的力量和技巧,集轻兵器和重兵器功能于一身。"},
{8,"干将莫邪","【紫装】",10,10000,hands, .attack=20,"干将莫邪为晋君作剑,三年而成,剑有雌雄,天下名器也。"},
{9,"苍天帝剑","【金装】",5,50000,hands, .attack=50,"此剑为天地所铸,铸成之日,斗转星移,日升日落,万里之内神光漫天!"},
{10,"九天龙魂贯","【金装】",5,50000,hands, .attack=50,"此器由龙骨所化,蕴含着真龙不死不灭之气,非英豪不能驾驭!"},
{11,"鸿蒙造化炉","【神器】",1,100000,hands, .attack=100,"宇宙为成,而鸿蒙初开,传说此炉是天地之本,万物之主!"},
{12,"混沌开天斧","【神器】",1,100000,hands, .attack=100,"传说为盘古开天地是所用斧子,有无尽威能,有缘人可得之!"},
{13,"布衣","【白装】",100,1000,chothes, .defence=3,"由布做的麻衣,可以御寒,穿起来也挺舒服。"},
{14,"皮裤","【白装】",100,1000,pants, .defence=3,"猎人使用野兽毛皮缝制的裤子,穿起来十分威武。"},
{15,"雨鞋","【白装】",100,1000,shoes, .defence=3,"可以在下雨天有效行走,不惧风雨。"},
{16,"黑甲","【绿装】",50,2000,chothes, .defence=6,"黑铁打造的战甲,刀枪不入,是军队使用的装备。"},
{17,"漠河裤","【绿装】",50,2000,pants, .defence=6,"用料奇特,手法惊人,五品官以下统一穿着,是身份的象征。"},
{18,"疾步鞋","【绿装】",50,2000,shoes, .defence=6,"不动则已,一动飞天,是行走江湖必备鞋子。"},
{19,"锁子甲","【蓝装】",30,5000,chothes, .defence=10,"禁卫军专用战衣,杀气十足,敌人闻风而逃。"},
{20,"琉璃裤","【蓝装】",30,5000,pants, .defence=10,"五光十色,光彩夺目,皇室花重金打造。"},
{21,"梯云鞋","【蓝装】",30,5000,shoes, .defence=10,"武当梯云宗,走路很轻松。"},
{22,"修仙道袍","【紫装】",10,10000,chothes, .defence=20,"修仙者穿的道袍,可以抚平心境,修仙有望!"},
{23,"光武战裤","【紫装】",10,10000,pants, .defence=20,"上古炼体士打造的装备,配合炼体士可以绽放无限威能。"},
{24,"碧水寒光鞋","【紫装】",10,10000,shoes, .defence=20,"可上天入地,下海,进地府,无地不可去。"},
{25,"八门金索甲","【金装】",5,50000,chothes, .defence=50,"八门齐开,全身附带迷阵,能有效迷惑敌人。"},
{26,"霓虹登仙裳","【金装】",5,50000,chothes, .defence=50,"上古时期,传说有仙人飞升,古器师取飞升之气炼制此衣,万法不侵!"},
{27,"补血丸","【药丸】",100,1000,eats1, .powerhp=100,"可以增加血量,受伤时可以用于恢复血量。"},
{28,"补气丸","【药丸】",100,1000,eats2, .powermp=100,"可以增加法力,受伤时可以用于恢复法力。"},
{29,"万人丹","【灵丹】",50,2000,eats1, .powerhp=200,"可以增加大量生命值,受伤时可以用于恢复生命值。"},
{30,"冲泉丹","【灵丹】",50,2000,eats2, .powermp=200,"可以增加大量法力,受伤时可以用于恢复大量法力。"},
{31,"天涯金丹","【金丹】",30,5000,eats1, .powerhp=300,"可以巨幅增加生命值,受伤时可以用于恢复血量。"},
{32,"天雷金丹","【金丹】",30,5000,eats2, .powermp=300,"可以巨幅增加法力值,受伤时可以用于恢复法力。"},
{33,"九转金丹","【金丹】",30,5000,eats3, .exp=300,"可以巨幅增加经验。"},
{34,"造化仙丹","【仙丹】",10,50000,eats1, .powerhp=1000,"造化万物,丹通天地,此丹可以说是人世间的极致。"},
{35,"万古仙丹","【仙丹】",10,50000,eats2, .powermp=1000,"此丹历经九九八一劫,滋生灵智。"},
{36,"大梦三千","【仙丹】",10,50000,eats3, .exp=3000,"梦中悟道,大梦三千。"}
};
//初始化地图
Map maps[8][8]={
{
{1,"丐帮",0,{0,0},menpai, .name1="【门派】","有人的地方便有丐帮的存在,可以说丐帮是江湖中消息最灵通的帮派,不过该派弟子也有强者,不可小觑。"},
{2,"西凉",0,{1,0},cheng, .name2="【城池】","西凉,古时也叫凉州,因为地理位置的重要,凉州便成为丝路重镇和经济交流的都会,同时也决定了其深厚的文化积淀。凉州自古多安定。古谣云:“秦川中,血没腕,唯有凉州倚柱观。”凉州百姓爱好和平,从不排外,能忍辱负重,讲究“吃亏是福”,商贾往来,从不欺凌,渐成经济文化重镇。"},
{3,"陇右",0,{2,0},cheng, .name2="【城池】","陇右地区位处黄土高原西部,界于青藏、内蒙、黄土三大高原结合部,自然条件独特;历史上无论是政区划分、民族分布、人口构成还是经济形态、民风民俗,均有较多联系和相似之处,是一个相对完整的自然、人文地域单元。"},
{4,"地心眼",2,{3,0},shan, .name3="【奇地】","地心眼位于大盆地之中,有一洞口,极为又黑,传说中可以通向大地之心,也有人说这里是通往另一个世界的入口,众说纷纭。没有人能知道它究竟通向何方,地魔古教之人常常在此游荡。"},
{5,"地魔古教",25,{4,0},menpai, .name1="【门派】","信奉大地之母。派中秘典两极大法,可以将地壳深处的元磁之气炼入躯体形成磁场,如果未练同种功法的人靠近其百丈范围,都会感到功法运转不灵,极端不适。因此该教派极难渗透,在修行界都非常神秘。"},
{6,"龙丘",2,{5,0},shan, .name3="【奇地】","龙丘之名来源很多,有人说此地蕴藏龙穴,也有人说这里是埋龙之地。其实最让人信服的是上古隐士龙丘君隐居于此,因以为名,"},
{7,"流沙",2,{6,0},shan, .name3="【奇地】","上古从横世家双雄之一的卫庄君曾经在此地悟道,道成之时,黄沙漫天,遮天蔽日,久久不散,传说其中包含着纵横圣道,所有无人能将之彻底消除。"},
{8,"子午谷",5,{7,0},shan, .name3="【奇地】","曲径可通幽,空谷声不绝。这里是造物主的奇迹。传说此地有称君者隐居。"}
},
{
{9,"金牛山",5,{0,1},shan, .name3="【奇地】","金牛山高耸漠地,为北方第一山脉,山上多豺狼虎豹,不过因为环境容易生长草药,所以很多炼丹师来此地采药,各门派都有人来此历练。"},
{10,"紫霞洞天",20,{1,1},menpai, .name1="【门派】","上清于人间界嫡传,坐落于丹霞山绝顶,乃是正道砥柱。丹霞派精通法宝炼制之术,派中镇派十大神剑皆为紫装以上的无上神兵,各门派都与之交好"},
{11,"街亭",0,{2,1},cheng, .name2="【城池】","街亭,历史悠久,文化底蕴深厚。是兵家必争之地。"},
{12,"咸阳",0,{3,1},cheng, .name2="【城池】","咸阳乃龙脉之地,人杰地灵,很多有名的称君者都来过此地,是江湖中有名的圣地"},
{13,"阳平",0,{4,1},cheng, .name2="【城池】","阳平,临近咸阳,传说以前隶属咸阳,后来在战争中导致割据两地。"},
{14,"定陶",0,{5,1},cheng, .name2="【城池】","定陶是铁器产出地,多矿脉。"},
{15,"御尸宗",10,{6,1},menpai, .name1="【门派】","门派擅长操控尸体,百年前该宗之人时常偷盗那些生前武艺高强之人的尸体,遭所有人诟病,所以被丹霞洞天斩尽杀绝,现在该派弟子都不敢暴露自己。隐居深山。"},
{16,"景君洞窟",10,{7,1},shan, .name3="【奇地】","此地因景君而得名。历史记载,景君便是在此地以杀戮成道。洞窟内魂魄极多,不得超生。"}
},
{
{17,"青龙塔",20,{0,2},shan, .name3="【奇地】","青龙塔内封印着青龙投影。"},
{18,"青龙潭",10,{1,2},shan, .name3="【奇地】","此地藏有蛟龙,又因离青龙塔相近,顾得名青龙潭。"},
{19,"成都",0,{2,2},cheng, .name2="【城池】","成都之名由来已久,在巴蜀之地,居民多性格豪爽。"},
{20,"凡门",0,{3,2},menpai, .name1="【门派】","“凡体便霸体”这句话出自凡门第一人掌门,传说他出生后筋脉尽废,但却依旧凭借着他的努力,成为陆地神仙般的人物。凡门招收弟子不限天赋,这也导致了门派弟子繁多,但很难出天才人物。"},
{21,"新野",0,{4,2},cheng, .name2="【城池】","新野之地多草原,“有野火烧不尽,春风吹又生。”的美誉。"},
{22,"汝南",0,{5,2},cheng, .name2="【城池】","传言汝南原本是一片山脉,不知什么原因现在变成一一片平原。"},
{23,"徐州",0,{6,2},cheng, .name2="【城池】","徐州是鱼米之乡,一方水土养一方人,女子多貌美如花,男子亦分外俊朗。"},
{24,"天丹阁",5,{7,2},menpai, .name1="【门派】","百年前,众多爱好炼丹之士齐聚此地,开天丹会盟,会中丹君了悟丹道,为纪念此次聚会,丹君在此地建立门派,史称天丹阁。"}
},
{
{25,"云州",0,{0,3},cheng, .name2="【城池】","云州是丝绸产地,牛羊极多。"},
{26,"云梦泽",55,{1,3},shan, .name3="【奇地】","云梦之地是古时云梦仙子隐居之地,现在是药王世家在此悬壶济世。"},
{27,"昆仑宫",25,{2,3},menpai, .name1="【门派】","玉清元始所传人间道统,雄踞龙脉祖庭昆仑山之麓,乃是正道砥柱。昆仑派所修玉清仙法以法力雄浑见长,其门人弟子众多,可称正道第一大派。门派弟子多行侠仗义,游历江湖!"},
{28,"百花邬",2,{3,3},shan, .name3="【奇地】","我花开后百花杀,这是一个十分奇异的世界。"},
{29,"落凤岭",10,{4,3},shan, .name3="【奇地】","传说当年白虎与凤凰在此地大战,有凤凰真血在此地洒落,所有被称作落凤岭。"},
{30,"白虎塔",20,{5,3},shan, .name3="【奇地】","白虎塔内封印着白虎投影。"},
{31,"青州",0,{6,3},cheng, .name2="【城池】","青州是人口之州,面积广阔,有很多人都喜欢来青州旅游,踏青。"},
{32,"飞升古碑",10,{7,3},shan, .name1="【奇地】","传说这里是曾经是百年前洪天居也就玉京天君飞升之地,很多侠客都慕名前来,希望能够一窥飞升之谜,也有人说碑中留有玉京天君的武功秘籍,引来无数人围观参悟!"}
},
{
{33,"剑冢",5,{0,4},shan, .name3="【奇地】","剑者,兵中帝君。"},
{34,"刀墓",5,{1,4},shan, .name3="【奇地】","刀者,器中之皇。"},
{35,"玉州",0,{2,4},cheng, .name2="【城池】","玉州是玉京天君洪天居的出生地,传说天君留有传承。"},
{36,"灵山",2,{3,4},shan, .name3="【奇地】","此地灵气浓郁,是个宝地。"},
{37,"极天宫",15,{4,4},menpai, .name1="【门派】","亦正亦邪,地处天极峰的隐世门派,派中只收俊男美女。其门派秘法以情入道,先有情后忘情,以此臻至太上境界,给修行界留下众多痴男怨女。太上无情,太上斩情!"},
{38,"毒龙潭",5,{5,4},shan, .name3="【奇地】","毒蝎子成精在此地为非作歹,自称为毒龙,脸皮十分厚。"},
{39,"虞山",2,{6,4},shan, .name3="【奇地】","此处为上古虞美人埋骨之地。"},
{40,"华州",0,{7,4},cheng, .name2="【城池】","“物华天宝”说的便是此地。"}
},
{
{41,"墨城",0,{0,5},cheng, .name2="【城池】","墨家提倡剪爱,非攻。信仰侠客之道,在此地颇有名望。"},
{42,"剑峡",5,{1,5},shan, .name3="【奇地】","传说是纵横双雄之一的盖聂君练剑之地。"},
{43,"六仙山",6,{2,5},shan, .name3="【奇地】","山上有六座怪石,呈仙人指路状,故得名六仙山。"},
{44,"逍遥谷",0,{3,5},menpai, .name1="【门派】","逍遥派在此隐居,因为逍遥派修行逍遥心法,所有弟子都崇尚自由与无拘无束,门派比较松散,发展到现在可以说是一脉单传。不过虽然该派弟子极少,但却是上古逍遥天宫分支,不可轻视!"},
{45,"蓬莱岛",20,{4,5},shan, .name3="【奇地】","蓬莱岛传说被巨龟百岳所驮,所以飘忽不定,有缘人方可寻到。岛上相传有长生不老药。"},
{46,"长安",0,{5,5},cheng, .name2="【城池】","古都城长安,龙脉之地,有龙腾九天之气象。"},
{47,"东海",10,{6,5},shan, .name3="【奇地】","东海之地,多水怪,传说海底有龙宫。龙宫之内有龙王,不过具体真伪不得而知。"},
{48,"酆都",0,{7,5},cheng, .name2="【城池】","酆都,也叫做鬼城,此地之人修炼鬼道,食人魂魄。"}
},
{
{49,"地精洞",3,{0,6},shan, .name3="【奇地】","地底精灵出入口。"},
{50,"朱雀塔",20,{1,6},shan, .name3="【奇地】","朱雀塔内封印着朱雀投影"},
{51,"雷州",0,{2,6},cheng, .name2="【城池】","此地多降雨。并且矿产十分多,这也是常常引来雷电的原因。"},
{52,"七杀魔殿",15,{3,6},menpai, .name1="【门派】","七杀魔殿地址十分隐蔽,门派修炼七杀心法,杀气十足,修改此功的人都性格暴躁,极端嗜杀,所有被江湖上所有正道仇视。不过一般人也不敢得罪此派,所以也无法遏制它的发展!"},
{53,"黑泉",8,{4,6},shan, .name3="【奇地】","火山洞口,温度极高,铁石化为液状,得名黑泉。"},
{54,"樊城",0,{5,6},cheng, .name2="【城池】","小城镇,不是特别有名,多为军队驻扎。"},
{55,"豹子林",66,{6,6},shan, .name3="【奇地】","野兽繁多,特别时豹妖。"},
{56,"崆峒山",5,{7,6},shan, .name3="【奇地】","山中有奇异力量,进入其中会使人忘记烦恼。"}
},
{
{57,"沧溟海",10,{0,7},shan, .name3="【奇地】","与东海齐名,不过传说不归龙族管理,真相不得而知。"},
{58,"玉门关",0,{1,7},cheng, .name2="【城池】","边关,传说是人族与妖族的分界,是所有人族抵御妖蛮的重地。"},
{59,"瀛洲岛",5,{2,7},shan, .name3="【奇地】","此地人口繁多,身体矮小,智商不高,疑是遭到血脉禁锢。"},
{60,"玄武塔",20,{3,7},shan, .name3="【奇地】","玄武塔内封印着玄武投影。"},
{61,"九天宫",10,{4,7},menpai, .name1="【门派】","该门派只招女子,传说该门派祖师最是痛恨男子,所有也间接影响了她的弟子,于是就这样一直发展到现在。也培养出了很多精英弟子,同样在江湖行侠仗义。美女极多,很适合历练!"},
{62,"桂林",0,{5,7},cheng, .name2="【城池】","“桂林山水甲天下”山水是桂林的神奇之处,传说每座山、每条河都有灵智。"},
{63,"建业",0,{6,7},cheng, .name2="【城池】","第二军事要地。"},
{64,"归园田居",10,{7,7},shan, .name3="【奇地】","传说是陶君隐居之地。"}
}
};
Player plays[]={
{1,"玉京天君","2584456944",100,100,1000,1000,10000,10000,10000,10000,1000000,{1,0,12,}},
};
char chenghao[11][20]={"凡人","练气士","武者","武魁","武师","武神","道尊","道皇","君者","道君","天君"};
//初始化怪物
Monster mosters[]={
{1,"地痞流氓","【凡人】",{0,},100,0,100,100},
{2,"地痞流氓","【练气士】",{0,},500,0,500,500},
{3,"地痞流氓","【凡人】",{1,},100,0,100,100},
{4,"地痞流氓","【凡人】",{1,},100,0,100,100},
{5,"地痞流氓","【凡人】",{2,},100,0,100,100},
{6,"地痞流氓","【凡人】",{2,},100,0,100,100},
{7,"地痞流氓","【凡人】",{3,},100,0,100,100},
{8,"地痞流氓","【练气士】",{3,},500,0,500,500},
{9,"地痞流氓","【凡人】",{4,},100,0,100,100},
{10,"地痞流氓","【凡人】",{4,},100,0,100,100},
{11,"地痞流氓","【武者】",{5,},1000,0,1000,1000},
{12,"地痞流氓","【凡人】",{5,},100,0,100,100},
{13,"地痞流氓","【武者】",{6,},1000,0,1000,1000},
{14,"地痞流氓","【凡人】",{7,},100,0,100,100},
{15,"官军","【练气士】",{0,},100,0,100,100},
{16,"官军","【武者】",{1,},500,0,500,500},
{17,"官军","【凡人】",{5,},100,0,100,100},
{18,"官军","【武者】",{2,},500,0,500,500},
{19,"官军","【练气士】",{2,},100,0,100,100},
{20,"官军","【凡人】",{3,},100,0,100,100},
{21,"官军","【武者】",{3,},500,0,500,500},
{22,"官军","【凡人】",{4,},100,0,100,100},
{23,"官军","【凡人】",{4,},100,0,100,100},
{24,"官军","【武者】",{5,},500,0,500,500},
{25,"官军","【凡人】",{7,},100,0,100,100},
{26,"官军","【凡人】",{7,},100,0,100,100},
{27,"山贼","【凡人】",{1,},100,0,500,500},{28,"山贼","【武者】",{1,},1000,0,1000,1000},
{29,"山贼","【凡人】",{5,},100,0,500,500},{30,"山贼","【凡人】",{2,},100,0,500,500},
{31,"山贼","【练气士】",{6,},500,0,500,500},{32,"山贼","【凡人】",{3,},100,0,500,500},
{33,"山贼","【凡人】",{2,},100,0,500,500},{34,"山贼","【练气士】",{4,},500,0,500,500},
{35,"流浪剑客","【练气士】",{1,},500,0,500,500},
{36,"流浪剑客","【练气士】",{1,},500,0,500,500},
{37,"流浪剑客","【武者】",{2,},1000,0,1000,1000},
{38,"流浪剑客","【武者】",{2,},1000,0,1000,1000},
{39,"流浪剑客","【练气士】",{3,},500,0,500,500},
{40,"流浪剑客","【练气士】",{3,},500,0,500,500},
{41,"流浪剑客","【武者】",{4,},1000,0,1000,1000},
{42,"流浪剑客","【练气士】",{4,},500,0,500,500},
{43,"流浪剑客","【练气士】",{5,},500,0,500,500},
{44,"流浪剑客","【武者】",{5,},1000,0,1000,1000},
{45,"流浪剑客","【练气士】",{6,},500,0,500,500},
{46,"流浪剑客","【练气士】",{6,},500,0,500,500},
{47,"流浪剑客","【武魁】",{7,},2000,12,2000,2000},
{48,"流浪剑客","【练气士】",{7,},500,0,500,500},
{49,"流浪剑客","【武魁】",{0,},2000,3,2000,2000},
{50,"流浪剑客","【练气士】",{0,},500,0,500,500},
{51,"妖族间谍","【武者】",{1,},1000,0,1000,1000},
{52,"妖族间谍","【武者】",{4,},1000,0,1000,1000},
{53,"妖族间谍","【武魁】",{6,},2000,12,1000,1000},
{53,"妖族间谍","【武者】",{4,},1000,0,1000,1000},
{55,"妖族间谍","【武魁】",{1,},2000,13,1000,1000},
{56,"妖族间谍","【武者】",{0,},1000,0,1000,1000},
{57,"妖族间谍","【武魁】",{5,},1000,14,1000,1000},
{58,"妖族间谍","【武者】",{4,},1000,0,1000,1000},
{59,"妖族间谍","【武魁】",{7,},2000,16,1000,1000},
{60,"妖族间谍","【武者】",{4,},1000,0,1000,1000},
{61,"妖族间谍","【武者】",{0,},1000,0,1000,1000},
{62,"巡查将军","【武师】",{7,},3000,8,3000,3000},
{63,"巡查将军","【武师】",{7,},3000,2,3000,3000},
{64,"灵族通剑","【武神】",{6,},4000,16,4000,4000},
{65,"灵族通刀","【武神】",{5,},4000,15,4000,4000},
{66,"鬼帅","【道尊】",{4,},5000,8,5000,5000},
{67,"鬼将军","【道尊】",{3,},5000,22,5000,5000},
{68,"影杀者","【道皇】",{1,},6000,35,6000,6000},
{69,"暗精灵","【道皇】",{2,},6000,34,6000,6000},
{70,"隐居怪客","【君者】",{0,},7000,11,7000,7000},
{71,"背剑狂君","【君者】",{6,},7000,10,7000,7000},
};
//游戏名字界面
void showhello()
{
set_color(12,0);
set_position(left,0);
printf(sep);
set_position(left,1);
printf("|");
set_position(left+33,1);
printf("笑傲江湖之鸿蒙");
set_position(left+77,1);
printf("|");
set_position(left,2);
printf(sep);
}
//地图界面
void showmap()
{
set_color(2,0);
int i,j;
for(i=0;i<8;i++)
{
set_position(left,map_start+i);
printf("| ");
for(j=0;j<8;j++)
{
if(i==Y&&j==X)
{
set_color(14,0);
}
printf("%-9s",maps[i][j].name);
set_color(2,0);
}
printf(" |");
}
set_position(left,map_end);
printf(sep);
}
//信息界面
void showinformation()
{
set_color(3,0);
int i;
for(i=0;i<7;i++)
{
set_position(left,map_end+i+1);
printf("|");
set_position(left+77,map_end+i+1);
printf("|");
}
set_position(left,info_end);
printf(sep);
}
//地图信息
void mapinfo()
{
cclear(left+1,most,6);
set_color(3,0);
set_position(left+25,most);
printf("当前玩家所在地图为:【%s】",maps[Y][X].name);
set_position(left+10,most+1);
char *desc=maps[Y][X].desc;
int desclen=strlen(desc);
int i;
for(i=0;i<desclen;i++)
{
if(i!=0&&(i%60)==0)
{
set_position(left+10,most+1+i/60);
}
printf("%c",desc[i]);
}
}
void yidong()
{
char key;
while(1)
{
key=getch();
if(key=='1'||key=='2')
{
xingdong(key);
}
else if(key==75) //左
{
X--;
}
else if(key==72) //上
{
Y--;
}
else if(key==77) //右
{
X++;
}
else if(key==80) //下
{
Y++;
}
if(X>7) X=0;
if(X<0) X=7;
if(Y>7) Y=0;
if(Y<0) Y=7;
showmap();
//mapinfo();
menu1();
}
}
//登录界面1
void denglu()
{
showhello();
set_color(2,0);
int i;
int caozuo;
for(i=0;i<8;i++)
{
set_position(left,map_start+i);
printf("| ");
set_position(left+77,map_start+i);
printf("|");
}
set_position(left,map_end);
printf(sep);
set_position(left+30,map_start+2);
printf("1.新侠客注册身份");
set_position(left+30,map_start+4);
printf("2.老侠客重出江湖");
set_position(left+1,most);
printf("请选择操作:");
scanf("%d",&caozuo);
if(caozuo==1)
log1();
if(caozuo==2)
log2();
}
//注册账号
void log1()
{
void kaishi();
char username[25];
char password[25];
cclear(left+1,map_start+1,7);
set_position(left+16,map_start+2);
getchar();
printf("用户名:");
gets(username);
set_position(left+16,map_start+4);
printf("密码:");
gets(password);
number++;
plays[number-1].id=number;
strcpy(plays[number-1].name,username);
strcpy(plays[number-1].password,password);
plays[number-1].level=1;
plays[number-1].rucheng=0;
plays[number-1].attack=10;
plays[number-1].defence=10;
plays[number-1].hp=200;
plays[number-1].nowhp=200;
plays[number-1].nowmp=200;
plays[number-1].mp=200;
plays[number-1].money=1000;
plays[number-1].bag.id=number;
plays[number-1].bag.num=0;
plays[number-1].bag.maxs=12;
set_position(left+16,map_start+5);
printf("恭喜少侠注册成功!按任意键可正式进入游戏!");
set_position(left+1,most);
system("pause");
cclear(left+1,map_start+1,7);
set_position(left+15,map_start+1);
kaishi();
set_position(left+1,most);
system("pause");
system("cls");
showhello();
showmap();
showinformation();
// mapinfo();
menu1();
yidong();
}
void kaishi()
{
char desc[500]={"百年前,玉京天君洪天居以一己之力夺得天命,击败所有同时代的修仙者。荡平人间所有黑暗,妖界只能俯首称臣!从那之后便销声匿迹,有人说他已经窥得飞升之道,已经成仙,也有人说他在以一人之力抗衡妖界终究受了严重的伤,所有早已去世!不过真相如何已经不得而知,百年后的现在\
就要看少侠如何力挽狂澜。扶大厦之将倾。逍遥谷便是少侠的崛起之地。"};
int desclen=strlen(desc);
int i;
for(i=0;i<desclen;i++)
{
if(i!=0&&(i%60)==0)
{
set_position(left+10,map_start+1+i/60);
}
printf("%c",desc[i]);
}
}
//老用户登录
void log2()
{
int i;
char name[25];
char password[25];
cclear(left+1,map_start+1,7);
set_position(left+16,map_start+2);
getchar();
printf("用户名:");
gets(name);
set_position(left+16,map_start+4);
printf("密码:");
gets(password);
for(i=0;i<number;i++)
{
if(strcmp(name,plays[i].name)==0&&strcmp(password,plays[i].password)==0)
{
set_position(left+16,map_start+5);
printf("欢迎大侠重归江湖!按任意键可正式进入游戏!");
set_position(left+1,most);
system("pause");
system("cls");
showhello();
showmap();
showinformation();
menu1();
//mapinfo();
yidong();
}
}
set_position(left+16,map_start+5);
printf("用户名或密码错误!");
set_position(left+1,most);
system("pause");
system("cls");
denglu();
}
//退出游戏函数
void gameover()
{
system("cls");
showhello();
set_color(2,0);
int i;
for(i=0;i<8;i++)
{
set_position(left,map_start+i);
printf("| ");
set_position(left+77,map_start+i);
printf("|");
}
set_position(left,map_end);
printf(sep);
set_position(left+16,map_start+4);
printf(" G A M E O V E R ");
set_position(left,most);
}
//菜单函数
void menu1()
{
set_color(3,0);
cclear(left,info_end+1,7);
set_position(left+1,info_end+1);
printf("游戏菜单:");
set_position(left+1,info_end+2);
printf("1.进入其中");
set_position(left+1,info_end+3);
printf("2.退出游戏");
set_position(left+1,info_end+4);
printf("上下左右键控制地图移动,数字键控制菜单");
printf("\t");
}
//进入菜单
void menu2()
{
int key;
cclear(left,info_end+1,7);
set_position(left+1,info_end+1);
printf("游戏菜单:");
set_position(left+1,info_end+2);
printf("1.查看自身状态");
set_position(left+1,info_end+3);
printf("2.搜索(探查)");
set_position(left+1,info_end+4);
printf("3.打坐恢复");
set_position(left+1,info_end+5);
printf("4.购买道具");
set_position(left+1,info_end+6);
printf("5.返回");
set_position(left+1,info_end+7);
printf("请选择操作:");
scanf("%d",&key);
switch(key)
{
case 1:
player_imfomation();
break;
case 2:
daye();
break;
case 3:
plays[number-1].nowhp=plays[number-1].hp;
plays[number-1].nowmp=plays[number-1].mp;
cclear(left+1,most,6);
set_color(3,0);
set_position(left+5,most+3);
printf("只见天地之间灵气汇聚而来!少侠顿时神清气爽!");
break;
case 4:
buy();
break;
case 5:
break;
}
}
//进入判定函数
void xingdong(char x)
{
if(x=='1')
{
if(plays[number-1].rucheng==0&&maps[Y][X].type==cheng)
{
cclear(left+1,map_start,8);
set_position(left+30,map_start+2);
printf("入城令不足!无法进入!");
set_position(left+30,map_start+4);
system("pause");
}
if(maps[Y][X].type==shan||maps[Y][X].type==menpai)
{
if(plays[number-1].level<maps[Y][X].minlevel)
{
cclear(left+1,map_start,8);
set_position(left+30,map_start+2);
printf("少侠江湖阅历不足哦!还是以后再进此地吧!");
set_position(left+30,map_start+4);
system("pause");
}
else
{
mapinfo();
menu2();
}
}
if(plays[number-1].rucheng>0&&maps[Y][X].type==cheng)
{
plays[number-1].rucheng--;
mapinfo();
menu2();
}
}
if(x=='2')
{
gameover();
exit(0);
}
}
//人物信息显示函数
void player_imfomation()
{
int i;
cclear(left+1,most,6);
set_color(3,0);
set_position(left+5,most);
printf("姓名:");printf("%-10s",plays[number-1].name);
printf("等级:");printf("%-4d ",plays[number-1].level);
printf(" 称号:%-8s",chenghao[plays[number-1].level/10]);
printf("金币:%-10.2lf\t",plays[number-1].money);
set_position(left+5,most+1);
printf("入城令:%-4d",plays[number-1].rucheng);
printf("攻击力:%-10d",plays[number-1].attack);
printf("防御力:%-10d",plays[number-1].defence);
printf("生命值:%-10d",plays[number-1].nowhp);
set_position(left+5,most+2);
printf("装备:\t\t\t \t");printf("法力值:%-10d",plays[number-1].nowmp);
set_position(left+5,most+3);
for(i=0;i<plays[number-1].bag.num;i++)
{
printf("%-10s\t",plays[number-1].bag.daoju_s[i].name);
if(i%4==0)
set_position(left+5,most+3+(i/4));
}
}
//购买装备函数
void buy()
{
cclear(left+1,most,6);
set_color(3,0);
int a[20];
int i,j;
int x;
srand((unsigned)time(NULL));
for(i=0;i<20;i++)
{
if(i%4==0)
set_position(left+1,most+i/4);
a[i]=rand()%36;
printf("%-2d%s(%d)\t",daojus[a[i]].id,daojus[a[i]].name,daojus[a[i]].number);
}
set_position(left+1,most+5);
printf("输入武器前面的编号来选择您想购买的装备:");
scanf("%d",&x);
if(plays[number-1].money<daojus[x].price)
{
set_position(left+48,most+5);
printf("金币不足!购买失败!");
}
else if(plays[number-1].bag.num==12)
{
set_position(left+48,most+5);
printf("背包已满!购买失败!");
}
else
{
set_position(left+48,most+5);
printf("购买成功!");
daojus[x].number--;
strcpy(plays[number-1].bag.daoju_s[plays[number-1].bag.num].name,daojus[x].name);
plays[number-1].bag.num++;
if(daojus[x].type==hands)
{
plays[number-1].attack+=daojus[x].attack;
plays[number-1].money-=daojus[x].price;
}
if(daojus[x].type==chothes||daojus[x].type==pants||daojus[x].type==shoes)
{
plays[number-1].defence+=daojus[x].defence;
plays[number-1].money-=daojus[x].price;
}
if(daojus[x].type==eats1)
{
plays[number-1].hp+=daojus[x].powerhp;
plays[number-1].money-=daojus[x].price;
}
if(daojus[x].type==eats2)
{
plays[number-1].mp+=daojus[x].powermp;
plays[number-1].money-=daojus[x].price;
}
if(daojus[x].type==eats3)
{
plays[number-1].level+=daojus[x].exp;
plays[number-1].money-=daojus[x].price;
plays[number-1].bag.num++;
}
}
}
void daye()
{
int num=0;
int caozuo;
cclear(left+1,most,6);
set_position(left+1,most);
int count=sizeof(mosters)/sizeof(Monster);
for(int i=0;i<count;i++)
{
if(mosters[i].coord.X==X)
{
printf("%d%s%s ",mosters[i].id,mosters[i].name,mosters[i].level);
num++;
if(num%4==0)
{
set_position(left+1,most+num/4);
}
}
}
set_position(left+1,most+4);
printf("请选择要战斗的野怪编号(按0退出):");
scanf("%d",&caozuo);
if(caozuo==0)
menu2();
else
{
for(int i=0;i<count;i++)
{
if(caozuo==mosters[i].id)
{
if(plays[number-1].hp<plays[number-1].nowhp)
{
set_position(left+10,most+5);
printf("少侠已经受伤!请休息后再来吧!");
}
else if(plays[number-1].hp<mosters[i].hp)
{
set_position(left+10,most+5);
printf("对方武艺高强,不建议战斗!等您以后再挑战他吧!");
}
else
{
plays[number-1].nowhp-=mosters[i].hp;
plays[number-1].nowmp-=mosters[i].hp;
plays[number-1].money+=mosters[i].money;
plays[number-1].level+=(mosters[i].exp)/plays[number-1].level;
set_position(left+10,most+5);
printf("挑战成功!获得%d经验!%d金币!掉落《%s》",mosters[i].exp,mosters[i].money,daojus[mosters[i].diaoluo].name);
if(mosters[i].diaoluo==0)
plays[number-1].rucheng++;
else
{
strcpy(plays[number-1].bag.daoju_s[plays[number-1].bag.num].name,daojus[mosters[i].diaoluo].name);
plays[number-1].bag.num++;
}
}
}
}
}
}
int main()
{
set_title("笑傲江湖之鸿蒙");
denglu();
return 0;
}
如果代码有问题的话,我这里有工程文件
笑傲江湖之鸿蒙工程文件
提取码:6uos