Discuz! Board

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

2023.2.11tcs1.0

[复制链接]

17

主题

17

帖子

637

积分

高级会员

Rank: 4

积分
637
发表于 2023-2-11 10:55:52 | 显示全部楼层 |阅读模式
[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 wallj=100;

struct body
{
    int x;
    int y; 
};
struct snake
{
	int len;
	int v;
	body bo[1000];
	char dir;
}sna;



void start()//初始化 
{
    srand(time(0));//随机种子函数      
    sna.v=20;
    sna.len=4;
	sna.dir='d';
	for(int i=0;i<4;i++)
	{
		sna.bo[i].x=20-i;
		sna.bo[i].y=15;	
    }

    
    
    
    //float g=0;
    initgraph(width, height);               //初始化图形界面
    setcolor(RED);  //设置画图线为红色
    setbkcolor(WHITE);//设置背景颜色为白色
    setfillcolor(RED);//设置填充颜色为红色
}

void update()//数据更新
{		

    
    /*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 drawball()//画球 
{

    //fillellipse(ball.x, ball.y, ball.radius, ball.radius); //画一个实心圆
    for(int i=0;i<sna.len;i++)
    {
    	setfillcolor(hsv2rgb(10*i%360, 1, 1));//设置填充颜色  参数(颜色,饱和度,明亮度)
    	bar(sna.bo[i].x*20,sna.bo[i].y*20,sna.bo[i].x*20+20,sna.bo[i].y*20+20);
    	
	}
    Sleep(10);
    cleardevice();         
}

int main()
{
    start();
    while(1)
    {
        update();
        drawball();
    }
    return 0;
}
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 02:03 , Processed in 0.049255 second(s), 24 queries .

Powered by Discuz! X3.4

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

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