C Language Snake Color edition

Source: Internet
Author: User

#include <stdio.h>//not finished.
#include <conio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib, "WinMM.lib")
#include <string.h>
#include <math.h>
#include <time.h>
#include <graphics.h>
#define PI 3.1415926
#define WIDTH 640
#define HEIGHT 480
#define MAXSTAR 100
struct STAR
{
int x;
int y;
Double step;
int color;
}star[maxstar];
void frame ();
void Initstar (int);
void MoveStar (int);
int main ()
{
PlaySound ("k:\\resource\\ Liu Sanjie. wav", null,snd_filename| snd_async| Snd_loop);
Initgraph (width,height,nominimize);
SetBkColor (white);
Cleardevice ();
Frame ();
Getch ();
Closegraph ();
return 0;
}

void Frame ()

{

int i;
Srand ((unsigned) time (NULL));
SetColor (RGB (rand ()%225,rand ()%225,rand ()%225));
Rectangle (0,0,width-1,height-1);
SetColor (CYAN);
Line (0,49,width-1,49);
Outtextxy ("Present-score:");
Outtextxy (1,16, "Highest-score:");//Default height 13
Outtextxy (1,30, "start-times:");
Line (120,0,120,49);
Line (170,0,170,49);
Outtextxy (121,1, "888888");
Line (0,16,170,16);
Line (0,30,170,30);
Second box
Setfillstyle (Bs_solid);
Setfillcolor (LightGreen);
FillRectangle (0,50,639,69);
Rainbow
float H = 190;//hue
float S = 1;//saturation
float L = 0.7f;//brightness
for (int y = x; y < 480; y++)
{
L + = 0.0005f;
Setlinecolor (HSLtoRGB (H, S, L));
Line (0, y, 639, y);
}

Draw a rainbow (gradually increase through hue)
H = 0;
S = 1;
L = 0.5f;
Setlinestyle (Ps_solid, 2);//Set the line width to 2
for (int r = N; r > 344; r--)
{
H + = 5;
Setlinecolor (HSLtoRGB (H, S, L));
Circle (480, R);
}

Stars
SetBkColor (BLACK);
Setfillcolor (BLACK);
Solidrectangle (170,1,639,49);
for (i=0;i<maxstar;i++)
{
Initstar (i);
star[i].x = rand ()% (640-170) +170;
}
while (true)
{
for (i=0;i<maxstar;i++)
MoveStar (i);
Sleep (40);
}
}
void Initstar (int i)
{
star[i].x = 171;
STAR[I].Y = rand ()%50;
Star[i].step = (rand ()%5000)/1000.0+1;
Star[i].color = (int) (STAR[I].STEP * 255/6.0 + 0.5);//The faster the color, the brighter it becomes.
Star[i].color = RGB (Star[i].color, Star[i].color, Star[i].color);
}
void MoveStar (int i)
{
Putpixel (int) star[i].x, star[i].y, 0);
star[i].x + = Star[i].step;
if (star[i].x > 639)
Initstar (i);
Putpixel (int) star[i].x, star[i].y, Star[i].color);
}

C Language Snake Color edition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.