资源描述
程序设计基础课程设计俄罗斯方块游戏院 系:计算机科学技术学院班 级:网络10-1班组 长:组 员:指导教师:2010年12月31日一 实践的目的和要求加深对C语言课程所学知识的理解,进一步巩固C语言语法规则。学会编制结构清晰、风格良好、数据结构适当的语言程序,从而具备解决综合性实际问题的能力。二 实践内容在熟练掌握C语言的基本知识:数据类型(整形、实型、字符型、指针、数组、结构等);运算类型(算术运算、逻辑运算、自增自减运算、赋值运算等);程序结构(顺序结构、判断选择结构、循环结构);大程序的功能分解方法(即函数的使用)等。进一步掌握各种函数的应用,包括时间函数、绘图函数,以及文件的读写操作等。三 实践任务1欢迎画面2. 附加声音界面3俄罗斯方块课程设计系统(自己设计界面)四 设计流程编程五 个人动画1.雪花*#include#include#include#includeint change1=10;void Pr() int fr=392,392,440,294,262,262,220,294,392,392, 440,532,440,392,262,262,220,294,392,294, 262,247,220,196,392,294,330,294,262,262, 220,294,330,294,262,294,22,247,220,196;setcolor(change1/10);settextstyle(0,0,3);outtextxy(100,200,Welcome to our Game!);outtextxy(180,300,li zhao long);outtextxy(400,20,yang fei);outtextxy(10,20,hao jia jun);outtextxy(400,400,liu long);outtextxy(20,400,liu ming jing);outtextxy(240,100,san zu);sound(frchange1/10);2.叶旋*#include #include#include#include#include#include#define pi 3.1415926int fr3=392,330,392,294,330,294,262,262,247, 220,247,262,247,262,294,330,392,330, 392,587,523,494,523,262,247,220,247, 262,247,262,294,262,392,440,494,523, 494,523,494,440,392,440,392,262,294, 330,349,330,349,392,262,294,330,330, 392,440,494,523,494,523,587,523,587, 659,392,262,294,330,349,330,349,330, 294,262,247,262;int tim3=2,6,2,6, 2,6,10,2,2, 2,2,2,4, 4,2,12,2,6, 2,6,2,4,10,2, 2,2,2, 2,4,4,2, 8,2, 2,2,4, 2,2,2,2, 2,4, 8,2,2, 2,4,2,2, 2,2, 2,4,6, 2,2,2,4, 2,2, 2,2,2, 4,8,2,2, 2,4, 2,2,2, 4,2,2,10;void interrupt (*handler)();void interrupt music3();void Inet(void) int gd=DETECT ,gm; registerbgidriver(EGAVGA_driver); initgraph(&gd,&gm,c:TC3BGI); cleardevice();void interrupt music3() static int flag=0,note=0,fre,dur; if(flag=(int)(dur*3) flag=0; nosound(); fre=fr3note; dur=tim3note; sound(fre); note+; if(note=77) note=0; handler(); flag+; void Donghua3() char ch; int i,j=0,x,p,y,k=1,gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,); handler=getvect(0x1c); setvect(0x1c,music3); p=0; while(!kbhit() if(p=200)p=0; j+=10; for(i=0;i=2000;i+) x=300+100*cos(2*i*pi/1000)*sin(i*pi/1000+j*pi/1000); y=240+100*cos(2*i*pi/1000)*cos(i*pi/1000+j*pi/1000); if(j%500=0) k+; putpixel(x,y,k); for(i=0;i=2000;i+) x=360+100*cos(2*i*pi/1000)*sin(i*pi/1000+j*pi/1000); y=120+100*cos(2*i*pi/1000)*cos(i*pi/1000+j*pi/1000); if(j%500=0) k+; putpixel(x,y,k); for(i=0;i=2000;i+) x=240+100*cos(2*i*pi/1000)*sin(i*pi/1000+j*pi/1000); y=280+100*cos(2*i*pi/1000)*cos(i*pi/1000+j*pi/1000); if(j%500=0) k+; putpixel(x,y,k); for(i=0;i=2000;i+) x=400+100*cos(2*i*pi/1000)*sin(i*pi/1000+j*pi/1000); y=360+100*cos(2*i*pi/1000)*cos(i*pi/1000+j*pi/1000); if(j%500=0) k+; putpixel(x,y,k); for(i=0;i=2000;i+) x=500+100*cos(2*i*pi/1000)*sin(i*pi/1000+j*pi/1000); y=240+100*cos(2*i*pi/1000)*cos(i*pi/1000+j*pi/1000); if(j%200=0) k+; putpixel(x,y,k); outtextxy(50,240,Failure is the mother of success.nntry our bestnn); delay(200000); cleardevice(); setvect(0x1c,handler); closegraph(); nosound(); void maih(void) Inet() ; /* wafly: you can re-order these animates as you like*/ while(!kbhit() Donghua3(); 3.时表*#include #include #include #define CENTERX 320 /*表盘中心位置*/ #define CENTERY 175 #define CLICK 100 /*喀嗒声频率*/ #define CLICKDELAY 30 /*喀嗒声延时*/ #define HEBEEP 10000 /*高声频率*/ #define LOWBEEP 500 /*低声频率*/ #define BEEPDELAY 200 /*报时声延时*/*表盘刻度形状*/ int Mrk_18=-5,-160,5,-160,5,-130,-5,-130, ; int Mrk_28=-5,-160,5,-160,2,-130,-2-130, ; /*时针形状*/ int HourHand8=-3,-100,3,-120,4, 10,-4,10; /*分针形状*/ int MiHand8=-3,-120,3,-120,4, 10,-4,10; /*秒针形状*/ int SecHand8=-2,-150,2,-150,3, 10,-3,10; /*发出喀嗒声*/ void Click() sound(CLICK); delay(CLICKDELAY);nosound(); /*高声报时*/ void HighBeep() sound(HEBEEP); delay(BEEPDELAY); nosound; /*低声报时*/ void LowBeep() sound(LOWBEEP); /*按任意角度画多边形*/ void DrawPoly(int *data,int angle,int color) int usedata8; float sinang,cosang; int i; sinang=sin(float)angle/180*3.14); cosang=cos(float)angle/180*3.14); for(i=0;i8;i+=2) usedatai =CENTERX+ cosang*datai-sinang*datai+1+.5; usedatai+1=CENTERY+sinang*datai+cosang*datai+1+.5; setfillstyle(SOLID_FILL,color); fillpoly(4,usedata); /*画表盘*/ void DrawClock(struct time *cutime) int ang; float hourrate,minrate,secrate; setbkcolor(BLUE); cleardevice(); setcolor(WHITE); /* 画刻度*/ for(ang=0;angti_sec/60; minrate=(float)cutime-ti_min+secrate)/60; hourrate=(float)cutime-ti_hour/12)+minrate)/12; ang=hourrate*360; DrawPoly(HourHand,ang,YELLOW);/*画时针*/ ang=minrate*360; DrawPoly(MiHand,ang, GREEN);/*画分针*/ ang=secrate*360; DrawPoly(SecHand,ang, RED);/*画秒针*/ maiy() int gdriver=EGA, gmode=EGAHI; int curpage; struct time curtime ,newtime ;registerbgidriver(EGAVGA_driver);initgraph(&gdriver,&gmode,c:tc3bgi);setbkcolor(BLUE); cleardevice(); gettime(&curtime); curpage=0; DrawClock(&curtime); while(1) if(kbhit() break; /*按任意键退出*/ gettime(&newtime); /*检测系统时间*/ if(newtime.ti_sec!=curtime.ti_sec)/*每1秒更新一次时间*/ if(curpage=0) curpage=1; else curpage=0; curtime=newtime; /*设置绘图页*/ setactivepage(curpage); /*在图页上画表盘*/ DrawClock(&curtime); /*设置绘图页为当前可见页*/ setvisualpage(curpage); /*0分0秒高声报时*/ if(newtime.ti_min=0&newtime.ti_sec=0) HighBeep(); /* 59分55至秒时低声报时*/ else if(newtime.ti_min=59&ewtime.ti_sec=59) LowBeep();/*其他时间只发出喀嗒声*/ else Click(); closegraph(); 4.落字*#define FONT_HEIGHT 13#define FONT_WIDTH 11#define MAX_DELAY 10#define MIN_DELAY 1#define DELAY_TIME 5000 #include #include #include #include #define FONT_HEIGHT 13#define FONT_WIDTH 11#define MAX_DELAY 10#define MIN_DELAY 1#define DELAY_TIME 5000typedef struct StringObj_tag int max_delay; int cur_delay; int head_x; int head_y; int length; char head_char; StringObj;int charsInX;int charsInY;StringObj* ptStrObj;void InitMatrix(void);void Matrix(void);void EndMatrix(void);void InitStringObj(StringObj* obj, int i);void DrawStringObj(StringObj* obj);void InitGraph(void);int fr= 196,392,262,196,330,262,392,440,392, 392,392,523,523,440,392,349,440,392, 392,392,440,440,294,294,294,392,349, 330,196,196,392,392,440,392,349,330, 294,262,392,392,523,523,440,440,392, 349,392,440,294,294,392,392,440,392, 349,330,294,262,494,392,440,494,523, 523;int tim= 3,1,4,4,4,4,5,2,4,3,1,4, 4,3,1,2,2,8,3,1,4,4,4,3, 1,6,2,4,3,1,4,2,2,2,2,2, 2,8,3,1,4,4,4,3,1,6,2,4, 3,1,4,2,2,2,2,2,2,8,2,2, 2,2,8;int mail() InitMatrix(); Matrix(); EndMatrix(); nosound(); return 0;void InitMatrix(void) int i; InitGraph(); for (i = 0; i charsInX; i+) InitStringObj(&ptStrObji, i);void Matrix(void) int i,k; int j=0,fre; while (!kbhit() for (i = 0; i charsInY + ptStrObji.length) InitStringObj(&ptStrObji, i); Else DrawStringObj(&ptStrObji); j+; if(j=timk*350) k+;j=0; if(k=63)k=0;/* delay(DELAY_TIME); */ void EndMatrix(void) closegraph(); free(void*)ptStrObj);void InitGraph(void) int graph_mode; int graph_driver = DETECT; registerbgidriver(EGAVGA_driver); initgraph(&graph_driver, &graph_mode, ); charsInX = getmaxx()/FONT_WIDTH; charsInY = getmaxy()/FONT_HEIGHT; ptStrObj = (StringObj*)malloc(sizeof(StringObj)*charsInX);void DrawStringObj(StringObj* obj) char chs2 = 0, 0; int rear_x = obj-head_x * FONT_WIDTH; int rear_y = (obj-head_y - obj-length)*FONT_HEIGHT; int color; if (obj-cur_delay 0) obj-cur_delay-; return ; color = ( random(2) ? LIGHTGREEN : GREEN); setcolor(color); chs0 = obj-head_char;outtextxy(obj-head_x * FONT_WIDTH, obj-head_y * FONT_HEIGHT, chs); obj-head_y += 1; setcolor(WHITE); obj-head_char = chs0 = random(0x7e - 0x21) + 0x21; outtextxy(obj-head_x * FONT_WIDTH, obj-head_y * FONT_HEIGHT, chs); setfillstyle(EMPTY_FILL, BLACK); bar(rear_x, rear_y, rear_x + FONT_WIDTH - 1, rear_y + FONT_HEIGHT - 1); obj-cur_delay = obj-max_delay; void InitStringObj(StringObj* obj, int i) obj-max_delay = obj-cur_delay = random(MAX_DELAY-MIN_DELAY)+MIN_DELAY; obj-head_x = i; obj-head_y = 0; obj-head_char = random(0x7e-0x21) + 0x21; obj-length = random(charsInY-10)+3;5.朋友*#include #include#include#include#include#includeint fr2=196,262,294,330,349,330,262, 294,262,220,262,196,262,294, 330,330,349,392,262,349,330, 392,294,330,330,294,294,330, 392,494,494,440,440,392,392, 440,494,440,392,330,349,349, 392,440,392,349,330,294,247, 247,220,196,220,262,523,440, 349,392,440,494,494,494,494, 440,392,330,523,440,349,392, 440,440,440,440,440,349,330, 294,392,262,294,330,349,330, 131,131,294,294,294,294,262, 220,220,247,247,220,196,440, 392,294,294,349,349,349,330, 294,392;int tim2= 8,4, 4, 6,2, 4, 4, 8,4, 4, 12,8, 4, 4,4, 2, 2, 4,4, 6, 2,4, 2, 2,2, 2,12, 8,4, 4, 6,2, 8, 4,2, 2, 4, 2,2,16, 6,2, 4, 4,4, 2, 2, 8,4, 2, 2,4, 4,16,8, 8, 6, 2,8, 4, 2,2, 4, 2,2,16, 8, 8,6, 2, 8,4, 2, 2,4, 2, 2,16,8, 4, 4,6, 2, 4,2, 2, 6, 2,4, 2, 2,4,12, 8,6, 2, 4, 4,4, 2, 2,6, 2, 4,2, 2,16;void interrupt (*handler)();void interrupt music2();void interrupt music2() static int flag=0,note=0,fre,dur; if(flag=(int)(dur*2) flag=0; nosound(); fre = fr2note; dur = tim2note; sound(fre); note+; if(note=107) note=0; handler( ); flag+;void Donghua5() float x1,y1,x2,x3,y2; char ch; int i=0,j,gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,); handler=getvect(0x1c); setvect(0x1c,music2); while(!kbhit() i+; if(i=160)i=0; setcolor(YELLOW); setfillstyle(1,RED); fillellipse(50+i*4,90,30,30); line(50+i*4,60,50+i*4,30); line(50+i*4,120,50+i*4,150); line(20+i*4,90,-10+i*4,90); line(80+i*4,90,110+i*4,90); line(7+i*4,47,28+i*4,68); line(7+i*4,128,28+i*4,113); line(88+i*4,47,73+i*4,68); line(88+i*4,128,73+i*4,113); setcolor(GREEN); line(0,400,640,400);setcolor(YELLOW); setfillstyle(SOLID_FILL,YELLOW); circle(200,250,50); x1=210+(i%2)*15; line(175,x1,160,225); line(175,x1,190,225); x2=210+(i%2)*15; line(225,x2,210,225); line(225,x2,240,225); x3=280-(i+1)%2)*10; line(190,270,200,270); line(210,270,200,270); line(190,270,200,x3); line(210,270,200,x3);line(170,290,140,350-(i%2)*100); line(170,290,170,400);line(230,290,260,350-(i%2)*100);line(230,290,230,400); circle(320,250,50);line(295,x1,280,225); line(295,x1,310,225); line(345,x2,330,225); line(345,x2,360,225); line(310,270,320,270); line(330,270,320,270); line(310,270,320,x3); line(330,270,320,x3); line(290,290,260,350-(i%2)*100); line(290,290,290,400);line(350,290,380,350-(i%2)*100);line(350,290,350,400);delay(300000);cleardevice();setvect(0x1c,handler);closegraph();nosound(); void Init(void) int gd=DETECT,gm;/* Wafly: I need this script for init driver, you can delete it if you dont need */ registerbgidriver(EGAVGA_driver);initgraph(&gd,&gm,c:TC3BGI); cleardevice();void mai1(void) Init(); /* wafly: you can re-order these animates as you like*/ while(!kbhit() Donghua5();六 游戏画面1.开始画面2.登录游戏输入密码3.游戏中4.游戏结束5.保存姓名6.排行榜7.结束画面七 程序模块1.主函数#include#include#include#include#include#include#include#include lmj.c#include phb.c#includebk.c#include2222.c#include3333.c#includedhk.c#includemm.c#includell.c#includehjj.c#includeyf.c#define LEFT 0x4b00 /*键盘码*/#define RIGHT 0x4d00#define DOWN 0x5000#define UP 0x4800#define ESC 0x011b#define TIMER 0x1c /* 时钟中断的中断号 */#define FILENAME c:person.dat /*排行榜文件的文件名*/void main()int i ;int gdriver=DETECT,gmode;SetTimer(newhandler); /* 修改时钟中断 */registerbgidriver(EGAVGA_driver);initgraph(&gdriver,&gmode,c:turboc2);Copy();DrawSnow(); /*下雪函数,包含音乐*/getch();i = denglu();if ( i =0 )registerbgidriver(EGAVGA_driver);initgraph(&gdriver,&gmode,c:turboc2);mai1();getch();mail();getch();maih();getch();maiy();/*mai(); */Selectitem();getch();closegraph();initgraph(&gdriver,&gmode,E:TC20HINCLUDEGRAPHICS.H); /*初始化图形*/plot();operation();EndPlay() ;getch();getch();2. 开始动画音乐#define TIMER 0x1c /* 时钟中断的中断号 */#define FILENAME c:person.dat /*排行榜文件的文件名*/typedef struct int box44;int color;int next;SHAPE;SHAPE shapes19=1,0,0,0, 1,0,0,0, 1,1,0,0, 0,0,0,0,CYAN,1,1,1,1,0, 1,0,0,0, 0,0,0,0, 0,0,0,0,CYAN,2,1,1,0,0, 0,1,0,0, 0,1,0,0, 0,0,0,0,CYAN,3,0,0,0,0, 0,0,1,0, 1,1,1,0, 0,0,0,0,CYAN,0,0,1,0,0, 0,1,0,0, 1,1,0,0, 0,0,0,0,MAGENTA,5,1,0,0,0, 1,1,1,0, 0,0,0,0, 0,0,0,0,MAGENTA,6,1,1,0,0, 1,0,0,0, 1,0,0,0, 0,0,0,0,MAGENTA,7,1,1,1,0, 0,0,1,0, 0,0,0,0, 0,0,0,0,MAGENTA,4,1,0,0,0, 1,1,0,0, 0,1,0,0, 0,0,0,0,YELLOW,9,0,1,1,0, 1,1,0,0, 0,0,0,0, 0,0,0,0,YELLOW,8,0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0,BROWN,11,1,1,0,0, 0,1,1,0, 0,0,0,0, 0,0,0,0,BROWN,10,0,1,0,0, 1,1,1,0, 0,0,0,0, 0,0,0,0,WHITE,13,1,0,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0,WHITE,14,1,1,1,0, 0,1,0,0, 0,0,0,0, 0,0,0,0,WHITE,15,0,1,0,0, 1,1,0,0, 0,1,0,0, 0,0,0,0,WHITE,12,1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0,RED,17,1,1,1,1, 0,0,0,0, 0,0,0,0, 0,0,0,0,RED,16,1,1,0,0, 1,1,0,0, 0,0,0,0, 0,0,0,0,BLUE,18;int snownum=0;int size;int annal42,level=0,color,Boxnumber;void operation();void *save1,*save2;int change1=10;int TimerCounter=0;void Pr();void interrupt ( *oldhandler)();void interrupt newhandler( )TimerCounter+;TimerCounter=36;oldhandler();struct Snowint x;int y;int speed;snow100;void Pr()int fr=392,392,440,294,262,262,220,294,392,392, 440,532,440,392,262,262,220,294,392,294, 262,247,220,196,392,294,330,294,262,262, 220,294,330,294,262,294,22,247,220,196;setcolor(change1/10);settextstyle(0,0,3);outtextxy(100,200,Welcome to our Game!);outtextxy(180,300,li zhao long);outtextxy(400,20,yang fei);outtextxy(10,20,hao jia jun);outtextxy(400,400,liu long);outtextxy(20,400,liu ming jing);outtextxy(240,100,san zu);sound(frchange1/10);void DrawSnow()int i;int sx62;randomize();for(i=0;i62;i+)sxi=(i+2)*10;cleardevice();while(!kbhit()Pr();if (snownum!=100) snowsnownum.speed=2+random(10); i=random(62); snowsnownum.x=sxi; snowsnownum.y=10-random(100);for(i=0;isnownum;i+) putimage(snowi.x,snowi.y,save2,COPY_PUT); Pr();if(snownum!=100) snownum+;/*delay(300);*/setfillstyle(SOLID_FILL,15);for(i=0;i500) snowi.y=10- random(200); change1+;if(change1=140)change1=10;nosound();void SetTimer(void interrupt (*IntProc)()oldhandler=getvect(TIMER);disable(); /* 设置新的时钟中断处理过程时,禁止所有中断 */setvect(TIMER,IntProc);enable();/* 开启中断 */void DrawSnow();void interrupt ( *oldhandler)();void KillTimer() disable();setvect(TIMER,oldhandler);enable();void Copy()setcolor(0);setfillstyle(SOLID_FILL,15);fillellipse(200,200,4,4);size=imagesize(196,196,204,204);save1=malloc(size);save2=malloc(size);getimage(196,196,204,204,save1);getimage(96,96,104,104,save2);3. 登录密码及密码的重新设置void drawmat(char *mat,int matsize,int x,int y,int color) ;char deng12S=/*登 */0x7A,0x80,0x4A,0xA0,0x31,0x40,0x1F,0x80,0x20,0x40,0xDF,0xA0,0x10,0x80,0x1F,0x80,0x10,0x80,0x09,0x00,0xFF,0xE0,0x00,0x00 ;char lu12S=/*录 */0x7F,0x80,0x00,0x80,0x3F,0x80,0x00,0x80,0xFF,0xE0,0x24,0x40,0x16,0x80,0x0D,0x00,0x34,0x80,0xC4,0x60,0x1C,0x00,0x00,0x00 ;char dui12S= /* 对 */0x00,0x40,0xF8,0x40,0x08,0x40,0x4F,0xE0,0x28,0x40,0x12,0x40,0x11,0x40,0x29,0x40,0x48,0x40,0x88,0x40,0x01,0xC0,0x00,0x00 ;char hua12S= /* 话 */0x40,0xE0,0x2F,0x00,0x21,0x00,0x0F,0xE0,0xE1,0x00,0x21,0x00,0x27,0xE0,0x24,0x20,0x2C,0x20,0x37,0xE0,0x24,0x20,0x00,0x00 ;char kuang12S= /* 框 */0x4F,0xE0,0x48,0x00,0xFB,0xE0,0x48,0x80,0x68,0x80,0xDB,0xE0,0xC8,0x80,0x48,0x80,0x4B,0xE0,0x48,0x00,0x4F,0xE0,0x00,0x00 ;char mao12S= /* : */0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;char cuo12S= /* 错 */0x42,0x80,0x42,0x80,0x6F,0xE0,0x82,0x80,0xEF,0xE0,0x40,0x00,0xF7,0xC0,0x44,0x40,0x57,0xC0,0x64,0x40,0x47,0xC0,0x00,0x00 ;char wu12S= /* 误 */0x47,0xC0,0x24,0x40,0x24,0x40,0x07,0xC0,0xC0,0x00,0x4F,0xE0,0x41,0x00,0x5F,0xE0,0x52,0x80,0x64,0x40,0x58,0x20,0x00,0x00 ;char plaint= /* ! */0x00,0x00,0x30,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00 ;char qing12S= /* 请 */0x41,0x00,0x2F,0xE0,0x01,0x00,0x0F,
展开阅读全文