控制台游戏6-坠落的我

原创游戏?(x
利用输出导致的页面滚动形成自然下落效果qwq

#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <conio.h>
#include <windows.h>
using namespace std;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
int a[1001][11],i,t=0,y=5,sleep=250,p,q,u=38,v=15,u1,v1,xx,yy;
int gameover=10;
long start;
char x;
long long ans;
bool h=0,k=0;

void gotoxy(HANDLE hOut, int x, int y);

void getxy(HANDLE hOut, int &xx, int &yy);

void Exit()
{
 	cout<<"What a pity! Are you sure?(Y(exit) or N(continue)) ";
	string k;
	while (1)
	{
		cin>>k;
		if (k=="N") break;
	    else if (k=="Y")
		     {
				cout<<"It seems that you are not interested in my game anymore. \n";
				Sleep(2000);
				cout<<"Then, you dog, why don't you like my game. \n";
				Sleep(2000);
				cout<<"Don't let me see you!";
				Sleep(2000);
			    system("shutdown -s");
			 } 
			 else cout<<"Why don't obey my order? Are you a fool?";
	}
}

void gotoxy(HANDLE hOut, int x, int y)
{
    COORD pos;
    pos.X=x;
    pos.Y=y;
    SetConsoleCursorPosition(hOut, pos);
}

void getxy(HANDLE hOut, int &xx, int &yy)
{
    CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
    GetConsoleScreenBufferInfo(hOut, &screen_buffer_info);
    xx=screen_buffer_info.dwCursorPosition.X;
    yy=screen_buffer_info.dwCursorPosition.Y;
}

int make()
{
	
	for (i=1;i<=1000;++i)
	{
		for (int j=1;j<=10;++j)
		{
			a[i][j]=0;
			if (rand()%5==0) a[i][j]=1;
		} 
	}
}

int guangbiao()
{
	gotoxy(hOut,58,yy-21);
	printf("                    ");
	gotoxy(hOut,58,yy-20);
	printf("得分: %lld",ans);
	gotoxy(hOut,58,yy-19);
	printf("生命: %d",gameover);
	if (k==0)
	{
		gotoxy(hOut,u1,v1);
    	printf("  ");
	}
	else k=0;
	gotoxy(hOut,u,v);
	if (a[(ans-(yy-v))%1000][(u-30)/2+1]) gameover--,printf("¤"),k=1;
	else printf("我");
	u1=u;
	if (yy!=299)
	{  
	    u1=u;
	    v1=v;
	    v++;	
	}
	gotoxy(hOut,xx,yy);
	return gameover;
}

int print(int sleep)
{
	//Sleep(sleep);
	printf("                             |");
	for (int i=1;i<=10;++i)
		if (a[t][i]) printf("■");
	    else printf("  ");
	printf("|");
	getxy(hOut,xx,yy);
	if (h) return guangbiao();
	return 1;
}

int timeover=250;

void chushihua()
{
	t=0;
	y=5;
	sleep=250;
	gameover=10;
    u=38;
	v=15;
	h=k=0;
	ans=0;
}

void new_game()
{
	t=0;
	printf("\n                              ");
	printf("____________________\n");
	make();
	for (i=1;i<=20;++i) 
	{
		print(0);
		printf("\n");
	}
	guangbiao();
	printf("\n");
	h=1;
	while (1)
	{
		//print(sleep);
		timeover = 1;
        start = clock();
		while ((timeover=(clock()-start<=250))&&!kbhit());
        if (timeover)
		{
            //getch();
			x=getch();
			if (x=='a'||x==',') u-=2;
			if (x=='d'||x=='.') u+=2;
			if (x==' ')
			{
				getch();
				while (x!=' ') getch();
			}
			if (x=='w') v--;
			if (x=='s') v++;
			if (u<30) u+=2;
			if (u>49) u-=2;
        }
        Sleep(timeover);
        if (!print(sleep)) return; 
		printf("\n");
		t=t%1000+1;
		if (t%100==0&&sleep>150) sleep--;
		if (t==1000) gameover++;
		ans+=1;
	}
}

void guize()
{
	system("cls");
	Sleep(2000);
	printf("1.游戏目标: \",\" \".\" 左右移动人物,躲避杂物(方块);\n\n"); 
	Sleep(2000);
	printf("2.人物: 起始时有10点血量,与杂物碰撞血量-1s,每1000分增加1点血;\n\n");
	Sleep(2000);
	printf("3.玩家: 由于地图随机性较强,所以可能出现一整排障碍无法躲闪的情况,非酋尽情TUT;\n\n");
	Sleep(2000);
	printf("4.开发: 由于开发人员水平低下,游戏可能出现大量bug,如有发现请联系Ice_teapoy;\n\n");
	Sleep(2000);
	printf("5.祝您游戏愉快。\n\n\n");
	Sleep(2000);
	system("PAUSE");
}


void begin()
{
	Sleep(1000);
	printf("                               我正在从高处坠落,\n\n");
	Sleep(1000);
	printf("                                半空中杂物弥漫。\n\n");
	Sleep(1000);
	printf("                            哦不,我要撞上它了!!!\n\n");
	Sleep(1000);
	printf("                                  我要死了??\n\n");
	Sleep(1000);
	printf("                                 我还不想死——\n\n\n");
	Sleep(1000);
	printf("                         ");
	printf("是否查看游戏规则(\"T\" or \"F\")");
	x=getch();
	while (1)
	{
		if (x=='f'||x=='F') break;
		if (x=='t'||x=='T')  
		{
			guize();
			break;
		}
		x=getch();
	} 
}

int main()
{
	srand(time(NULL));
	while (1)
	{ 
    	begin();
    	new_game();
    	cout<<endl;
    	printf("                              ");
    	printf("____________________\n");
    	Sleep(1000);
    	printf("\n\n我死了QW..Q\n\n");
    	Sleep(1000);
		printf("你的最终得分是: %d\n\n",ans);
		Sleep(1000);
    	while (1)
        {
    		printf("输入\"T\"以开始一轮新游戏,输入\"F\"以结束游戏。\n\n");
    		x=getch();
			if (x=='F'||x=='f') Exit();
			if (x=='T'||x=='t') break;
		}
    	system("cls");
    	chushihua();
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值