#include <bits/stdc++.h>//工作模拟器
#include <windows.h>
#define ll long long

using namespace std;


char dt[8][20]= {
	{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','+','+','#'},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','=',' '},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
	{'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
	{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
};
namespace gongjv {
	inline void cd(int x) {
		Sleep(x);
		system("cls");
	}
	void ggb() {
		HWND hwnd = GetConsoleWindow();
		LONG style = GetWindowLong(hwnd, GWL_STYLE);
		style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX  | WS_THICKFRAME);
		SetWindowLong(hwnd, GWL_STYLE, style);
		SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
		             SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
	}
	bool SetWindowTopMost(HWND hWnd, bool topmost, bool noActivate = true) {
		if (!IsWindow(hWnd)) return false;
		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
		if (noActivate) flags |= SWP_NOACTIVATE; // 关键:置顶但不抢焦点
		return SetWindowPos(hWnd,
		                    topmost ? HWND_TOPMOST : HWND_NOTOPMOST,
		                    0, 0, 0, 0,
		                    flags);
	}
	bool axj(long long key) {
		return (GetKeyState(key) < 0) ? (true) : (false);
	}
	struct hl {
		long long h,l;
	};
	inline void de(int x) {
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
	}
	int djde1(int x) {
		int y=0;
		switch(x) {
			case 1:
				y=7;
				break;
			case 2:
				y=15;
				break;
			case 3:
				y=2;
				break;
			case 4:
				y=10;
				break;
			case 5:
				y=3;
				break;
			case 6:
				y=11;
				break;
			case 7:
				y=9;
				break;
			case 8:
				y=14;
				break;
			case 9:
				y=12;
				break;
		}
		return y;
	}
	void pzde2(int x) {
		int y=0;
		switch(x) {
			case 1:
				y=15;
				break;
			case 2:
				y=10;
				break;
			case 3:
				y=11;
				break;
			case 4:
				y=14;
				break;
			case 5:
				y=4;
				break;
		}
		de(y);
	}
	int pzde1(int x) {
		int y=0;
		switch(x) {
			case 1:
				y=15;
				break;
			case 2:
				y=10;
				break;
			case 3:
				y=11;
				break;
			case 4:
				y=14;
				break;
			case 5:
				y=4;
				break;
		}
		return y;
	}
	void djde2(int x) {
		int y=0;
		switch(x) {
			case 1:
				y=7;
				break;
			case 2:
				y=15;
				break;
			case 3:
				y=2;
				break;
			case 4:
				y=10;
				break;
			case 5:
				y=3;
				break;
			case 6:
				y=11;
				break;
			case 7:
				y=9;
				break;
			case 8:
				y=14;
				break;
			case 9:
				y=12;
				break;
		}
		de(y);
	}
	bool ax(long long key) {
		return (GetKeyState(key) < 0) ? (true) : (false);
	}
	hl wz(bool x = 1, bool n = 1) {
		HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
		HWND h = GetForegroundWindow();
		CONSOLE_FONT_INFO consoleCurrentFont;
		hl hl;
		POINT p;
		if (x) {
			GetCursorPos(&p);
			ScreenToClient(h, &p);
		} else {
			GetCursorPos(&p);
		}
		if (n) {
			GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
			p.x /= consoleCurrentFont.dwFontSize.X;
			p.y /= consoleCurrentFont.dwFontSize.Y;
		}
		hl.h = p.y + 1;
		hl.l = p.x + 1;
		return hl;
	}
	hl GetActiveWindowSize() {
		HWND hwnd = GetForegroundWindow();
		RECT rect;
		if (GetClientRect(hwnd, &rect)) {
			int clientWidth = rect.right - rect.left;
			int clientHeight = rect.bottom - rect.top;
			hl sas= {clientWidth /8,clientHeight /16};
			return sas;
		}
	}
	void ycbj() {
		HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
		DWORD mode;
		GetConsoleMode(hStdin, &mode);
		mode &= ~ENABLE_QUICK_EDIT_MODE;
		SetConsoleMode(hStdin, mode);
		return;
	}
	void ycgb() {
		CONSOLE_CURSOR_INFO cursor;
		cursor.bVisible = FALSE;
		cursor.dwSize = sizeof(cursor);
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorInfo(handle, &cursor);
		return;
	}
	inline void ydgb(long long h, long long l) {
		h-=1;
		l-=1;
		COORD pos = { (short)l,(short)h  };
		HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorPosition(hOut, pos);
		return;
	}
	inline void ydgb_zj_sc(int x,string zt) {
		ll s1=GetActiveWindowSize().h/2;
		ll s2=zt.size()/2;
		ydgb(x,s1-s2);
		cout<<zt;
	}
	inline void ydgb_zj(int x,string zt) {
		ll s1=GetActiveWindowSize().h/2;
		ll s2=zt.size()/2;
		ydgb(x,s1-s2);
	}
	inline void ydgb_zj(int x,int zt) {
		ll s1=GetActiveWindowSize().h/2;
		ll s2=zt/2;
		ydgb(x,s1-s2);
	}
	inline hl ydgb_zj_hl(string zt) {
		ll s1=GetActiveWindowSize().h/2;
		ll s2=zt.size()/2;
		hl z= {s1-s2,s1+s2};
		return z;
	}
	inline bool pdbj(int y,int x,int x1,int x2,int ys,string zt) {
		ycgb();
		ycbj();
		hl z=wz(1,1);
		bool a=0;
		if(z.h==y&&z.l>=x1&&z.l<=x2) {
			ydgb(y,x);
			de(ys*16);
			cout<<zt;
			de(ys);
			if(axj(VK_LBUTTON)) {
				a=1;
			}
		} else {
			ydgb(y,x);
			de(ys);
			cout<<zt;
		}
		de(15);
		return a;
	}
	inline bool pddj_zj(int h,int ys,string zt) {
		int s1=GetActiveWindowSize().h/2;
		int s2=zt.size()/2;
		if(pdbj(h,s1-s2,s1-s2,s2+s1,ys,zt)) {
			return 1;
		} else {
			return 0;
		}
	}
	inline bool pddj_zj_kh(int h,int ys,string zt,string z1="",string z2="") {
		int s1=GetActiveWindowSize().h/2;
		int s2=zt.size()/2;
		ydgb(h,s1-s2-z1.size()-1);
		cout<<z1<<"[";
		ydgb(h,s1+s2);
		cout<<"]"<<z2;
		if(pdbj(h,s1-s2,s1-s2,s2+s1,ys,zt)) {
			return 1;
		} else {
			return 0;
		}
	}
	inline bool pddj_kh(int h,int x,int ys,string zt,string z1="",string z2="") {
		int s2=zt.size();
		ydgb(h,x);
		cout<<z1<<"[";
		ydgb(h,x+z1.size()+s2+1);
		cout<<"]"<<z2;
		if(pdbj(h,x+z1.size()+1,x+z1.size()+1,s2+x+z1.size(),ys,zt)) {
			return 1;
		} else {
			return 0;
		}
	}
	inline string wjcc(string x, string y) {
		std::string full_path = x + "\\" + y;
		// 只创建目录,不创建文件
		std::string command = "if not exist " + x + " mkdir " + x;
		int ret = system(command.c_str());
		return full_path;
	}
	inline string in_str(ll x) {
		string y="";
		const string z[]= {"0","1","2","3","4","5","6","7","8","9"};
		while(x) {
			y+=z[x%10];
			x/=10;
		}
		reverse(y.begin(),y.end());
		return y;
	}
};

using namespace gongjv;

int wzx=2,wzy=1,money=200,tired=0,health=100;

void gongdi(){
	cout<<"     "<<"一片工地,好像是某户人家要建造房屋?";
	cout<<"                          是否上工?";
	while(1){
		if(pdbj(3,20,20,20,7,"是")){
			break; 
		}
		if(pdbj(4,20,20,20,7,"否")){
			return; 
		}
	} 
	system("cls");
	int zhuanshu=0;
	int wzx_gong=1,wzy_gong=2;
	char gdt[8][10]={
		{'#',' ',' ',' ',' ','e',' ',' ',' ','#'},
		{'#',' ',' ',' ',' ',' ',' ',' ',' ','#'},
		{'#',' ',' ',' ',' ',' ',' ',' ','d',' '},
		{'#',' ',' ',' ',' ',' ',' ',' ','d',' '},
		{'#',' ',' ',' ',' ',' ',' ',' ','d',' '},
		{'#',' ',' ',' ',' ',' ',' ',' ',' ','#'},
		{'#','s',' ',' ',' ',' ',' ',' ',' ','#'},
		{'#','#','#','#','#','#','#','#','#','#'},
	}; 
	ggb();
	ycgb();
	bool f=0;
	ycbj();
	int yd=0;
	for(int hu=1;1;++hu){
		if(yd){
			if(hu%10==0)yd=0;
		}
		ydgb(1,1);
		for(int i=0;i<8;i++){
			ydgb(i+1,1);
			for(int j=0;j<10;j++){
				if(i==wzx_gong&&j==wzy_gong){
					cout<<"I";
					if(gdt[i][j]=='d'){
						system("cls");
						return ;
						system("cls");
					}
					if(gdt[i][j]=='s'){
						if(zhuanshu<9){
							zhuanshu+=1;
							Sleep(100);
						}else{	
							f=1;
						}
					} 
					if(gdt[i][j]=='e'){
						money+=zhuanshu;
						tired-=zhuanshu;
						zhuanshu=0;
						f=0;
					} 
				}else{
					cout<<gdt[i][j];
				}
				
			}
			if(i==0){
				cout<<"   d:门口,会离开工地"; 
			}
			if(i==1){
				cout<<"   s:取砖处  当前砖数:"<<zhuanshu;
			}
			if(i==2){
				cout<<"   e:放砖处 已拥有金额:"<<money; 
			}
		}
		cout<<endl;
		if(f){
			cout<<"已经到达最大限度"; 
		}else{
			if(gdt[wzx_gong][wzy_gong]=='e'){
				system("cls");
				wzx_gong=1;wzy_gong=5;
			}
			
		}
		if(tired<=0){
			system("cls");
			cout<<"你因过度劳累,被工友抬出了施工现场,请及时吃饭哦";
			Sleep(500);
			return ; 
		} 
		if(axj('W')&&!yd){
			ydgb(wzx_gong+1,wzy_gong+1);cout<<" ";if(wzx_gong>0)wzx_gong-=1;hu=1;yd=1;
		}
		if(axj('S')&&!yd){
			ydgb(wzx_gong+1,wzy_gong+1);cout<<" ";if(wzx_gong<6)wzx_gong+=1;hu=1;yd=1;
		}
		if(axj('A')&&!yd){
			ydgb(wzx_gong+1,wzy_gong+1);cout<<" ";if(wzy_gong>1)wzy_gong-=1;hu=1;yd=1;
		}
		if(axj('D')&&!yd){
			ydgb(wzx_gong+1,wzy_gong+1);cout<<" ";if(wzy_gong<8)wzy_gong+=1;hu=1;yd=1;
		}
		Sleep(1); 
	}
}

void chifan(){
	int wzx_eat=2,wzy_eat=1;
	char meishijie[5][10]={
		{'#','#','#','#','#','#','#','#','#','#'},
		{' ',' ',' ',' ','.',' ',' ',' ',' ',' '},
		{' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
		{' ',' ',' ',' ','.',' ',' ',' ',' ',' '},
		{'#','#','#','#','#','#','#','#','#','#'},		
	};
	system("mode con cols=50 lines=20");
	ggb();
	ycgb();
	ycbj();
	int yd=0;
	for(int hu=1;1;++hu){
		if(yd){
			if(hu%10==0)yd=0;
		}
		ydgb(1,1);
		for(int i=0;i<5;i++){
			ydgb(i+1,1);
			for(int j=0;j<10;j++){
				if(i==wzx_eat&&j==wzy_eat){
					cout<<"I";
					if(meishijie[i][j]=='.'){
						system("cls");
						cout<<"一家酒楼,有一份40元套餐,你要吃吗?";
						while(1){
							if(pddj_zj(2,7,"是")){
								if(tired>10){
									cout<<"实在吃不消";
									break; 
								}
								system("cls");
								tired+=100;
								money-=40; 
								health+=50;
								break;
							}
							if(pddj_zj(3,7,"否")){
								break; 
							}
						} 
						wzx_eat=2;
						system("cls");
						break;
					}
					if(j==0){
						return;
					}
				}else{
					cout<<meishijie[i][j];
				}
				
			}
			if(i==0){
				cout<<"    余额:"<<money;
			}
		}
		if(axj('W')&&!yd){
			ydgb(wzx_eat+1,wzy_eat+1);cout<<" ";if(wzx_eat>0)wzx_eat-=1;hu=1;yd=1;
		}
		if(axj('S')&&!yd){
			ydgb(wzx_eat+1,wzy_eat+1);cout<<" ";if(wzx_eat<3)wzx_eat+=1;hu=1;yd=1;
		}
		if(axj('A')&&!yd){
			ydgb(wzx_eat+1,wzy_eat+1);cout<<" ";if(wzy_eat>0)wzy_eat-=1;hu=1;yd=1;
		}
		if(axj('D')&&!yd){
			ydgb(wzx_eat+1,wzy_eat+1);cout<<" ";if(wzy_eat<8)wzy_eat+=1;hu=1;yd=1;
		}
		Sleep(1); 
	}
}

int main() {
	system("mode con cols=50 lines=20");
	ggb();
	ycgb();
	ycbj();
	int yd=0;
	for(int hu=1;1;++hu){
		if(yd){
			if(hu%10==0)yd=0;
		}
		ydgb(1,1);
		for(int i=0;i<8;i++){
			ydgb(i+1,1);
			for(int j=0;j<20;j++){
				if(i==wzx&&j==wzy){
					cout<<"I";
					if(dt[i][j]=='+'){
						system("cls");
						gongdi();
						wzx+=1; 
						health-=30;
						system("cls");
						break;
					}
					if(dt[i][j]=='='){
						system("cls");
						chifan();
						wzy-=1;
						system("cls"); 
					} 
				}else{
					cout<<dt[i][j];
				}
				
			}
			if(i==0){
				cout<<"    余额:"<<money;
			}
		}
		if(axj('W')&&!yd){
			ydgb(wzx+1,wzy+1);cout<<" ";if(wzx>1)wzx-=1;hu=1;yd=1;
		}
		if(axj('S')&&!yd){
			ydgb(wzx+1,wzy+1);cout<<" ";if(wzx<6)wzx+=1;hu=1;yd=1;
		}
		if(axj('A')&&!yd){
			ydgb(wzx+1,wzy+1);cout<<" ";if(wzy>1)wzy-=1;hu=1;yd=1;
		}
		if(axj('D')&&!yd){
			ydgb(wzx+1,wzy+1);cout<<" ";if(wzy<18)wzy+=1;hu=1;yd=1;
		}
		Sleep(1); 
	}
	return 0;
}