*****

#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<time.h>
#include<conio.h>
#include<iostream>
#include"sg.txt"
using namespace std;

void izc();
void gotoxy();
void move();
void keydown();
void map();
void newmap();
void time();
void home();
void home2();
void home3();
void home2key();
void homekey();
void home4();
void home4key();
void home5();
void home6();
void home6key();
void forest();
void forestkey();
void forestpk();
char chara[2]={"0"};
char charb[2]={"0"};
char charc[2]={"0"};
int backhome=0;
int k=0;
int k1=0;
int key=0;
int posx=xposx;
int posy=xposy;
int timea=xtimea;
int timeb=xtimeb;
int timec=xtimec;
int timed=xtimed;
int timee=xtimee;
int timef=xtimef;
int timeg=xtimeg;
int hp=xhp;
int dun=xdun;
int power=xpower;
int wood=xwood;
int meat=xmeat;
int firemeat=xfiremeat;
int gold=xgold;
int wood_sword=xwood_sword;
int stone_sword=xstone_sword;
void izc(int x)
{
	chara[0]='0';
	charb[0]='0';
	charc[0]='0';
	int num=0;
	int num1=0;
	int num2=0;
	int num3=0;
	num1=x%10;
	num=(x-num1)/10;
	num2=num%10;
	num3=(num-num2)/10;
	if(num3!=0)
	{
		k1=1;
		if(num3==1)
			charc[0]='1';
		if(num3==2)
			charc[0]='2';
		if(num3==3)
			charc[0]='3';
		if(num3==4)
			charc[0]='4';
		if(num3==5)
			charc[0]='5';
		if(num3==6)
			charc[0]='6';
		if(num3==7)
			charc[0]='7';
		if(num3==8)
			charc[0]='8';
		if(num3==9)
			charc[0]='9';
	}
	if(num2!=0||num3!=0)
	{
		k=1;
		if(num2==0)
			chara[0]='0';
		if(num2==1)
			chara[0]='1';
		if(num2==2)
			chara[0]='2';
		if(num2==3)
			chara[0]='3';
		if(num2==4)
			chara[0]='4';
		if(num2==5)
			chara[0]='5';
		if(num2==6)
			chara[0]='6';
		if(num2==7)
			chara[0]='7';
		if(num2==8)
			chara[0]='8';
		if(num2==9)
			chara[0]='9';
	}
	if(num1==0)
		charb[0]='0';
	if(num1==1)
		charb[0]='1';
	if(num1==2)
		charb[0]='2';
	if(num1==3)
		charb[0]='3';
	if(num1==4)
		charb[0]='4';
	if(num1==5)
		charb[0]='5';
	if(num1==6)
		charb[0]='6';
	if(num1==7)
		charb[0]='7';
	if(num1==8)
		charb[0]='8';
	if(num1==9)
		charb[0]='9';
}
void gotoxy(int x, int y)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord;
	coord.X = x;
	coord.Y = y;
	SetConsoleCursorPosition(handle, coord);
}
int stopup(int x,int y)
{
	if(y==2)
	{
		if(x==78)
			return 1;
		if(x==77)
			return 1;
		if(x==76)
			return 1;
		if(x==75)
			return 1;
	}
	return 0;
}
void move(int x,int y)
{	if (_kbhit())
	{
		switch (getch()) {
		case 13:
			if(posx==25&&posy==10)
				home();
			if(posx==10&&posy==4)
				forest();
			if(posx==10&&posy==5)
				forest();
			if(posx==11&&posy==4)
				forest();
			if(posx==12&&posy==4)
				forest();
			if(posx==13&&posy==4)
				forest();
			if(posx==12&&posy==5)
				forest();
			if(posx==12&&posy==3)
				forest();
			break;
		case 97:
			if(x==2)
				break;
			gotoxy(x,y);
			cout<<" ";
			gotoxy(x-1,y);
			cout<<"@";
			posx=x-1;
			posy=y;
			gotoxy(posx,posy);
			break;
		case 119:
			if(y==1)
				break;
			if(stopup(x,y)==1)
				break;
			gotoxy(x,y);
			cout<<" ";
			gotoxy(x,y-1);
			cout<<"@";
			posx=x;
			posy=y-1;
			gotoxy(posx,posy);
			break;
		case 115:
			if(y==23)
				break;
			gotoxy(x,y);
			cout<<" ";
			gotoxy(x,y+1);
			cout<<"@";
			posx=x;
			posy=y+1;
			gotoxy(posx,posy);
			break;
		case 100:
			if(x==78)
				break;
			if(x==74&&y==1)
				break;
			gotoxy(x,y);
			cout<<" ";
			gotoxy(x+1,y);
			cout<<"@";
			posx=x+1;
			posy=y;
			gotoxy(posx,posy);
			break;
		case 112:
			FILE *fp=fopen("temp.txt","w");
			fputs("int xposx=",fp);
			izc(posx);
			if(k==1)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xposy=",fp);
			izc(posy);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimea=",fp);
			izc(timea);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimeb=",fp);
			izc(timeb);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimec=",fp);
			izc(timec);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimed=",fp);
			izc(timed);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimee=",fp);
			izc(timee);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimef=",fp);
			izc(timef);
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xtimeg=",fp);
			izc(timeg);
			if(k1!=0)
			{
				k1=0;
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			
			fputs(";int xhp=",fp);
			izc(hp);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xdun=",fp);
			izc(dun);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xpower=",fp);
			izc(power);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xwood=",fp);
			izc(wood);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xmeat=",fp);
			izc(meat);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xfiremeat=",fp);
			izc(firemeat);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xgold=",fp);
			izc(gold);
			if(k1!=0)
			{
				k1=0;
				fputs(charc,fp);
			}
			if(k!=0)
			{
				k=0;
				fputs(chara,fp); 
			}
			fputs(charb,fp);
			fputs(";int xwood_sword=",fp);
			izc(wood_sword);
			fputs(charb,fp);
			fputs(";int xstone_sword=",fp);
			izc(stone_sword);
			fputs(charb,fp);
			fputs(";",fp);
			fclose(fp);
			system("del sg.txt");
			system("rename temp.txt sg.txt");
			break;
		}
	}
}
void map()
{
	for(int i=0;i<79;i++)
	{
		gotoxy(i,0);
		cout<<"█";
		gotoxy(i,24);
		cout<<"█";
	}
	for(int i=1;i<24;i++)
	{
		gotoxy(0,i);
		cout<<"█";
		gotoxy(79,i);
		cout<<"█";
	}
}
void newmap()
{
	gotoxy(24,9);
	cout<<"###";
	gotoxy(24,10);
	cout<<"#";
	gotoxy(24,11);
	cout<<"###";
	gotoxy(26,10);
	cout<<"#";
	gotoxy(10,4);
	cout<<"林";
	gotoxy(10,5);
	cout<<"林";
	gotoxy(11,4);
	cout<<"林";
	gotoxy(12,4);
	cout<<"林";
	gotoxy(13,4);
	cout<<"林";
	gotoxy(12,5);
	cout<<"林";
	gotoxy(12,3);
	cout<<"林";
}
void time()
{
	Sleep(10);
	timee=timee+1;
	if(timee>=100)
	{
		timed=timed+1;
		timee==0;
	}
	if(timed>=10)
	{
		timed=0;
		timec++;
	}
	if(timec>=6)
	{
		timec=0;
		timeb++;
	}
	if(timeb>=10)
	{
		timeb=0;
		timea++;
	}
	if(timea>=6)
	{
		timea=0;
		timef++;
	}
	if(timef>=10)
	{
		timef=0;
		timeg++;
	}
	if(timeg>=2&&timef>=4)
	{
		timeg=0;
		timef=0;
	}
	gotoxy(76,1);
	cout<<timef;
	gotoxy(75,1);
	cout<<timeg;
	gotoxy(78,1);
	cout<<timeb;
	gotoxy(77,1);
	cout<<timea;
}void home3()
{
	system("cls");
	map();
	if(wood>=1&&meat>=1)
	{
		meat--;
		wood--;
		firemeat++;
		system("cls");
		gotoxy(35,12);
		cout<<"获得烤肉*1";
		getch();
		backhome=1;
	}else
	{
		gotoxy(35,12);
		cout<<"您的材料不够";
		getch();
		backhome=1;
	}
}
void home()
{
	system("cls");
	map();
	while(backhome!=2)
	{
		backhome=0;
		time();
		gotoxy(35,10);
		cout<<"1.睡觉";
		gotoxy(35,11);
		cout<<"2.烹饪";
		gotoxy(35,12);
		cout<<"3.仓库";
		gotoxy(35,13);
		cout<<"4.外出";
		gotoxy(35,14);
		cout<<"5.商店";
		homekey();
		gotoxy(0,0);
	}
	system("cls");
	map();
	backhome=0;
}
void homekey()
{
	if (_kbhit())
	{
		switch (getch()) {
		case 49:
			home4();
			system("cls");
			map();
			break;
		case 50:
			home2();
			system("cls");
			map();
			break;
		case 51:
			home5();
			system("cls");
			map();
			break;
		case 52:
			backhome=2;
			break;
		case 53:
			home6();
			system("cls");
			map();
			break;
		}
	}
}
void home2key()
{
	if (_kbhit())
	{
		switch (getch()) {
		case 49:
			home3();
			break;
		}
	}
}
void home2()
{
	system("cls");
	map();
	while(backhome!=1)
	{
		time();
		gotoxy(35,12);
		cout<<"1.烤肉";
		home2key();
		gotoxy(0,0);
	}
}
void home4key()
{
	if (_kbhit())
	{
		switch (getch()) {
		case 49:
			system("cls");
			gotoxy(35,12);
			cout<<"您已睡眠4小时";
			timef=timef+4;
			if(timef>=10)
			{
				timef=timef-10;
				timeg++;
			}
			hp=hp+50;
			if(hp>100)
				hp=100;
			gotoxy(0,0);
			getch();
			backhome=1;
			break;
		case 50:
			system("cls");
			gotoxy(35,12);
			cout<<"您已睡眠8小时";
			timef=timef+8;
			if(timef>=10)
			{
				timef=timef-10;
				timeg++;
			}
			hp=hp+100;
			if(hp>100)
				hp=100;
			gotoxy(0,0);
			getch();
			backhome=1;
			break;
		}
	}
}
void home4()
{
	system("cls");
	map();
	while(backhome!=1)
	{
		time();
		gotoxy(35,11);
		cout<<"1.睡眠4小时";
		gotoxy(35,12);
		cout<<"2.睡眠8小时";
		home4key();
		gotoxy(0,0);
	}
}
void home5()
{
	system("cls");
	gotoxy(0,0);
	cout<<"生命值为:"<<hp<<endl;
	cout<<"攻击力为:"<<power<<endl;
	cout<<"防御力为:"<<dun<<endl;
	cout<<"烤肉有:"<<firemeat<<endl;
	cout<<"生肉有:"<<meat<<endl;
	cout<<"原木有:"<<wood<<endl;
	cout<<"金币有:"<<gold<<endl;
	getch();
	backhome=1;
}
void home6()
{
	system("cls");
	gotoxy(0,0);
	cout<<"1.木剑(10金币)"<<endl;
	cout<<"2.石剑(20金币)"<<endl;
	while(backhome!=1)
	{
		home6key();
	}
}
void home6key()
{
	if (_kbhit())
	{
		switch (getch()) {
		case 49:
			
			if(gold>=10&&wood_sword==0)
			{
				gold=gold-10;
				wood_sword=1;
				system("cls");
				gotoxy(35,12);
				cout<<"购买成功";
				getch();
				backhome=1;
			}else{
				if(wood_sword>=1)
				{
					system("cls");
					gotoxy(35,12);
					cout<<"您已经拥有此物品";
					getch();
					backhome=1;
				}else{
					system("cls");
					gotoxy(35,12);
					cout<<"你的金币不够";
					getch();
					backhome=1;
				}
			}
			break;
		case 50:
			if(gold>=20&&stone_sword==0)
			{
				gold=gold-20;
				stone_sword=1;
				system("cls");
				gotoxy(35,12);
				cout<<"购买成功";
				getch();
				backhome=1;
			}else{
				if(stone_sword>=1)
				{
					system("cls");
					gotoxy(35,12);
					cout<<"您已经拥有此物品";
					getch();
					backhome=1;
				}else{
					system("cls");
					gotoxy(35,12);
					cout<<"你的金币不够";
					getch();
					backhome=1;
				}
			}
			break;
		}
	}
}
void forest()
{
	system("cls");
	map();
	while(backhome!=2)
	{
		backhome=0;
		time();
		gotoxy(35,11);
		cout<<"1.狩猎";
		gotoxy(35,12);
		cout<<"2.外出";
		forestkey();
		gotoxy(0,0);
	}
	system("cls");
	map();
	backhome=0;
}
void forestkey()
{
	if (_kbhit())
	{
		switch (getch()) {
		case 49:
			forestpk();
			system("cls");
			map();
			break;
		case 50:
			backhome=2;
			break;
		}
	}
}
void forestpk()
{
	system("cls");
	gotoxy(0,0);
	srand((unsigned)time(NULL));
	int a=rand()%3;
	if(a==0||a==1)
	{
		int bearhp=20;
		int bearpower=5;
		while(bearhp>0&&hp>0)
		{
			cout<<"熊受到了"<<power<<"伤害"<<endl;
			bearhp=bearhp-power;
			if(bearhp<=0)
			{
				cout<<"您赢了"<<endl;
				cout<<"您获得了1金币"<<endl;
				gold++;
				backhome=1;
				goto WINNER;
			}
			if(dun>=bearpower)
			{
				cout<<"您未受到伤害";
				goto WINNER;
			}
			hp=hp-bearpower+dun;
			cout<<"你受到了"<<(bearpower-dun)<<"伤害"<<endl;
			WINNER:
				if(hp<=0)
				{
					cout<<"您死了";
					backhome=1;
				}
		}
	}
	if(a==2)
	{
		int bearhp=30;
		int bearpower=5;
		while(bearhp>0&&hp>0)
		{
			cout<<"熊受到了"<<power<<"伤害"<<endl;
			bearhp=bearhp-power;
			if(bearhp<=0)
			{
				cout<<"您赢了"<<endl;
				cout<<"您获得了2金币"<<endl;
				gold++;
				backhome=1;
				goto WIN;
			}
			if(dun>=bearpower)
			{
				cout<<"您未受到伤害";
				goto WIN;
			}
			hp=hp-bearpower+dun;
			cout<<"你受到了"<<(bearpower-dun)<<"伤害"<<endl;
			WIN:
				if(hp<=0)
				{
					cout<<"您死了";
					backhome=1;
				}
		}
	}
	getch();
}
int main()
{
	gotoxy(35,11);
	cout<<"1.开始游戏";
	gotoxy(35,12);
	cout<<"2.退出游戏";
	gotoxy(0,0);
	AGAIN:
	switch (getch()) {
	case 49:
		goto PLAY;
		break;
	case 50:
		system("cls");
		return 0;
		break;
	default:
		goto AGAIN;
		break;
	}
	PLAY:
	system("cls");
	map();
	gotoxy(posx,posy);
	while(1)
	{
		gotoxy(posx,posy);
		cout<<"@";
		gotoxy(0,0);
		move(posx,posy);
		time();
		newmap();
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值