当前位置: 代码迷 >> C语言 >> [BCCNCCode] C源码染色器
  详细解决方案

[BCCNCCode] C源码染色器

热度:347   发布时间:2007-07-31 08:45:00.0
<TABLE borderColor=#cccccc cellSpacing=0 cellPadding=3 bgColor=#ffffff border=4><TBODY><TR><TD><P><TABLE style=TABLE-LAYOUT: fixed; WORD-BREAK: break-all height=* width=98% align=center border=0><TBODY><TR><TD style=FONT-SIZE: 9pt; LINE-HEIGHT: 12pt width=100% height=100%><BR><STYLE>FIELDSET{padding:0px 0PX 30PX 30PX;}LEGEND{color:red;font-weight:bold;margin-bottom:25px;}</STYLE><FIELDSET><LEGEND>此源码由BC-CN论坛C源码染色机染色</LEGEND><FONT color=#090909>程序作者:knocker<br> BC-CNCode BUG版 如有差错请见谅</FIELDSET><BR><DIV align=right><FONT color=#000066></FONT></DIV></TD></TR></TBODY></TABLE></P></TD></TR></TBODY></TABLE>

----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------
Test:


´ËÔ´ÂëÓÉBC-CNÂÛ̳CÔ´ÂëȾɫ»úȾɫ³ÌÐò×÷Õߣºknocker
BC-CNCode BUG°æ ÈçÓвî´íÇë¼ûÁÂ


/* Hit.cpp */

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>
#include <graphics.h>

#define SCREEN_HEIGHT 480
#define SCREEN_WIDTH 640

static int dx=1,dy=1;
static unsigned int r=20;
static unsigned int cx=0,cy=0;

unsigned int randrange(int start,int end) {
randomize();
unsigned int ret=start+rand() % (end-start) + 1;
return ret;
}

void igdrv(void) {
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk) {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/* return with error code */

}
}

void draw_border(void) {
setcolor(WHITE);
line(0,0,SCREEN_WIDTH-1,0);
line(0,0,0,SCREEN_HEIGHT-1);
line(0,SCREEN_HEIGHT-1,SCREEN_WIDTH-1,SCREEN_HEIGHT-1);
line(SCREEN_WIDTH-1,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1);
}

void draw_ball(void) {
cx=randrange(r+1,SCREEN_WIDTH-2-r);
cy=randrange(r+1,SCREEN_HEIGHT-2-r);
setcolor(WHITE);
circle(cx,cy,r);
}

void direction(void) {
randomize();
dx = (rand() % 100+1) < 50 ? dx : -dx;
dy = (rand() % 100+1) < 50 ? dy : -dy;
}

void reflect(void) {
if(cx==r+1||cx==SCREEN_WIDTH-r-2)
dx=-dx;
if(cy==r+1||cy==SCREEN_HEIGHT-r-2)
dy=-dy;
}

int main() {
int flag=1,key;
igdrv();

// draw the border
draw_border();

// first time , draw the ball
draw_ball();

// random a direction of action
direction();
do {
do {
delay(2);
if(flag) {
setcolor(BLACK);
circle(cx,cy,r);
cx+=dx;
cy+=dy;
setcolor(WHITE);
circle(cx,cy,r);

if((cx==r+1||cx==SCREEN_WIDTH-r-2)||(cy==r+1||cy==SCREEN_HEIGHT-r-2)) {
flag=0;
}
}
else {
reflect();
flag=1;
}
} while(!bioskey(1));

// Press esc to exit the program.
} while((key=bioskey(0))!=0x11b);

closegraph();
return 0;
}

[此贴子已经被作者于2007-7-31 13:30:52编辑过]


----------------解决方案--------------------------------------------------------
很棒啊,最好把已定义的和未定义的也用不同颜色分开.如:
int main()
{
int i;
printf("%d",i);
}
int main()
{
printf("%d",i);
}
虽然很难实现,但Knocker你一定有办法的.

----------------解决方案--------------------------------------------------------
果然是强!
----------------解决方案--------------------------------------------------------