Discuz! Board

 找回密码
 立即注册
查看: 314|回复: 0

2023.2.26贪吃蛇2.0无限破译版

[复制链接]

20

主题

33

帖子

3458

积分

论坛元老

Rank: 8Rank: 8

积分
3458

小火马 Lv:11
发表于 2023-2-26 17:49:34 | 显示全部楼层 |阅读模式
[C++] 纯文本查看 复制代码
#include <graphics.h>                 //包含EGE的头文件
#include<time.h> //包含随机数,时间函数
#include<bits/stdc++.h>
using namespace std;
int width =800;
int height =600;
int num;
  
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(LIGHTGRAY);//设置背景颜色为白色
    setfillcolor(BLUE);//设置填充颜色为红色
}
void yd()
{
	for(int i=sn.l-1;i>=0;i--)
	{
		sn.n[i+1].x=sn.n[i].x;
		sn.n[i+1].y=sn.n[i].y;
	}
	 switch (sn.fx) 
		{
            case 'w':
				{
                    sn.n[0].y--;
                }
                break;
            case 'a':
				{
                    sn.n[0].x--;
                }
                break;
            case 's':
				{
                    sn.n[0].y++;
                }
                break;
            case 'd':
				{
                    sn.n[0].x++;
                }
                break;
        }
} 
void update()//数据更新
{

    if(kbhit())
    {
        sn.fx= getch();
        yd();
    }
} 
 
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;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 04:58 , Processed in 0.048356 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表