打字游戏——基于C语言课程设计与游戏开发

#include<stdio.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
#define MAXN 10
struct Node {
	int x;
	int y;
	char n;
};
struct Node node[MAXN];
int s,lifecount,number;
int high,width,count;
int sdeep,sdeepm;
void gotoxy(int x,int y)
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(handle,pos);
}
void HideCursor()
{
  CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
  SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void startup()
{
	s = 0;
	lifecount = 5;
	number = 0;
	high = 20;
	width = 60;
	count = 0;
	sdeep = 100;
	sdeepm=300;
	
}
void show()
{
	int i;
	
	gotoxy(0,high+1);
	for(i=0;i<width+1;i++)
		printf("_");
	printf("\n");
	printf("级 别: %d\n",s);
	printf("得 分: %d\n",number);
	printf("生命值: %d\n",lifecount);
	HideCursor();
	
	
	
}
void createchar(int n)
{
	node[n].x = rand()%60;
	node[n].y = -1;
	node[n].n = rand()%26+'A'; 
}
void deletechar(int n)
{
	int i;
	for(i = n;i<count;i++)
		node[i] = node [i+1];
		
	
}
void updateWithoutInput()
{
	int i;
	static int sdeep = 0;
	if(sdeep%sdeepm==0&&count<MAXN)
	{
		createchar(count);
		count++;	
	}
	if(sdeep%sdeepm==0)
	{
		for(i =0;i<count;i++)
		{
			gotoxy(node[i].x,node[i].y);
			printf(" ");
			node[i].y++;
			if(node[i].y==high)
			{
				lifecount--;
				if(lifecount==0)
				{
					gotoxy(0,high+2);
					printf("游戏结束") ;
					exit(0);
				}
					
				deletechar(i);
				count--;
				
			}
			else
			{
				gotoxy(node[i].x,node[i].y);
				printf("%c",node[i].n);	
			} 
			
		}
	}
	sdeep++;
	
}
void updateWithInput()
{
	int i;
	char input;
	if(kbhit())
	{
		input = getch();
		for(i =0;i<count;i++)
			if(input == node[i].n||input-32 == node[i].n)
			{
				gotoxy(node[i].x,node[i].y);
				printf(" ");
				deletechar(i);
				count--;
				number++;
				if(number%10==0)
				{
					s++;
					if(sdeep>20)
						sdeep = sdeep -10;
					if(sdeep>60)
						sdeepm = sdeepm -30;
				}
				break;
			}
		
	}
}
int main()
{
	
	startup();
	while(1)
	{
		srand(time(NULL));
		
		show();
		updateWithoutInput();
		updateWithInput();
		
		
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值