一个经我改进的游戏,还带声音(Lv1-Lv2)

各位粉丝赏脸过来看一下:

我先说,转载 一句 也得 原文链接 + 私信,因为我和别人一样,不希望被人侵权。

还有,别顾着玩  未改进时 里的游戏啦。

当然,我也不是不让你玩。

我改的是他的 赛车。

还加了很多。

未改进时

未改进时 游戏缺陷(这也是我对Johnny_0760想说的)

希望大家别顾着玩,看一下:

1.缺陷:该游戏名为 “ 赛车 2 ” ,可是当 H 碰到 H 时, 游戏便结束了。

1.改进:将该游戏名改为 “ 躲避物体 " 在形象不过。

2.缺陷:明明有加速减速按钮,按下却没有变化,代码也未提及速减速按钮(这个可能是还未制作,暂时搁那的原因)。

2.改进:在下面的代码可见,我将 a d 按钮改成了 kd类型 。

3.缺陷:移动空间小,游戏速度慢了,刺激性弱,输出是:cout(有点慢)

3.改进:将二维数组 sae 【5】【3】改为 sae【5】【5】,与其他的一些地方进行改进,缩小移动时间,将cout改为printf

改进后:

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

#define sys system
#define box MessageBox
#define sep(a) Sleep(a)
#define prn printf("\n")
#define cls system("cls")
#define ST SetConsoleTitle
#define st system("time/T")
#define pause system("pause")
#define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
/***制作者:CSDN 小学的wxn***/ 
using namespace std;
struct my;
void cd(void);
struct my
{
	string name;
	string yd;
	long long password;
	bool condition,zdcd,sy,vip;
	int species;
}my;

/***存档***/ 
void cd(void)
{
	ofstream OutFile("存档.游戏");
    OutFile<<my.name<<endl;
    OutFile<<my.password<<endl;
    OutFile<<my.condition<<endl;
    OutFile<<my.zdcd<<endl;
    OutFile<<my.sy<<endl;
    OutFile<<my.yd<<endl;
	OutFile<<my.vip<<endl;
    OutFile<<my.species<<endl;
    OutFile.close();
    return;
}
 
/***读档***/ 
void dd(void)
{
	ifstream InFile("存档.游戏");
    InFile>>my.name;
	InFile>>my.password;
	InFile>>my.condition;
	InFile>>my.zdcd;
	InFile>>my.sy;
	InFile>>my.yd;
	InFile>>my.vip;
	InFile>>my.species;
    return;
}
/***使窗口移动到桌面居中位置***/
void centerwindow(RECT &rect, RECT &desktop)
{ 
	int width,height,dtWidth,dtHeight;
	bool bSuccess=false;
	HWND hwnd = GetDesktopWindow();
	GetWindowRect(hwnd,&desktop); 
	dtWidth=desktop.right-desktop.left;
	dtHeight=desktop.bottom-desktop.top;
	hwnd = GetForegroundWindow(); 
	GetWindowRect(hwnd,&rect); 
	width=rect.right-rect.left;
	height=rect.bottom-rect.top;
	bSuccess=MoveWindow(hwnd,(dtWidth-width)/2,(dtHeight-height)/2,width,height,true); 
	GetWindowRect(hwnd,&rect); 
	return ;
}

/***覆盖清屏**/ 
void gotoxy_0(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;
}

/***移动光标1***/ 
void gotoxy_1(int x,int y)
{
    COORD pos;pos.X=y*2;
	pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    return;
}

/***移动光标2***/ 
void gotoxy(int x,int y)
{
    COORD pos;pos.X=y;
	pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    return;
}

/***颜色***/ 
void yanse(int ForgC, int BackC)
{
	WORD wColor=((BackC & 0x0F)<<4)+(ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
	return;
}

/***移除快速编辑模式***/
void noedit()
{
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hStdin,&mode);
	mode&=~ENABLE_QUICK_EDIT_MODE;
	mode&=~ENABLE_INSERT_MODE;
	mode&=~ENABLE_MOUSE_INPUT;
	SetConsoleMode(hStdin,mode);
	return;
}

/***声音***/
void sy()
{
	if(my.sy==true)
	{
		if(my.yd=="随机")
		{
			int a;
			a=rand()%7+1;
			if(a==1)Beep(830.61,200);
			if(a==2)Beep(880,200);
			if(a==3)Beep(987.76,200);
			if(a==4)Beep(1108.73,200);
			if(a==5)Beep(1174.66,200);
			if(a==6)Beep(1318.52,200);
			if(a==7)Beep(1479.98,200);
		} 
		if(my.yd=="do  ")Beep(830.61,200);
		if(my.yd=="re")Beep(880,200);
		if(my.yd=="mi")Beep(987.76,200);
		if(my.yd=="fa")Beep(1108.73,200);
		if(my.yd=="so")Beep(1174.66,200);
		if(my.yd=="la")Beep(1318.52,200);
		if(my.yd=="si")Beep(1479.98,200);
	}
	return;
}

/***自动存档***/
void zdcd()
{
	if(my.zdcd==true)cd();
	return;
}
/***加载***/
void jiazai(int a,int b)
{
	cls;
	//手要断掉啦~~~ 
	ST("加载");
	for(int i=1;i<a;i++)
	{
		gotoxy_0(0,0);
		printf("  .       \n");
		printf(" .        \n");
		printf(". 加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf(" .        \n");
		printf(". 加载中  \n");
		printf(" .        \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf(". 加载中  \n");
		printf(" .        \n");
		printf("  .       \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf(" .        \n");
		printf("  ..      \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("  ...     \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("   ...    \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("    ...   \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("     ...  \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("        . \n");
		printf("      ..  \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("          \n");
		printf("  加载中 .\n");
		printf("        . \n");
		printf("       .  \n");
		sep(b);
		gotoxy_0(0,0);
		printf("          \n");
		printf("        . \n");
		printf("  加载中 .\n");
		printf("        . \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("       .  \n");
		printf("        . \n");
		printf("  加载中 .\n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("      ..  \n");
		printf("        . \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("     ...  \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("    ...   \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("   ...    \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("  ...     \n");
		printf("          \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
		printf("  ..      \n");
		printf(" .        \n");
		printf("  加载中  \n");
		printf("          \n");
		printf("          \n");
		sep(b);
		gotoxy_0(0,0);
	}
	cls;
	return;
} 

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

/***输出 2***/
void pr(string a,int b,int c)
{
	prin(a,b,c);
	getchar();
	cls;
	return;
}

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

/***密码验证***/
void password_authentication()
{
	o:
	cls;
	ST("密 码 认 证");
	yanse(2,0);
	printf("〓 〓 〓           〓 〓 〓\n");
	yanse(15,0);
	gotoxy_1(3,0);
	printf("忘记密码 或 新手:输入0");
	gotoxy_1(4,0);
	yanse(12,0);
	printf("不要冒充 ");
	yanse(6,0),
	printf("新手");
	yanse(13,0);
	gotoxy_1(0,4);
	prin("密 码 认 证",200,0);
	yanse(15,0);
	gotoxy_1(1,0);
	prin("输入密码:",10,0);
	gotoxy_1(2,0);
	yanse(15,0);
	int a;
	cin>>a;
	if(a==0)
	{
		cls;
		if(my.condition==false)
		{
			printf("检测到是新手\n");
			sep(1000);
			printf("设定名称为:\n");
            cin>>my.name;
			printf("设定密码为:\n");
            scanf("%d",&my.password);
            my.condition=true;
            zdcd();
            printf("设置成功!\n");
            sep(1000);
            cls; 
			return;
		}
		else
		{
			wt:
			cls;
			string d;
			printf("用户名:");
			cin>>d;
			if(d!=my.name)
			{
				cls;
				printf("未找到该用户!");
				sep(2000);
				goto wt;
			}
			cls;
			int c;
			cls;
			printf("请接收6位验证码(3s)");
			sep(2000);
			cls;
			int randomnumber=rand()%999999+100000;
			printf("%d(验)\n",randomnumber);
			sep(3000);
			cls;
			printf("输入验正码\n");
			scanf("%d",&c);
			cls;
			if(c==randomnumber)
			{
			    cls;
				printf("\a验证通过\a\n");
				printf("你的密码:%d",my.password);
				sep(5000);
				cls;
				return;
			}	
			else
			{
				cls;
				printf("!!!");
				sep(1000);
				goto wt;
			}
	    }
	}
	else if(a==my.password)
	{
		cls;
		printf("\a验证通过\a");
		sep(1000);
		cls;
		return;
	}
	else
	{
		cls;
		printf("错误!");
		sep(1000);
		goto o;
	}
}
int x_what(int x)
{//取随机数
	srand((unsigned)time(NULL));
	return( rand() % x);
}

/***游戏一***/
void game1()
{
	int dx,dy;
	int mx,my;
	int sea[5][5];
	int ms=0;
	int maxms=0;
	int healthy=1;
	int sd=500;
	ms=0;
	char ch;
	for(int i=0;i<5;i++)
	{
		for(int j=0;j<5;j++)
		{
			sea[i][j]=0;
		}
	}
	sea[4][1]=8;
	mx=4;
	my=1;
	printf("+躲+\n");
	printf("+避+\n");
	printf("+物+\n");
	printf("+体+\n");
	printf("+..+\n");
	while(!kbhit())
	sy();
	cls;
	printf("摇杆↑↓←→移动");
	Sleep(2000);
	dx=1;
	cls;
	while(healthy>0)
	{
		if(kd(VK_UP))
		{
			if(mx>0)
			{
				sy();
				mx--;
			}
		}
		if(kd(VK_DOWN))
		{
			if(mx<4)
			{
				sy();
				mx++;
			}
		}
		if(kd(VK_LEFT))
		{
			if(my>0)
			{
				sy();
				my--;
			}
		}
		if(kd(VK_RIGHT))
		{
			if(my<4)
			{
				sy();
				my++;
			}
		}
		yanse(15,0);
		cout<<ms<<"米"<<endl; 
		for(int i=0;i<5;i++)
		{
			for(int j=0;j<5;j++)
			{
				if(i==mx&&j==my)
				{
					yanse(12,0);
					printf("H");
				}
				else if(i==dx&&j==dy)
				{
					yanse(9,0);
					printf("H");
				}
				else
				{
					yanse(8,0);
					printf("*");
				}
			}
			cout<<endl;
		}
		if(dx==10)
		{
			dx=0;
			dy=x_what(5);
		}
		else
		{
			dx++;
		}
		Sleep(200);
		gotoxy_0(0,0); 
		ms+=50;
		if(dy==my&&dx==mx)
		{
			healthy--;
		}
	}
	cls;
	yanse(15,0);
	cout<<ms<<"米"<<endl;
	cout<<"游戏结束!"<<endl;
	Sleep(2000);
	cls;
	return;
} 
/***游戏***/
void game()
{
	while(1)
	{
		ST("游戏");
		gotoxy_0(0,0);
		gotoxy(0,7);
		printf("1|躲避物体");
		gotoxy(1,9);
		printf("2|退出");
		if(kd('1')||kd(VK_NUMPAD1))
		{
			sy();
			sep(100);
			cls;
			game1();
		}
		if(kd('2')||kd(VK_NUMPAD2))
		{
			sy();
			sep(100);
			cls;
			break;
		}
	}
} 
/***MIF***/
void MIF()
{
	sys("mode con cols=24 lines=10");
	while(1)
	{
		ST("界面");
		gotoxy_0(0,0);
		gotoxy(3,7);
		printf("1|进入游戏");
		gotoxy(4,9);
		printf("2|设置");
		gotoxy(5,9);
		printf("3|退出"); 
		if(kd('1')||kd(VK_NUMPAD1))
		{
			sy();
			sep(100);
			cls;
			game(); 
			
		}
		if(kd('2')||kd(VK_NUMPAD2))
		{
			sy();
			sep(100);
			cls;
			while(1)
			{
				ST("设置");
				gotoxy_0(0,0);
				cout<<my.name<<"的设置:"<<endl;
				gotoxy(2,5);
				printf("1.自动存档  ");
				if(my.zdcd==true)yanse(2,0),printf("开"); 
				else yanse(12,0),printf("关");
				yanse(15,0);
				gotoxy(3,7);
				printf("2.声音  ");
				if(my.sy==true)yanse(2,0),printf("开"); 
				else yanse(12,0),printf("关");
				yanse(15,0);
				gotoxy(4,6);
				if(my.yd!="随机")printf(" ");
				printf("3.音调  ");
				cout<<my.yd;
				yanse(15,0);
				gotoxy(5,7);
				printf("4.恢复默认"); 
				gotoxy(6,9);
				printf("5.返回\n");
				if(kd('1')||kd(VK_NUMPAD1))
				{
					sy();
					sep(100);
					if(my.zdcd==false)my.zdcd=true;
					else my.zdcd=false;
					cd();
				}
				if(kd('2')||kd(VK_NUMPAD2))
				{
					sep(100);
					if(my.sy==false)my.sy=true;
					else my.sy=false;
					sy();
					cd();
				}
				if(kd('3')||kd(VK_NUMPAD3))
				{
					sep(100);
					if(my.yd=="do  ")my.yd="re";
					else if(my.yd=="re")my.yd="mi";
					else if(my.yd=="mi")my.yd="fa";
					else if(my.yd=="fa")my.yd="so";
					else if(my.yd=="so")my.yd="la";
					else if(my.yd=="la")my.yd="si";
					else if(my.yd=="si")my.yd="随机";
					else my.yd="do  ";
					sy();
					zdcd();
				}
				if(kd('4')||kd(VK_NUMPAD4))
				{
					sep(100);
					my.zdcd=true;
					my.sy=true;
					my.yd="随机";
					zdcd();
					sy();
				}
				if(kd('5')||kd(VK_NUMPAD5))
				{
					sy();
					sep(100);
					cls;
					break;
				}
			}
		}
		if(kd('3')||kd(VK_NUMPAD3))
		{
			sy();
			sep(100);
			cls;
			break;
		}
	}
}

/***main***/ 
int main()
{
	noedit();
	HideCursor();
	RECT Rect,rectDesktop;
	centerwindow(Rect,rectDesktop);
	if(my.condition==false)
	{
		my.zdcd=true;
		my.sy=true;
		my.yd="随机";
		ST("介绍");
		sys("mode con cols=66 lines=20");
		st;
		prin("Hello",10,0);
		prn;
		prin("制作者:CSDN 小学的wxn",10,0);
		prn;
		pause;
		cls;
		prin("欢迎来到本小游戏",10,1000);
		cls;
		box(NULL,TEXT("即将转接……"),TEXT("01消息"),MB_OK);
	}
	CDD();
	password_authentication(); 
	jiazai(10,10);
	MIF();
}

beybey~

哪位大神有更好建议?

Lv2获取吗:101100111000

私信发送获取吗可获得 Lv2 代码

很神秘的   L   v   2   !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值