高分:求Windows下的C语言版的绘图程序(代码)。

tc001 2003-05-07 05:56:39
高分:求Windows下的C语言版的绘图程序(代码)。
...全文
40 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiuyu 2003-05-17
  • 打赏
  • 举报
回复
我用vc6.0,
出现错误,说,找不到<bios.h>
怎么回事?
arfi 2003-05-07
  • 打赏
  • 举报
回复
续:
int GetResult(void)
{
return result;
}

int KeyEvent(void)
{
int key = 0;

while(!key)
key = bioskey(1);

key = bioskey(0);

return key;
}

int SelectOperate(int key)
{
static int select = 0;
static int action = 0;
static void *tempmap = NULL;
struct MAP_LIST baktemp, bakcurrent;

switch(key)
{
case KEY_RET:
if(current->num != 0)
{
if(action == 0)
{
select ^= 1;
if(select == 1)
{
ShowTheMap(current);
setfillstyle(SOLID_FILL, RED);
floodfill(current->mx+1, current->my+1, YELLOW);
getimage(current->mx, current->my, \
current->mx+map[current->index].width, \
current->my+map[current->index].thickness-1, tempmap);
}
else
{
ShowTheMap(current);
setfillpattern(pattern, LIGHTGRAY);
floodfill(current->mx+1, current->my+1, YELLOW);
}
}
else /* action == 1 */
{
if(temp->center == current->center)
{
/*cancel the selected status*/
setfillpattern(pattern, LIGHTGRAY);
floodfill(temp->mx+1, temp->my+1, YELLOW);

action = 0;
select = 0;
}
else if( (temp->num == 0) || (map[current->index].width < map[temp->index].width) )
{
memcpy(&bakcurrent, current, sizeof(struct MAP_LIST));

/*cancel the selected status*/
setfillpattern(pattern, LIGHTGRAY);
floodfill(temp->center-map[current->index].width/2+1, \
temp->my-map[current->index].thickness+1, YELLOW);

/*ajust the info of the list*/
current->index = map[current->index].next;
current->mx = current->center-map[current->index].width/2;
current->my = current->my+map[bakcurrent.index].thickness;
current->num--;

map[bakcurrent.index].next = temp->index;

temp->index = bakcurrent.index;
temp->mx = temp->center-map[temp->index].width/2;
temp->my = temp->my-map[temp->index].thickness;
temp->num++;

current = temp;
action = 0;
select = 0;
}
}
}
break;
case KEY_ESC:
result = TERMINATE;
break;
case KEY_LEFT:
if(select == 1)
{
memcpy(&baktemp, temp, sizeof(struct MAP_LIST));
temp = temp->left;

/*Erase the selected bitmap(current)*/
if(baktemp.center == current->center)
putimage(baktemp.mx, baktemp.my, tempmap, XOR_PUT);
else
putimage(baktemp.center-map[current->index].width/2, \
baktemp.my-map[current->index].thickness, \
tempmap, XOR_PUT);

/*Display the selected bitmap on left.*/
if(temp->center == current->center)
putimage(temp->mx, temp->my, tempmap, COPY_PUT);
else
putimage(temp->center-map[current->index].width/2, \
temp->my-map[current->index].thickness, \
tempmap, COPY_PUT);

action = 1;
}
else
{
memcpy(&bakcurrent, current, sizeof(struct MAP_LIST));
do
{
current = current->left;
}while(current->num == 0);

rectangle(bakcurrent.mx, bakcurrent.my, \
bakcurrent.mx+map[bakcurrent.index].width, \
bakcurrent.my+map[bakcurrent.index].thickness-1);
ShowTheMap(current);
temp = current;
}
break;
case KEY_RIGHT:
if(select == 1)
{
memcpy(&baktemp, temp, sizeof(struct MAP_LIST));
temp = temp->right;

/*Erase the selected bitmap(current)*/
if(baktemp.center == current->center)
putimage(baktemp.mx, baktemp.my, tempmap, XOR_PUT);
else
putimage(baktemp.center-map[current->index].width/2, \
baktemp.my-map[current->index].thickness, \
tempmap, XOR_PUT);

/*Display the selected bitmap on right.*/
if(temp->center == current->center)
putimage(temp->mx, temp->my, tempmap, COPY_PUT);
else
putimage(temp->center-map[current->index].width/2, \
temp->my-map[current->index].thickness, \
tempmap, COPY_PUT);

action = 1;
}
else
{
memcpy(&bakcurrent, current, sizeof(struct MAP_LIST));
do
{
current = current->right;
}while(current->num == 0);

rectangle(bakcurrent.mx, bakcurrent.my, \
bakcurrent.mx+map[bakcurrent.index].width, \
bakcurrent.my+map[bakcurrent.index].thickness-1);
ShowTheMap(current);
temp = current;
}
break;
default:
break;
}
return 0;
}

void GameOver(void)
{
closegraph();
}
arfi 2003-05-07
  • 打赏
  • 举报
回复
汉诺塔游戏:
/********************************************************************
* The C source file is about playing Hanoi game.
*********************************************************************/

/********************************************************************
* STEPS:
*
* 1. data initializtion.
* 2. get key event.
* 3. operate according to the key pressed.
* 4. check the result of each operation to see whether succeed. if su-
* cceed, terminate.
*
* REQUESTS:
*
* 1. give the total num of steps.
* 2. give the time used.
*********************************************************************/

#include <stdio.h>
#include <bios.h>
#include <alloc.h>
#include <graphics.h>


#define MAX 7
#define QEND 0xff
#define TERMINATE -1

#define SOURCE 100
#define VIA 300
#define DEST 500
#define WIDTH 8
#define THICK 10
#define CHANGE 5

#define KEY_RET 0x1c0d
#define KEY_ESC 0x011b
#define KEY_LEFT 0x4b00
#define KEY_RIGHT 0x4d00

#define BOTTOM 350

struct BITMAP
{
int thickness;
int width;
void *pmap;
int index;
int next;
};

struct MAP_LIST
{
int index;
int num;
int center;
int mx, my; /*the point to lefttop*/
struct MAP_LIST *left;
struct MAP_LIST *right;
};

char pattern[8] = {0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,0xee};
struct BITMAP map[MAX];
struct MAP_LIST sour, via, dest;
struct MAP_LIST *current;
struct MAP_LIST *temp;
int result;

void GameInit(void);
void GameOver(void);
int GetResult(void);
int KeyEvent(void);
int SelectOperate(int key);

void main(void)
{
int key;

GameInit();

while(TERMINATE != GetResult())
{
key = KeyEvent();
SelectOperate(key);
}

GameOver();
}


void StartGraph(void)
{
int gdriver = VGA, gmode = VGAHI;
int errorcode;

registerbgidriver(EGAVGA_driver);
initgraph(&gdriver, &gmode, "");
if( (errorcode = graphresult()) != grOk )
{
printf("Graphics error: %d\n", errorcode);
getch();
abort();
}
}

void ShowTheMap(struct MAP_LIST *pm)
{
setcolor(YELLOW);
rectangle(pm->mx, pm->my, pm->mx+map[pm->index].width, \
pm->my+map[pm->index].thickness-1);
/* setfillpattern(pattern, LIGHTGRAY);
floodfill(pm->mx+1, pm->my+1, YELLOW);*/
setcolor(WHITE);
}

void BitMapInit(int n)
{
unsigned int size;
int i;

setcolor(WHITE);

for(i=n-1; i>=0; i--)
{
rectangle(SOURCE-WIDTH-i*CHANGE, BOTTOM-(n-i)*THICK, SOURCE+WIDTH+i*CHANGE, BOTTOM-(n-i-1)*THICK-1);
}
for(i=n-1; i>=0; i--)
{
setfillpattern(pattern, LIGHTGRAY);
floodfill(SOURCE, BOTTOM-(n-i)*THICK-1+THICK/2, WHITE);
}

/* save the bitmaps. */
for(i=n-1; i>=0; i--)
{
map[i].thickness = THICK;
map[i].width = (WIDTH+i*CHANGE)*2;
size = imagesize(SOURCE-WIDTH-i*CHANGE, BOTTOM-(n-i)*THICK, SOURCE+WIDTH+i*CHANGE, BOTTOM-(n-i-1)*THICK-1);
map[i].pmap = malloc(size);
if(map[i].pmap == NULL)
{
printf("In BitMapInit(): alloc memory fail!\n");
exit(1);
}
getimage(SOURCE-WIDTH-i*CHANGE, BOTTOM-(n-i)*THICK, SOURCE+WIDTH+i*CHANGE, BOTTOM-(n-i-1)*THICK-1, map[i].pmap);
map[i].index = i;
map[i].next = i+1;
}
map[n-1].next = QEND;

sour.index = 0;
sour.num = n;
sour.center = SOURCE;
sour.mx = sour.center - map[sour.index].width/2;
sour.my = BOTTOM - sour.num*map[sour.index].thickness;
sour.left = &dest;
sour.right = &via;

via.index = QEND;
via.num = 0;
via.center = VIA;
via.mx = via.center;
via.my = BOTTOM;
via.left = &sour;
via.right = &dest;

dest.index = QEND;
dest.num = 0;
dest.center = DEST;
dest.mx = dest.center;
dest.my = BOTTOM;
dest.left = &via;
dest.right = &sour;

current = &sour;
temp = current;
}

void GameInit(void)
{
int count;

clrscr();
while(1)
{
printf("Please input the count(1--%d):",MAX);
scanf("%d", &count);
if( (count>=1) && (count<=MAX) )
break;
else
printf("Out of range!\n");
}

clrscr();
StartGraph();

setcolor(BLUE);
rectangle(50, 200, 550, 350);

setcolor(RED);
line(SOURCE-1, BOTTOM, SOURCE+1, BOTTOM);
line(VIA-1, BOTTOM, VIA+1, BOTTOM);
line(DEST-1, BOTTOM, DEST+1, BOTTOM);
setcolor(WHITE);

BitMapInit(count);

ShowTheMap(current);
}

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧