[C++] 纯文本查看 复制代码 #include <graphics.h> //包含EGE的头文件
#include<time.h> //包含随机数,时间函数
#include<bits/stdc++.h>
using namespace std;
int width =800;
int height =600;
int num;
char ch;
int wallk=50;//障碍物宽和高
int wallc=100;//障碍物间的缺口长度
int score,score_flag;
struct body
{
int x,y;//坐标
};
struct snake
{
int l;//长
int v;//速度
char fx;//方向
body n[1000];
}sn;
void start()//初始化
{
srand(time(0));//随机种子函数
sn.l=4;
sn.v=20;
sn.fx='d';
for(int i=0;i<sn.l;i++)
{
sn.n[i].x=20-i;
sn.n[i].y=15;
}
initgraph(width, height); //初始化图形界面
setcolor(GREEN); //设置画图线为红色
setbkcolor(BLUE);//设置背景颜色为白色
setfillcolor(BLUE);//设置填充颜色为红色
}
void update()//数据更新
{
// ball.x=ball.x+ball.vx;
// ball.y=ball.y+ball.vy;
// ball.vy=ball.vy+ball.g;
// if(ball.y>=height-ball.radius)
// {
// ball.vy=-ball.vy;
// }
// if(ball.y<=ball.radius)
// {
// ball.vy=-ball.vy;
// }
// if(ball.x>=width-ball.radius)
// {
// ball.vx=-ball.vx;
// }
// if(ball.x<=ball.radius)
// {
// ball.vx=-ball.vx;
// }
//
// if(kbhit())
// {
// ch = getch();
// if(ch==' ')
// {
// ball.vy = -10;
// }
// }
}
void draw()//画球
{
for(int i=0;i<sn.l;i++)
{
setfillcolor(hsv2rgb(10*i%360, 1, 1));//设置填充颜色 参数(颜色,饱和度,明亮度)
bar(sn.n[i].x*20,sn.n[i].y*20,sn.n[i].x*20+20,sn.n[i].y*20+20);
}
Sleep(10);
cleardevice();
}
int main()
{
start();
while(1)
{
update();
draw();
}
return 0;
} |