博文

c语言画蜡烛(2006-06-16 11:03:00)

摘要: 新3.2版QQ空间代码       #include<stdlib.h>#include<stdio.h>#include<graphics.h>int main(){  int gdriver=VGA, gmode=VGAHI, i,j,size,s2,s3,s4;  initgraph(&gdriver, &gmode, "c:\\tc");  setbkcolor(BLUE);  cleardevice();  setcolor(12);  setfillstyle( 4,4) ;  bar(180,360,200,320);   /*蜡烛*/  sector(190,310,0,360,4,6);  setcolor(6);  getch();  closegraph();}  ......

阅读全文(3122) | 评论:0

迷宫程序1.10版(2006-06-16 10:54:00)

摘要:新3.2版QQ空间代码       程序目的:输入一个任意大小的迷宫,用栈求出一条走出迷宫的路径,并显示在屏幕上。程序实现:可以实现载入迷宫和保存迷宫,附带文件中有4个测试迷宫路径的文件test1~4.dd。请将这些文件拷贝到TC当前目录下,或者在载入时写明完全路径。由于屏幕大小的限制,当用户自己输入迷宫时一定要注意:迷宫大小是有限制的,不小于4*3,不大于30*20。否则会出现错误信息。输入开始时全是墙,用上下左右键移动,用Del键删除墙,形成通路,用Enter键添加墙。输入结束时可以将迷宫保存下来,以dd为扩展名。输入完毕时用F9键来得到结果,找到路径时,屏幕下方会出现Path found,否则出现Path not found。程序经Turbo C 2.0编译调试成功。运行时不用添加任何运行库。不可以在VC上编译。下载DOS版和windows版的迷宫游戏全部代码用户名:migong ----------------------------------------------------------------------------------/*MazePath Demo BY Turbo C 2.0Copyright(c) RoverUnion. All right reserved.Filename: Maze.cAuthor Dongchengyu.Ver 1.10*/#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <conio.h>#include <dos.h>#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define F9 0x43#define Esc 0x1b#define Del 0x53#define Home 0x47#define End 0x4f#define Space 0x20#define Up 0x48#define Down 0x50#define Left 0x4b#define Right 0x4d#define Enter 0x0d#define F2 0x3c#define F3......

阅读全文(2601) | 评论:1

设计彩色框的C源程序(2006-06-16 10:43:00)

摘要:   /*** Short driver module**/ main(){clrscr();box(1,1,23,79);box(2,2,21,77);box(3,3,19,75);box(4,4,17,73);box(5,5,15,71);box(6,6,13,69);box(7,7,11,67);box(8,8,9,65);box(9,9,7,63);box(10,10,5,61);box(11,11,3,59);box(12,12,1,57);poscur(24,1);} /************************************************************* BOX **----------------------------------------------------------** Written by: Jeff Ebert 7/01/87 ** Modified by: xxxxxxxxxx ** ** Please modify me! ** Possible Enhancements include but are not limited to: ** 1) Variable box character styles [1 line or 2] ** 2) Error checking ** 3) Color options ** ** ** This function builds a simple double frame for a menu. ** The function is passed the parameters for the upper ** left corner row, upper left corner column the height ** of the frame and the width. ** *************************************************************/#include #define ULCOR 201#define URCOR 187#define LLCOR 200#define LRCOR 188#define VBAR 186#define HBAR 205#d......

阅读全文(2233) | 评论:0

c语言(2006-06-16 10:42:00)

摘要:运动与静止同时实现在这里我用圆实现运动、方块实现静止 代码如下: #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main(void) { int gdriver = DETECT, gmode; void *ball; int x, y,maxx; unsigned int size; initgraph(&gdriver, &gmode, ""); maxx = getmaxx(); x = 0; y = 200; rectangle(x,y+11,x+20,y+31); circle(x+10,y,10); size = imagesize(x, y-10, x+20, y+10); ball = malloc(size); setfillstyle(SOLID_FILL, BLACK); while (!kbhit()) { cleardevice(); x += 10; if (x >= maxx) x = 0; rectangle(0,211,20,231); circle(x+10,y,10); delay(100); } free(ball); closegraph(); return 0; } 再来说一下赛车游戏 我上面给大家可以说是从第一步:制作简单的场景和玩家的赛车 到第二步:进一步完善场景, 大家可能已经有所领会 下面我们就把它做成一个简单的游戏 代码如下: #include <math.h>#include <conio.h> #include <stdio.h> #include <stdlib.h> #include <graphics.h> static int c=1; static int e=0; static int u=0; static int v=0; static int x=1; static int y=0; static int j=-21; static int i; static int b; void begin(void) { int xmax, ymax; ......

阅读全文(2455) | 评论:0

c语言(九格游戏100多行)(2006-06-16 10:39:00)

摘要:/*很多人都觉得编游戏很高深...其实不然...以下是我初学C时写个一个九格游戏涉及的知识只有函数,各种流程控制和从老师那里问来的几个非常有用的函数. 当然,当时我连一点图形的知识都没有. 我只想说明一个问题:不要觉得你C语言学得不够多,只是,你没有充分利用你所学到的*/ #include #include /*使用其中的int random(int a): 产生一个在0到a-1之间的整数 和 randomize():复位随机发生器*/ #include /*使用其中的gotoxy(int x,int y): 把光标移动到屏幕的x(1~80),y(1~25/50)处*/ /*和clrscr():清屏*/ int num[]={1,2,3,4,5,6,7,8,0}; /*方块的数字*/ main(){ char key=0; /*键盘码*/ int pos; /*九格中,空格的位置*/ clrscr(); /*清屏*/ randomize(); /*初始化随机发生器*/ newGame(); for(;;){ key=getch(); /*获得键盘输入*/ if(key==0) continue; pos=GetTheNull(); /*得到空格*/ switch(key){ /*测试按键*/ case 72: /*按下*/ if(pos<=5) change(pos,pos+3); break; case 80: /*按上*/ if(pos>=3) change(pos,pos-3); break; case 77: /*按左*/ if(pos%3!=0) change(pos,pos-1); break; case 75: /*按右*/ if(pos%3!=2) change(pos,pos+1); break; case 110: /*按下‘n’新建游戏*/ newGame(); } update(); /*更新*/ if(isSuccess()){ /*看是否游戏成功*/ gotoxy(26,10); /*成功了,输出一个写有Well done!的外框*/ printf("\332\304\304\304\304\304\304\304\304\304\304\304\304\267"); gotoxy(26,11); printf("\2......

阅读全文(3539) | 评论:1

c语言(可控制的笑脸)(2006-06-16 10:34:00)

摘要:纯真童趣的《泡泡堂》,还有武林情仇,笑傲江湖的《剑侠情缘online》.它是e时代常谈的话题,是交互式娱乐的主力军,是一种高层次的综合艺术,更是一个民族的文化,世界观的全新传播方式.作为游戏玩家的我们,是不是想设计一个属于自己的游戏呢?爱玩是人的天性,而C语言是我们计算机专业都要学习的一门基础学科.一般来说,是比较枯燥的.那么,我们能不能通过编一些小游戏来提高它的趣味性呢?这样学习程序设计,就不会是一件艰苦,枯燥的事,它变得象电脑游戏一样充满好奇,富有乐趣.这正是我发贴的目的. 一、 总是从Hello,world开始 学习编程的第一个程序,一般就是打印一个亲切的词语——"Hello,来 vcok.com 学c语言!".让我们来看看这个最简单的C程序: #incolude <stdio.h> /*把输入输出函数的头文件包含进来*/ int main() { printf("Hello,来 vcok.com 学c语言!");/*在屏幕上输出字符串"Hello,来 vcok.com 学c语言!"*/ return 0;/*退出main函数,并返回0*/ } 下面我们发现几个值得改进的地方, 1,程序的运行结果一闪而过.2,每执行这个程序一次都能看见上次运行留下的字符.3,我们还希望屏幕输出一个笑脸来欢迎我们.(大家不要小看了这个笑脸曾经有人发贴专门问呢)让我们来改进一下这个程序吧! 1,在return语句的前面加一句:getch ();,表示按任意键结束.2,在printf语句前用clrscr函数清屏,要使用这个函数和getch函数,需要在程序开头再包含头文件conio.h.3,ASCII码也有许多非常好玩的字符,比如ASCII码值为2的就是一个笑脸,我们可以用printf("%c", 2)来输出一个笑脸. 现在我们把Hello,world程序改成一个更好看的Hello,world了.下面让我们开始做游戏吧! 二、 心动的开始,一个运动中的笑脸 大家小时侯喜欢看动画片吗?哈哈,我猜你们都喜欢吧!下面就让我们来做一个小动画吧.在屏幕上显示一个运动的小笑脸,而且当它到达屏幕的边缘时会自动弹回来. 先在程序定义一个在屏幕中运动的点的结构: struct move_point { int x, y;......

阅读全文(5953) | 评论:0

用C语言写的鼠标驱动程序(2006-06-16 10:30:00)

摘要:#include <dos.h> #include <bios.h> #include <malloc.h> #include <stdlib.h> #include <stdio.h> #include "graphics.h" #define R 15 /*鼠标的形态*/ void initgr(void) /* BGI初始化 */ { int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */ registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */ initgraph(&gd, &gm, ""); } /*获取鼠标位置和按键,key=1是左键,key=2是右键*/ void getmouse(int *x,int *y,int *key) { union REGS inregs,outregs; inregs.x.ax=3; /*获取鼠标位置和状态也可以用3*/ int86(0x33,&inregs,&outregs); /*中断调用*/ *x=outregs.x.cx; /*cx寄存器中存的是横坐标*/ *y=outregs.x.dx; /*dx寄存器中存的是列坐标*/ *key=outregs.x.bx; /*bx寄存器是按键状态*/ } void visbilemouse() { union REGS inregs,outregs; inregs.x.ax=0x01; /*显示鼠标*/ int86(0x33,&inregs,&outregs); } /*按键后,返回当前鼠标的x,y和按键状态,知道按键后才返回*/ void mouse(int *x,int *y,int *z) /*画鼠标是利用将一个空矩形存入内存中,然后再在该空矩形中画鼠标形状*/ { int a=0,b=0,c=0,a_old=0,b_old=0; /*a,b的值可以随便*/ int *ball; /*定义指向内存的存储图形的指针*/ ball=malloc(imagesize(a,b,a+R,b+R)); /*返回矩形的大小*/ getimage(a,......

阅读全文(2689) | 评论:2

c语言(变化的同心圆 )(2006-06-16 08:53:00)

摘要:  代码一、#include"graphics.h" #include<stdio.h> #include<time.h> main() {int i; int gdriver=DETECT,gmode; initgraph(&gdriver, &gmode, "d:\\tc"); for(i=0;i<=100;i++) {setcolor(i); setlinestyle(0,0,1); setfillstyle(1,3); circle(300, 240, 100-i); floodfill(300, 240,i); delay(9e245); } getch(); closegraph(); } 代码二、#include"graphics.h" #include<stdio.h> #include<time.h> main() {int i; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"d:\\tc"); for(i=0;i<=100;i++) {setcolor(i); setlinestyle(0,0,1); setfillstyle(1,i); circle(300, 240, 100-i); floodfill(300, 240,i); delay(9e245); } getch(); closegraph(); }......

阅读全文(2695) | 评论:1