C语言,RPG小游戏

老九C语言教程最后的笑傲江湖.

算是在编程门槛外面的深呼吸热身练习,基本上都是老九的那一套。

gamelib.h

#ifndef GAMELIB_H_INCLUDED
#define GAMELIB_H_INCLUDED
#include

void setColor(int, int);
void setPosition(int, int);
void setTitle();
void getKey();
void Clear();
void ClearInfo(int,int);
void ClearInfo2();
void StringPrint(char*);

#endif

gamelib.c

#include"gamelib.h"
void setPosition(int x, int y)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord = { x,y };
	SetConsoleCursorPosition(handle, coord);
}
void setTitle()
{
	char*ch = "维斯特洛大陆";
	SetConsoleTitle(ch);
}
void setColor(int x, int y)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(handle, x + y * 0x10);
}
void Clear()
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD written;
	COORD coord = { 0,0 };
	FillConsoleOutputCharacter(handle, '  ', 125 * 30, coord, &written);//LP代表指针变量
}
void ClearInfo(int x, int y)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD written;
	COORD coord = { x,y };
	FillConsoleOutputCharacter(handle,' ', 120 * 12, coord, &written);
}
void ClearInfo2()
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD written;
	COORD coord = {12,8};
	FillConsoleOutputCharacter(handle, ' ', 120 * 6, coord, &written);
}
void StringPrint(char* homeInfo)
{
	int i;
	for (i = 0; i < strlen(homeInfo); i++)
	{
		printf("%c", homeInfo[i]);
		_sleep(20);
	}
}

game.h

#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include
#include
#include
#include
#include
#include
#define SEP "**************************************************************"
#define MARGIN_X 12
#define MAP_Y 2
#define INFO_Y 8
#define MENU_Y 15
#define END 20
typedef enum _type {
	Weapon=1,Armor=2,Consumables=3
}PropType;
typedef struct _prop {
	int id;
	char name[50];
	int level;
	PropType type;
	int stock;
	union 
	{
		int minAtt;
		int minDef;
		int minCon;
	};
	union
	{
		int maxAtt;
		int maxDef;
		int maxCon;
	};
	double price;
	char desc[500];
}Prop;
typedef struct _bag {
	int id;
	int count;
	int maxcount;
	Prop prop[6];//要在结构体内默认给个常量大小
}Bag;
typedef struct _home {
	int id;
	char name[50];
	COORD coord;
	char desc[500];
}Home;
typedef struct _player {
	int id;
	char userName[50];
	char passWord[50];
	int hp;
	int mp;
	int exp;
	int level;
	double price;
	Home home;
	Bag bag;
	Prop Weapon;
	Prop Armor;
}Player;
typedef struct _monster {
	int id;
	char name[50];
	int level;
	int hp;
	int att;
	int def;
	int minLoot;
	int maxLoot;
	int exp;
	int state;
	COORD mCoord;
	Prop prop;
}Monster;
void Start();
void LevelUp();
void ShowPlayer();
void Init();
void ShowMap();
void Poccess(char);
void ShowMonster();
void ShowTrade();
void ShowHome();
void ShowBattle(Player*,Monster*);
void Trade(Player*,int);
/*
if count

game.c

#include"game.h"
#include"gamelib.h"

char Map[5][5][16] = {
	{"红堡","暮鼓城","黑水城","奔流城","河间地"},
	{"铁群岛","多恩","龙石岛","北境长城","恐怖堡"},
	{"临冬城","凯岩城","高庭","鹰巢城","君临"},
	{"赫伦堡","水果岛","宝石都","史塔克","高达岛"},
	{"光明都","堕落成","鬼搁倒","烂泥","翅膀"}
};
Monster monsters[] = {
	{ 1, "鬼子", 1, 100, 5, 5, 1, 3, 10, 1,.mCoord.X = 0,.mCoord.Y = 0 },
	{ 1, "鬼子", 1, 100, 5, 5, 1, 3, 10, 1,.mCoord.X = 0,.mCoord.Y = 1 },
	{ 1, "鬼子", 1, 100, 5, 5, 1, 3, 10, 1,.mCoord.X = 0,.mCoord.Y = 7 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 0 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 1 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 2 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 3 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 4 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 5 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 2, "汉奸", 2, 200, 8, 12, 1, 8, 11, 1,.mCoord.X = 0,.mCoord.Y = 7 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 0 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 1 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 2 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 3 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 4 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 5 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 4, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 4, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 3, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 2, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 4, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 4, 300, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 6 },
	{ 3, "浪人", 4, 30000, 10, 10, 3, 8, 20, 1,.mCoord.X = 0,.mCoord.Y = 0 }
};
//若内部有子变量,对子变量单个声明的时需要加一个.
//对坐标变量声明时,一定要加上.,相当于独自声明
Prop propArray[] = {
	{ 1, "一字长蛇剑", 1, Weapon, 50,.minAtt = 7,.maxAtt = 15, 3000,"犹如巨蟒出击,攻击凌厉!" },
	{2,"二龙戏珠",2,Weapon,100,.minAtt = 3,.maxAtt = 5,4000,"试验品"},
	{ 3, "三叉海神戟", 3, Weapon, 10,.minAtt = 2,.maxAtt = 4, 3000, "重达十万八千斤,威力无穷!" },
	{ 4, "四方苦禅杖", 4, Weapon, 10,.minAtt = 2,.maxAtt = 4, 4000, "极度彰显了少林作为中原武林第一大派和佛门贵地的崇高地位。" },
	{ 5, "五虎攒羊锤", 5, Weapon, 10,.minAtt = 2,.maxAtt = 4, 5000, "唯有能与元素沟通的人可以唤醒它的真正力量。" },
	{ 6, "六合迎风枪", 6, Weapon, 10,.minAtt = 2,.maxAtt = 4,6000, "当年兵器谱排名第二,第一是小李他妈的飞刀!" },
	{ 7, "七星斩将矛", 7, Weapon, 10,.minAtt = 2,.maxAtt = 4,7000, "矛尖有如白蛇吐信,是令敌将闻风丧胆的象征!" },
	{ 8, "八卦金锁鞭", 8, Weapon, 10,.minAtt = 2,.maxAtt = 4,8000, "打在身上,仿佛是幻影涰连,遮日蔽天!" },
	{ 9, "九转乾坤圈", 9, Weapon, 10,.minAtt = 2,.maxAtt = 4,10000, "金色镯子,可翻江倒海,震荡乾坤!" },
	{ 100, "辟邪犀", 1, Armor, 10,.minDef=244,.maxDef=400,1000, "一块能解天下百毒的透明佩玉。" },
	{ 101, "乌蚕裙", 2, Armor, 10,.minDef=300,.maxDef=500, 2000, "极其坚韧,刀枪不入,水火不侵!" },
	{ 102, "英姿带", 3, Armor, 10,.minDef = 300,.maxDef = 500,3000, "穿后精气饱满,神采飞扬,姿态英勇威风!" },
	{ 103, "天罡指", 4, Armor, 10,.minDef = 300,.maxDef = 500, 4000, "飘忽不定,防东西至,防西东至!" },
	{ 104, "紫鲛衫", 5, Armor, 10,.minDef = 300,.maxDef = 500,5000, "海蛟皮制成,装备后可在水下呼吸!" },
	{ 105, "碧麟披", 6, Armor, 10,.minDef = 300,.maxDef = 500,6000, "上撰:上古南火朱雀之子,曾云字!" },
	{ 106, "金钟罩", 7, Armor, 10,.minDef = 300,.maxDef = 500,7000, "装备后有如金铸之钟覆罩全身,刀剑难损!" },
	{ 107, "防弹衣", 8, Armor, 10,.minDef = 300,.maxDef = 500,8000, "闯荡武林、居家必备!" },
	{ 108, "软猬甲", 9, Armor, 10,.minDef = 300,.maxDef = 500,10000, "刀枪不入还可保暖,穿在身上,妙用无穷。桃花岛的镇岛之宝!" },
	{ 201, "回复奶瓶(大)", 1, Consumables, 50,.minCon=50,.maxCon=100, 2000, "一次性回复500点内力值。" }
};
Player* currplayer;
int playerCount=1;
int X = 0,Y = 0;
Home home[]=
{
	{1,"Tully家族",.coord.X = 1,.coord.Y = 1,"河间地是位于三叉戟河流域的肥沃地带。徒利家族势力不算最大,但与强大的Stark家族和艾林谷都有姻亲关系。"},
	{2,"Greyjoy家族",.coord.X=3,.coord.Y=2,"铁群岛是位于大陆西海岸的一组群岛,生活条件异常艰苦,他们坚持劫掠,非常彪悍。但曾经在战败后,将人质送往临冬城。"},
	{3,"塔格利安",.coord.X=2,.coord.Y=1,"龙石岛是维斯特洛位于狭海中的岛屿,当年龙家就是从这里登上维斯特洛大陆,开始了巨龙家族的征服之旅。Baratheon家族篡位成功后,将龙石岛赐给了自己的Stannis Baratheon。"},
	{4,"Stark家族",.coord.X=4,.coord.Y=2,"北境面积最大,几乎占据了整个大陆的四分之一,临冬城的名字,美剧迷们应该再熟悉不过了。作为主角的Stark家族在北境守护了八千年,血脉极为古老,信仰也与其他家族不同。"}
};
Player player[5] = {
	{1,"linka","39",100,200,.exp=10,3,10000000,.home= { 4,"Stark家族",.coord.X = 4,.coord.Y = 2,"北境面积最大,几乎占据了整个大陆的四分之一,临冬城的名字,美剧迷们应该再熟悉不过了。作为主角的Stark家族在北境守护了八千年,血脉极为古老,信仰也与其他家族不同。" } }
};
Player defaultPlayer[5];
void Start()
{
	int choice, i, j;
	int temp;
	char tempCh1[50];
	char* tempCh2;
	printf("欢迎来到《权力的游戏》,请选择您的登录方式\n1:新用户注册\n2:老用户登录\n");
	scanf("%d", &choice);
	switch (choice)
	{
	case 1:
		printf("请输入您要注册的的用户名和密码:");
		scanf("%s%s", player[playerCount].userName,player[playerCount].passWord);
		printf("%s\n", SEP);
		for (i = 0; i < 4; i++)
		{
			printf("%d\t%s\n", home[i].id, home[i].name);
		}
		printf("请选择一个家族\n");
		scanf("%d", &temp);
		player[playerCount].home = home[temp - 1];
		playerCount++;
		break;
	case 2:
		for (j = 0; j < 3; j++)
		{
			printf("请输入您的用户名:");
			scanf("%s", tempCh1);
			printf("请输入您的密码:");
			tempCh2 = (char*)malloc(50);
			scanf("%s", tempCh2);
			for (i = 0; i < playerCount; i++)
			{
				if (strcmp(tempCh1, player[i].userName) == 0 && strcmp(tempCh2, player[i].passWord) == 0)
				{
					printf("登录成功!\n");
					playerCount = i + 1;
					getchar();
					return;
				}
				else
					printf("登录失败!\n您还有%d次登录机会", 3 - j);
			}
		}
		break;
	default:
		printf("请输入正确的选择\n");
		getchar();
		break;
	}
}
void Init()
{
	currplayer = &player[playerCount - 1];
	currplayer->Weapon = propArray[0];
	currplayer->Armor = propArray[9];
	currplayer->hp = 100;
	currplayer->mp = 200;
	currplayer->exp = 30;
	currplayer->level = 2;
	Bag bag = { 1,0,6 };
	currplayer->bag = bag;
	defaultPlayer[playerCount - 1] = player[playerCount-1];
}
void ShowPlayer()
{
	ClearInfo2();
	int i;
	setPosition(MARGIN_X + 3, INFO_Y);
	printf("玩家《%s》的个人信息如下:", currplayer->userName);
	setPosition(MARGIN_X + 5, INFO_Y+1);
	printf("HP:%d\tMP:%d\texp:%d\t等级:%d\t家族:%s", currplayer->hp, currplayer->mp, currplayer->exp,currplayer->level, currplayer->home.name);
	setPosition(MARGIN_X + 5, INFO_Y + 2);
	printf("武器:%s   防具:%s\t攻击力:%d  金钱:%.2lf", currplayer->Weapon.name, currplayer->Armor.name, currplayer->Weapon.minAtt,currplayer->price);
	setPosition(MARGIN_X + 5, INFO_Y + 3);
	printf("背包信息为:");
	for (i = 0; i < currplayer->bag.count; i++)
	{
		if (i% 3 == 0)
		{
			setPosition(MARGIN_X+7, INFO_Y +4+ i / 3);
		}
		printf("%s \t", currplayer->bag.prop[i].name, currplayer->bag.prop[i].stock);
	}
	getch();
}
void ShowMap()
{
	int i, j;
	ClearInfo(MARGIN_X, MAP_Y);
	for (i = 0; i < 5; i++)
	{
		setPosition(MARGIN_X, MAP_Y + i);
		for (j = 0; j < 5; j++)
		{
			//printf("  %-9s", Map[i][j]);//先打印后判断,此时打印的地图是默认颜色,setColor()执行时只对下一个变量进行变更
			if (X == j&&Y == i)
			{
				setColor(1, 10);
			}
			else
				setColor(10, 0);
			printf("  %-9s", Map[i][j]);//后打印才能上色,此时所打印的颜色由上一个函数来决定
			setColor(10, 0);//颜色的改变会对以下的函数产生 持续影响,除非用函数重置一下颜色
		}	
	}
	setPosition(MARGIN_X, INFO_Y - 1);
	printf("%s", SEP);
	Home* currhome;
	char* homeInfo=NULL;//首先应该把指针声明为空指针
	for (i = 0; i < 4; i++)
	{
		if (home[i].coord.X == X&&home[i].coord.Y == Y)
		{
			currhome = &home[i];
			homeInfo = currhome->desc;
		}
	}
	if (homeInfo == NULL)
	{
		setPosition(MARGIN_X, INFO_Y);
		printf("此地未完成,有待建设!");
		setPosition(MARGIN_X + 9, END);
		return;
	}
	else
	{
		int length;
		length = strlen(homeInfo);
		setPosition(MARGIN_X + 1, INFO_Y);
		printf(currhome->name);
		setPosition(MARGIN_X + 3, INFO_Y+1);
		for (i = 0; i < length; i++)
		{
			if (i%55 == 0&i!=0)//  i%40表示i能被40整除 
			{
				setPosition(MARGIN_X+3, INFO_Y + 1 + i/55);
			}
			printf("%c", homeInfo[i]);//指针可以通过  str[i]来访问内部的字符
		}
		setPosition(MARGIN_X + 9, END);
	}
}
void ShowHome()
{
	X = currplayer->home.coord.X;
	Y = currplayer->home.coord.Y;
	currplayer->hp = defaultPlayer[playerCount - 1].hp;
	currplayer->mp = defaultPlayer[playerCount - 1].mp;
	ShowMap();
}
void ShowMonster()
{
	ClearInfo2();
	int i, j;
	int choice=0;
	int monsterCount = sizeof(monsters) / sizeof(Monster);
	int currmonsterIndex[6];
	Monster* currMonster;
	int currCount=1;
	char levelName[5][50] = { "新手","入门","队长","精英","大师" };
	setPosition(MARGIN_X + 3, INFO_Y);
	printf("当前地图《%s》的怪物有:", Map[Y][X]);
	setPosition(MARGIN_X + 4, INFO_Y + 1);
	for (i = 0; i < monsterCount; i++)
	{
		if (monsters[i].mCoord.X == X&&monsters[i].mCoord.Y == Y&&monsters[i].state==1)
		{
			currMonster = &monsters[i];
			printf("%d:%s(%s)   ", currCount, currMonster->name, levelName[currMonster->level]);//满足条件时进行打印
			currmonsterIndex[currCount - 1] = i;
			if (currCount % 3 == 0)
			{
				setPosition(MARGIN_X + 4, INFO_Y+1 +currCount / 3);
			}
			/*setPosition(MARGIN_X + 4, INFO_Y + 1); //需要位置重置一遍就可以了,这样的话每次循环都要重置一下光标的位置
			printf("%d:%s(%s)   ", currCount, currMonster->name, levelName[currMonster->level]);*/
		   currCount++;
		   if (currCount == 7)break;//总数大于6时,不再进行循环判定
		}
	}
	if (currCount == 1)
	{
		//判断循环外的情况,只需要排除循环内改变的变量就可以了
		printf("当前地区什么怪物也没有!");
		getch();
		return;//在此结束函数
	}
	do{
		setPosition(MARGIN_X + 1, INFO_Y + 4);
		printf("请输入你要挑战的怪物(按0键返回)");
		scanf("%d", &choice);
		if (choice < 0 || choice >= currCount)
		{
			setPosition(MARGIN_X + 1, INFO_Y + 4);
			printf("                                                                                                ");
		}
	} while (choice < 0 || choice >= currCount);
	if (choice == 0)
	{
		ShowMap();
		return;
	}
	currMonster = &monsters[currmonsterIndex[choice - 1]];
	ShowBattle(currplayer, currMonster);
	getch();
}
void ShowBattle(Player*currplayer, Monster*currMonster)
{
	int count=1;
	int playerAtt;
	srand(time(0));
	while (currplayer->hp>0&&currMonster->hp>0)
	{
		playerAtt = rand() % (currplayer->Weapon.maxAtt - currplayer->Weapon.minAtt) + currplayer->Weapon.minAtt;
		setPosition(MARGIN_X, INFO_Y + 4);
		printf("                                                                                         ");
		setPosition(MARGIN_X, INFO_Y + 4);
		currMonster->hp -= playerAtt;
		currplayer->hp -= currMonster->att;
		currplayer->mp -= 1 * playerAtt;
		if (currplayer->mp <= 0)
		{
			printf("当前内力已透支");
			return;
		}
		if (currplayer->hp < 0)
			currplayer->hp = 0;
		if (currMonster->hp < 0)currMonster->hp = 0;
		printf("战斗进行第%d轮:%s HP:%d MP:%d\t\t%s HP:%d",count, currplayer->userName, currplayer->hp, currplayer->mp, currMonster->name, currMonster->hp);
		count++;
		_sleep(200);
	}
	if (currplayer->hp == 0)
	{
		setPosition(MARGIN_X, INFO_Y + 5);
		printf("玩完了,大侠《%s》在与《%s》的斗争中牺牲", currplayer->userName, currMonster->name);
		return;//表示结束,可以不写else函数,直接结束函数的运行
	}
	int Item = rand() % 9;
	currMonster->state = 0;
	currplayer->price += currMonster->maxLoot;
	currplayer->exp += currMonster->exp;
	
	setPosition(MARGIN_X, INFO_Y + 5);
	printf("大侠《%s》胜出!金钱+%d   经验+%d 获得道具:%s", currplayer->userName, currMonster->maxLoot,currMonster->exp,propArray[Item].name);
	currplayer->bag.prop[currplayer->bag.count] = propArray[Item];
	currplayer->bag.count++;
	LevelUp();
}
void ShowTrade()
{
	int i;
	int choice=0;
	ClearInfo2();
	setPosition(MARGIN_X, INFO_Y);
	printf("当前《%s》所有的商品如下:",Map[Y][X]);
	setPosition(MARGIN_X + 2, INFO_Y + 1);
	for (i = 0; i < 10; i++)
	{
		if (i == 9)break;
		if (i % 3 == 0&&i!=0)
		{
			setPosition(MARGIN_X + 2, INFO_Y + 1 + i / 3);
		}
		printf("%d,%s %.1lf %d\t", propArray[i].id, propArray[i].name, propArray[i].price, propArray[i].stock);
	}
	setPosition(MARGIN_X, INFO_Y + 4);
	printf("请输入您要购买的商品序号:(按0键返回)");
	scanf("%d", &choice);
	if (choice == 0)
	{
		ShowMap();
		return;
	}
	setPosition(MARGIN_X, INFO_Y + 5);
    Trade(currplayer, choice);	
	ShowTrade();
}
void Trade(Player*player, int choice)
{
	if (choice > 9 || choice < 0)
	{
		printf("所选的选项不存在");
		getch();
		return;
	}
	if (currplayer->price < propArray[choice-1].price)
	{
		printf("你的钱不够呀!");
		getch();
		return;
	}
	if (currplayer->bag.count == currplayer->bag.maxcount)
	{
		printf("你的背包空间不够了!");
		getch();
		return;
	}
	if (propArray[choice-1].stock == 0)
	{
		printf("商店被你给买没了");
		getch();
		return;
	}
	//满足交易条件,执行交易的业务操作
	//1、商品库存-1
	propArray[choice-1].stock--;
	//2、玩家金币-商品单价
	player->price -= propArray[choice - 1].price;

	currplayer->bag.prop[currplayer->bag.count] = propArray[choice-1];
	
	currplayer->bag.count++;

	/*currplayer->bag.count++;
	for (i = 0; i < currplayer->bag.count; i++)
	{
		currplayer->bag.prop[i] = propArray[choice - 1];
	}*/
	printf("商品《%s》以购买",propArray[choice-1].name);
	getch();
	return;
}
void LevelUp()
{
	int expMax = 3* pow(2,(currplayer->level));//pow(2,n)表示n的2次方。squrt(a)表示求a的开方
	if (currplayer->exp >= expMax)
	{
		currplayer->exp = 0;
		currplayer->level++;
		defaultPlayer[playerCount - 1].hp += 10;
		defaultPlayer[playerCount - 1].mp += 30;
		currplayer->hp = defaultPlayer[playerCount - 1].hp;
		currplayer->mp = defaultPlayer[playerCount - 1].mp;
		setPosition(MARGIN_X, INFO_Y + 5);
		printf("                                                                                         ");
		setPosition(MARGIN_X, INFO_Y + 5);
		printf("恭喜升级,当前%d级,最大体力+10,最大耐力+30", currplayer->level);
	}
}
void Poccess(char key)
{
	switch (key)
	{
	case '1':
		ShowPlayer();
		break;
	case '2':
		ShowMonster();
		break;
	case '3':
		ShowTrade();
		break;
	case '4':
		ShowHome();
		break;
	case '5':
		exit(0);
		break;
	}
	setPosition(MARGIN_X + 9, END);
}


main.c

#include"gamelib.h"
#include"game.h"
extern Player*currplayer;
extern int X, Y;
int main()
{
	setColor(10, 0);
	Start();
	Init();
	Clear();
	setPosition(MARGIN_X, MAP_Y);
	printf("当前的您的状况如下:     (按任意键开始游戏)");
	ShowPlayer();
	getchar();
	Clear();

	//-3272  -3280   -3275   -3277
	Init();
	setPosition(MARGIN_X + 27, 0);
	printf("维斯特洛大陆");
	setPosition(MARGIN_X , 1);
	printf("%s", SEP);
	setPosition(MARGIN_X, MENU_Y-1);
	printf("%s",SEP);
	setPosition(MARGIN_X, MENU_Y);
	printf("1:查看个人状态:");
	setPosition(MARGIN_X, MENU_Y + 1);
	printf("2:四处查看:");
	setPosition(MARGIN_X, MENU_Y + 2);
	printf("3:购买装备:");
	setPosition(MARGIN_X, MENU_Y + 3);
	printf("4:回到城堡:");
	setPosition(MARGIN_X, MENU_Y + 4);
	printf("5:退出游戏:");
	char key;
	while (1)
	{
		ShowMap();
		key = getch();//相当于一个回车按键
		if (key == '1'||key == '2'||key == '3'||key == '4'||key == '5')
		{
			Poccess(key);
			//getch();//用来接收一个按键位,进行一下缓冲
		}
		if (key == 72)
		{
			Y--;
		}
		if (key ==80)
		{
			Y++;
		}
		if (key ==75)
		{
			X--;
		}
		if (key ==77)
		{
			X++;
		}
		if (X > 4)X =0;
		if (X < 0)X = 4;
		if (Y > 4)Y =0;
		if (Y < 0)Y =4;
	}

	return 0;
}


你可能感兴趣的:(程序,网课结业设计,c语言,结构体,小游戏)