程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> c語言貪吃蛇彩版,c語言貪吃蛇

c語言貪吃蛇彩版,c語言貪吃蛇

編輯:關於C語言

c語言貪吃蛇彩版,c語言貪吃蛇


#include <stdio.h>//沒寫完
#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\\劉三姐.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(1,16,"HIGHEST-SCORE:");//默認高度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);
//第二條框
setfillstyle(BS_SOLID);
setfillcolor(LIGHTGREEN);
fillrectangle(0,50,639,69);
//彩虹
float H = 190; // 色相
float S = 1; // 飽和度
float L = 0.7f; // 亮度
for(int y = 70; y < 480; y++)
{
L += 0.0005f;
setlinecolor( HSLtoRGB(H, S, L) );
line(0, y, 639, y);
}

// 畫彩虹(通過色相逐漸增加)
H = 0;
S = 1;
L = 0.5f;
setlinestyle(PS_SOLID, 2); // 設置線寬為 2
for(int r = 400; r > 344; r--)
{
H += 5;
setlinecolor( HSLtoRGB(H, S, L) );
circle(500, 480, r);
}

//星空
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); // 速度越快,顏色越亮
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);
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved