半成品文字游戏

半成品文字游戏(暂时禁止更改后转载或转载):


#include<bits/stdc++.h>
#include<iostream>
#include<windows.h>

#define sys system
#define Sep Sleep(1000)
#define prn printf("\n")
#define cls system("cls")
#define pause system("pause")
#define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
/***制作者:CSDN wxn小学***/ 
using namespace std;
struct node
{
	int species;
	bool condition;
	bool vip;
	int password;
	string name;
}my;

/***输出***/
void prin(string s,int a,int b)
{
	for(int i=0;i<s.size();i++){
		cout<<s[i];
		Sleep(a);
	}
	Sleep(b);
	return;
}

/***存档***/ 
void cd(void)
{
    FILE* fp = fopen("玩家属性.txt","wb");
    //fprintf(fp,"%c\n",my.name);
    fprintf(fp,"%d\n",my.password);
    fprintf(fp,"%d\n",my.condition);
    fprintf(fp,"%d\n",my.vip);
    fprintf(fp,"%d\n",my.species);
    fclose(fp);
    return;
}

/***读档***/ 
void dd(void)
{
	FILE* fp = fopen("玩家属性.txt","rb");
    if(fp != NULL)
	{
        //fprintf(fp,"%s\n",my.name);
        fscanf(fp,"%d\n",&my.password);
        fscanf(fp,"%d\n",&my.condition);
        fscanf(fp,"%d\n",&my.vip);
        fscanf(fp,"%d\n",&my.species);
        fclose(fp);
    }
	else
	{
        cd();
        printf("未找到存档,已新建存档\n");
        exit(1);
    }
    return;
}

/***覆盖清屏**/ 
void gotoxy_cover(int x, int y)//覆盖清屏 ,指定行列覆盖
{
	COORD pos = {x,y};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut, pos);
	return;
}

/***影藏光标***/
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = {1, 0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
	return;
}

/***颜色***/ 
void color(int a)
{
	if(a==1)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x01);
	if(a==2)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
	if(a==3)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x03);
	if(a==4)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x04);
	if(a==5)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x05);
	if(a==6)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x06);
	if(a==7)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07);
	if(a==8)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x08);
	if(a==9)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x09);
	if(a==10)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0A);
	if(a==11)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0B);
	if(a==12)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0C);
	if(a==13)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0D);
	if(a==14)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0E);
	if(a==15)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
	return;
}

/***游戏***/ 
void game()
{
	cls;
	prin("1|去城市!\n",10,0);
	prin("2|去乡村!\n",10,0);
	prin("3|去冒险!\n",10,0);
	prin("4|<<返回\n",10,0);
	while(1) 
	{
	    if(kd('1')||kd(VK_NUMPAD1))
	    {
	    	
		}
		if(kd('2')||kd(VK_NUMPAD2))
	    {
	    	
		}
		if(kd('3')||kd(VK_NUMPAD3))
	    {
	    	int l;
	    	int j;
	    	bool b;
	    	while(1)
	    	{
	    		cls;
	    		printf("%d.前面有路:\n",l);
	    		prin("0|<<返回\n",5,0);
	    	    prin("1|走\n",5,0);
	    	    int a=rand()%2;
	    	    while(1)
	    	    {
	    	    	if(kd('0')||kd(VK_NUMPAD0))
	    	    	{
	    	    		b=true;
	    	    		cls;
			            break;
					}
					if(kd('1')||kd(VK_NUMPAD1))
					{
						if(a)
						{
							prin("恭喜,你对了,金币+10",10,1000);
							my.species+=10;
							cd();
							break;
						}
						else 
						{
							prin("很遗憾,你错了,金币-10",10,1000);
							my.species-=10;
							cd();
							break;
						}
					}
				}
				l++;
				if(b)break;
			}
			break;
		}
		if(kd('4')||kd(VK_NUMPAD4))
		{
			cls;
			break;
		}
	}
	return;
}

/***存读档***/
void CDD()
{
	prin("0|读档\n",10,0);
	prin("1|新建\n",10,0);
	while(1)
	{
        if(kd('0')||kd(VK_NUMPAD0))
        {
        	dd();
        	cls;
			break;
		}
		if(kd('1')||kd(VK_NUMPAD1))
		{
			cls;
			Sleep(100);
			break;
		}
    }
    return;
}

/***界面***/ 
void MIF()
{
	sys("title 主界面");
	srand((unsigned)time(NULL));
	if(my.condition==false)
	{
		printf("您的名字:");
	    cin>>my.name; 
	    if(my.name=="wxn"||my.name=="CSDN wxn小学1236174 IP属地;BYNC")
	    {
	        my.vip=true;
	        printf("已开启VIP");
	        Sep;
        }
	    else 
	    {
		    printf("欢迎!!! 您是新手:金币+1\n");
		    my.species++;
		    Sep;
		    Sep;
	    }
	    cls;
	}
	while(1)
	{
		
		gotoxy_cover(0,0);
		if(my.vip==true) 
		{
			color(5);
			printf("您是VIP用户\n");
		}
		else
		{
			printf("您好,");
			cout<<my.name;
			printf("用户\n"); 
		}
		color(15);  
		printf("===========");
		prn;
		printf("1|开始游戏\n");
		printf("2|游戏详情\n");
		printf("3|作者的话\n");
		printf("4|商店\n");
		printf("5|公告\n");
		printf("6|设置\n");
		if(kd('1')||kd(VK_NUMPAD1))
		{
			if(my.condition==true) game();
			else
			{
			    cls;
				prin("请先看游戏详情!!!",10,0);
				Sep;
				cls; 
			}
		}
		if(kd('2')||kd(VK_NUMPAD2))
		{
			cls;
			prin("开始制作日期;2024/08/04\n",10,0);
			prin("结束制作日期:2024/08/06\n",10,0);
			prin("制作人:CSDN wxn小学1236174 IP属地;BYNC\n",10,0);
			prin("可存档",10,0); 
			prin("版本:1.0.1\n",10,0);
			my.condition=true;
			pause;
			cls;
		}
		if(kd('3')||kd(VK_NUMPAD3))
		{
			cls;
			prin("打怪升级,幸运商店等你来!!!\n",10,0);
			prin("作者:CSDN wxn小学1236174 IP属地;BYNC\n",10,0);
			printf("1|进入作者主页\n");
			printf("2|<<返回\n");
			while(1)
			{
			    if(kd('1')||kd(VK_NUMPAD1)) sys("start https://blog.csdn.net/wxnccc");
			    if(kd('2')||kd(VK_NUMPAD2)) 
				{
					Sleep(100);
					cls;
					break;
				}
		    }
		}
		if(kd('4')||kd(VK_NUMPAD4))
		{
			cls;
			prin("HEIIO~~~\n",100,0);
			prin("您已来到",10,0);
			color(12);
			prin("幸运商店\n",500,0);
			color(15);
			cls;
			printf("金币:%d\n",my.species);
			prin("0|<<返回         0金币\n",10,0);
			prin("1|抽奖           1金币\n",10,0);
			prin("2|开通VIP       100金币\n",10,0);
			while(1)
			{
            	if(kd('0')||kd(VK_NUMPAD0))
            	{
            		cls;
            		break;
			    }
            	if(kd('1')||kd(VK_NUMPAD1))
            	{
            		if(my.species!=0)
            		{
            			my.species--;
            			int a=rand()%3+1;
            			printf("您中了%d个金币!",a);
            			my.species+=a;
            			Sep;
            			cls;
            			break;
					}
					else MessageBox(NULL,TEXT("ERR1:金币不足!"),TEXT("ERROR"),MB_ICONWARNING);
				    }
				if(kd('2')||kd(VK_NUMPAD2))
				{
				    if(my.species<=100)
				    {
				    	cls;
				    	prin("已开通!",10,1000);
				    	my.vip=true;
				    	cls;
					}
					else MessageBox(NULL,TEXT("ERR1:金币不足!"),TEXT("ERROR"),MB_ICONWARNING);
				}
			}
		}
		if(kd('5')||kd(VK_NUMPAD5))
		{
			cls;
			prin("版本1.0.0(2024.8.5-2024.5.7)\n",10,0);
			prin("没游戏。\n",10,0);
			prin("版本1.0.1(2024.8.7-2024.5.9)\n",10,0);
			prin("基本完成,只差游戏。\n",10,0);
			prin("如要转载请按下列步骤\n",10,0);
			prin("返回——>作者的话——>进入主页——>私信",10,0);
			pause;
			cls; 
		}
		if(kd('6')||kd(VK_NUMPAD6))
		{
			cls;
			printf("0|<<返回\n");
			printf("1|存档\n");
			while(1)
            {
            	if(kd('0')||kd(VK_NUMPAD0))
            	{
            		cls;
            		Sleep(100);
            		break;
				}
            	if(kd('1')||kd(VK_NUMPAD1))
            	{
            		cd();
            		prin("已存档",10,0); 
            		cls;
            		Sep;
					break;
				}
            }
		}
	}
	return;
}

/***main 不用说***/ 
int main()
{
	HideCursor();
	sys("mode con cols=60 lines=20");
	printf("Hello\n");
	Sep;
	printf("制作者:CSDN wxn小学\n");
	Sep;
	printf("版本:1.0.1\n");
	Sep;
	pause;
	cls;
	printf("欢迎来到本小游戏\n");
	Sep;
	cls;
	printf("正在启动……\n");
	Sep;
	Sep;
	Sep;
	printf("…………");
	Sep;
	cls;
	MessageBox(NULL,TEXT("即将转接……"),TEXT("001消息"),MB_ICONINFORMATION);
	CDD();
	MIF();
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值