C language snake color edition, C language snake
# Include <stdio. h> // not completed
# 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 san .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 (1,1, "PRESENT-SCORE :");
Outtextxy (, "HIGHEST-SCORE:"); // default Height: 13
Outtextxy (1,30, "START-TIMES :");
Line (120,0, 120,49 );
Line (170,0, 170,49 );
Outtextxy (888888 ");
Line (, 17 );
Line );
// The second Frame
Setfillstyle (BS_SOLID );
Setfillcolor (LIGHTGREEN );
Fillrectangle );
// Rainbow
Float H = 190; // color
Float S = 1; // saturation
Float L = 0.7f; // brightness
For (int y = 70; y <480; y ++)
{
L + = 0.0005f;
Setlinecolor (HSLtoRGB (H, S, L ));
Line (0, y, 639, y );
}
// Draw a rainbow)
H = 0;
S = 1;
L = 0.5f;
Setlinestyle (PS_SOLID, 2); // set the line width to 2
For (int r = 400; r> 344; r --)
{
H + = 5;
Setlinecolor (HSLtoRGB (H, S, L ));
Circle (500,480, r );
}
// Star
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 speed, the brighter the color.
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 );
}