贪吃蛇 c++
来源:互联网 发布:linux查看jdk版本 编辑:程序博客网 时间:2024/06/17 13:44
各位大神帮我改一下,谢谢。
- #include <bits/stdc++.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
using namespace std;
struct in{
int x,y; //蛇身
};
char q[19][22]={'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
'#','*','*','*','O',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'};
//初始化地图
void start(int times)
{
int d=0,j=0;
int x1=9,y1=9;//豆子
int lenth = 3 ,x=1,y=4;//蛇身,蛇头
int number=0;//吃豆的数量
in a[340]; //蛇身最大值
for(int i=0;i<3;i++)
{
a[i].x=1;
a[i].y=i+1;
}
system("cls");
cout<<"得分"<<d<<endl;
cout<<"等级"<<j<<endl;
cout<<""<<times<<"毫秒移动一次"<<endl;
for(int i=0;i<19;i++)
{
for(int j=0;j<22;j++)
{
cout<<q[i][j];
}
cout<<endl;
}
int n , num ;
char ch='d'; //默认向右
while(1)
{
n = clock();
while(num=(clock()-n<=times));
if(kbhit())
{
ch=getch();
}
if(x==x1 && y==y1) //吃米
{
lenth++;
q[x][y]='*';
number++;
if(number==4)
{
number=0;
j++;
times=times-j*50;
}
do
{
srand(time(0));
x1 = rand()%16+1;
y1 = rand()%20+1; //刷米
}
while(q[x1][y1]!=' ');
d+=100;
}
else //不吃米
{
q[a[0].x][a[0].y]=' ';
for(int i=0;i<lenth;i++)
{
swap(a[i],a[i+1]);
}
a[lenth-1].x=x;
a[lenth-1].y=y;
}
for(int i=0;i<lenth;i++)
{
q[a[i].x][a[i].y]='*';
}
q[x][y]='*';
q[x1][y1]='*';
switch(ch)
{
case 'd': y++;break ;
case 'a': y--;break ;
case 'w': x--;break ;
case 's': x++;break ;
}
q[x][y]='O';
if((x==0 || x==18 || y==0 || y==21 )&&
(ch!='a' && ch!='d'&&ch!='w' && ch!= 's') )
{
system("cls");
cout<<"\t\tgame over";
return ;
}
else
{
for(int i=0;i<lenth;i++)
{
if(x==a[i].x && y== a[i].y)
{
system("cls");
cout<<"\t\tgame over";
return ;
}
}
}
system("cls");
cout<<"得分"<<d<<endl;
cout<<"等级"<<j<<endl;
cout<<""<<times<<"毫秒移动一次"<<endl;
for(int i=0;i<19;i++)
{
for(int j=0;j<22;j++)
{
cout<<q[i][j];
}
cout<<endl;
}
}
} - int main()
- {
- system("color f4");
cout<<"\n\n\t\t\t游戏即将开始!";
Sleep(500);
for(int i=3;i>=0;i--)
{
system("cls");
cout<<"\n\n\t\t\t\t倒计时:"<<i;
Sleep(1000);
}
start(500);
return 0;
}
阅读全文
0 0
- 贪吃蛇C实现
- 贪吃蛇C代码
- C代码 贪吃蛇
- [C++] Console 贪吃蛇
- c 贪吃蛇
- C版贪吃蛇
- 贪吃蛇(C语言版)
- 贪吃蛇,c,c++
- 贪吃蛇(c++)
- C语言贪吃蛇
- c语言“贪吃蛇”
- c语言贪吃蛇
- C#-测试贪吃蛇
- C++:贪吃蛇
- c语言版贪吃蛇
- 初学C#:贪吃蛇
- C语言:贪吃蛇
- C语言 贪吃蛇
- 103. Binary Tree Zigzag Level Order Traversal(BFS)
- mysql/oracle中create table as的用法
- centos无法安装pip解决办法
- python中Return浅析
- NVIDIA TK1 学习笔记(5):安装OpenCV
- 贪吃蛇 c++
- Java之instanceof
- JVM--详解虚拟机字节码执行引擎之栈帧结构
- python 判断debug
- 【Scikit-Learn 中文文档】处理文本数据
- Scala Cookbook.pdf 英文原版 免费下载
- List Form表单常用功能
- Android——使用OkHttp(含各种请求方法)
- java数字转换