一条不往左的废物蛇

不知哪里出了问题,这条蛇一往左走就死

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
using namespace std;
int  GameOver=0;

struct Body    
{int x,y;
Body *next; 
};

void SetPos(int i,int j)
{
	COORD pos={i-1,j-1};
	HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(Out,pos);
} 

class Sneak
{
	private:
		Body *head;
		int Direction;
		int Count;
		int Speed;
		int FoodExist;
		int Food_x;
		int Food_y;
	public:
	    Sneak(int a=3,int b=4,int c=1,int d=0)
		{
			FoodExist=d;
			Body *temp1,*temp2;
			
		    head=new(Body);
			head->x=4;
			head->y=2;
			
			temp1=new(Body);
			temp1->x=3;
			temp1->y=2;
			
			temp2=new(Body);
			temp2->x=2;
			temp2->y=2;
			
			head->next=temp1;
			temp1->next=temp2;
			temp2->next=NULL;
			
			Direction=b;
			Count=a;
			Speed=c;	
		}
		void Map();
		void Paint();
		void Food();
		int Over();
		void Gaming();
		void Move();	 
};
void Sneak::Map()

{
	int i=1;
	for(i=1;i<=50;i++)
	{
	SetPos(i,1);
	cout<<"-"; 
	}
	for(i=2;i<=25;i++)
	{
	SetPos(1,i);
	cout<<"|";
	SetPos(50,i);
	cout<<"|";
    }
    for(i=1;i<=50;i++)
    {
    	SetPos(i,25);
    	cout<<"-";
    }
	SetPos(54,3);
	cout<<"贪吃蛇";
	SetPos(54,5);
	cout<<"长度"<<Count;
	SetPos(54,7);
	cout<<"LEVEL:"<<Speed;	
}
void Sneak::Food()
{
	Body *p;
	int InBody=0;
	srand((int)time(0));
	while(1)
	{
		Food_x=rand()%48+2;
		Food_y=rand()%23+2;
		p=head;
		while(p!=NULL)
		{
			if(p->x==Food_x&&p->y==Food_y)
			{InBody=1;
			break;
			}
			p=p->next;
		}
		if(InBody==0)break;
		InBody=0;
	}
} 
int Sneak::Over()
{
	Body *p;
	p=head;
	if((head->x)>=50||(head->y)<=1||(head->y)>=25)
    return 1;
    p=head->next;
    while(p!=NULL)
    {
    	if((head->x==p->x)&&head->y==p->y)return 1;
    	p=p->next;
    }
    return 0;
}
void Sneak::Paint()
{
	Body *p;
	p=head;
	while(p!=NULL)
	{
		SetPos(p->x,p->y);
		cout<<"*";
		p=p->next;
	}
	SetPos(Food_x,Food_y);
	cout<<"*";
}
void Sneak::Move()
{
	Body *New;
	New=new(Body);
	if(Direction==1)
	{
		New->x=head->x;
		New->y=head->y-1;
		New->next=head;
		head=New;
	}
	if(Direction==2)
	{
		New->x==head->x-1;
		New->y=head->y;
		New->next=head;
		head=New;
	}
		if(Direction==3)
	{
		New->x=head->x;
		New->y=head->y+1;
		New->next=head;
		head=New;
	}
		if(Direction==4)
	{
		New->x=head->x+1;
		New->y=head->y;
		New->next=head;
		head=New;
	}	
}
void Sneak::Gaming()
{
	system("cls");
	char x;
	Body *p;
	Map();
	Paint();
	while(1)
 {   if(_kbhit())
	{
		x=_getch();
		if(x=='W'||x=='w'&&Direction==3)Direction=1;
		if(x=='S'||x=='s'&&Direction==1)Direction=3;
		if(x=='A'||x=='a'&&Direction==4)Direction=2;
		if(x=='D'||x=='d'&&Direction==2)Direction=4;
		while(_kbhit())_getch();
	}
	if(FoodExist==0)
	{
		Food();
		FoodExist=1;
	}
	Move();
	if(head->x==Food_x&&head->y==Food_y)
	{FoodExist=0;
	Count++;
	SetPos(54,5);
	cout<<"长度:"<<Count;
	if(Count%10==0) 
	{Speed++;
	SetPos(54,7);
	cout<<"LEVEL:"<<Speed;
	} 
	if(Speed==10)break;
	}
	Paint();
	if(FoodExist==1)
	{
		p=head;
		while((p->next)->next!=NULL)p=p->next;
		SetPos(p->next->x,p->next->y);
		cout<<" ";
		delete(p->next);
		p->next=NULL;
	}	
	if(Over())break;
	Sleep(500-Speed*50);
 }
 system("cls");
 if(Speed==10)
 {
 	SetPos(25,25);
 	cout<<"碉堡-_-||你通关了"<<endl;
	 system("pause"); 
 } 
 else{SetPos(25,10);
      cout<<"-0-沙雕,你挂了,你的小蛇才这么长:"<<cout<<endl;
	  system("pause"); 
      }
}
int main()
{
	Sneak game;
	system("cls");
	cout<<"*****************************************************"<<endl;
	cout<<"*                        贪吃蛇                     *"<<endl;
	cout<<"*****************************************************"<<endl;
	cout<<"*                说明                               *"<<endl;
	cout<<"*            W,A,S,D控制移动                        *"<<endl;
	cout<<"*       每10节蛇身升一级,并提高速度,10级通关      *"<<endl;
	cout<<"*****************************************************"<<endl;
	
	cout<<"*********         任意键开始   **********************"<<endl;
_getch();
    game.Gaming();
	return 0;	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值