傻啦吧机的。
怎么你要跟我比内存管理?
要不我去另开一帖
我们一起写个Mempool, 实现自己的malloc 跟delloc.
看谁的效率高。
怎么你要跟我比内存管理?
要不我去另开一帖
我们一起写个Mempool, 实现自己的malloc 跟delloc.
看谁的效率高。
#include<graphics.h> #define N 20 /*定义键盘*/ #define up 0x4800 #define down 0x5000 #define left 0x4b00 #define right 0x4d00 #define esc 0x011b #define enter 0x1c0d #define A 0x1e61 #define S 0x1f73 #define D 0x2064 #define W 0x1177 #define space 0x3920 #define Y 0x1579 #define n 0x316e int gamespeed=5000; int i,j,key; struct Sor { int x; int y;/*x,y表示当前光标的位置*/ int yes[N][N];/* 0表示无棋子,1表示白色棋子,2表示黑色棋子*/ int kao;/* 1表示白棋准备落子,2表示黑棋落子*/ int ok;/*1表示白棋胜出,2表示黑棋胜出*/ }sor; void init(void) /*graph drive*/ { int driver=DETECT,mode=0; registerbgidriver(EGAVGA_driver); initgraph(&driver,&mode,""); } void drawmat(char *mat,int matsize,int x,int y,int color) { int i,j,k,m; m=(matsize-1)/8+1; for(j=0;j<matsize;j++) for(i=0;i<m;i++) for(k=0;k<8;k++) if(mat[j*m+i]&(0x80>>k)) putpixel(x+i*8+k,y+j,color); } void show(void)/*input word*/ { drawmat(wu64H,64,438,49,0); drawmat(zi64H,64,488,49,0); drawmat(qi64H,64,538,49,0); drawmat(wu64H,64,440,50,13); drawmat(zi64H,64,490,50,13); drawmat(qi64H,64,540,50,13); drawmat(zuo16H,16,480,450,8); drawmat(zhe16H,16,498,450,8); drawmat(tian16H,16,518,450,8); drawmat(xue16H,16,536,450,8); drawmat(ke16H,16,554,450,8); } void drawqp(void)/*draw qi pan*/ { setcolor(3); for(i=50;i<=(N-1)*20+30;i+=20) { line(50,i,(N-1)*20+30,i); line(i,50,i,(N-1)*20+30); } setcolor(11); for(i=1;i<3;i++) { circle((N-1)*10+40,(N-1)*10+40,i); circle(130,130,i); circle(130,330,i); circle(330,130,i); circle(330,330,i); } } void clew(void) /*input message*/ { setcolor(15); settextstyle(0,0,1); outtextxy(50,20,"1P: Up Down Left Right Enter 2P: W S A D Space"); } void place(void)/*画出光标的位置*/ { line(sor.x-10,sor.y-10,sor.x-7,sor.y-10); line(sor.x-10,sor.y-10,sor.x-10,sor.y-7); line(sor.x-10,sor.y+10,sor.x-10,sor.y+7); line(sor.x-10,sor.y+10,sor.x-7,sor.y+10); line(sor.x+10,sor.y-10,sor.x+10,sor.y-7); line(sor.x+10,sor.y-10,sor.x+7,sor.y-10); line(sor.x+10,sor.y+10,sor.x+7,sor.y+10); line(sor.x+10,sor.y+10,sor.x+10,sor.y+7); } void win(void)/*判断是否胜出*/ { for(i=1;i<N;i++) { for(j=1;j<N;j++) { if(((j+4)<N&&sor.yes[i][j]!=0&& sor.yes[i][j]==sor.yes[i][j+1]&& sor.yes[i][j+1]==sor.yes[i][j+2]&& sor.yes[i][j+2]==sor.yes[i][j+3]&& sor.yes[i][j+3]==sor.yes[i][j+4])|| ((i+4)<N&&sor.yes[i][j]!=0&& sor.yes[i][j]==sor.yes[i+1][j]&& sor.yes[i+1][j]==sor.yes[i+2][j]&& sor.yes[i+2][j]==sor.yes[i+3][j]&& sor.yes[i+3][j]==sor.yes[i+4][j])|| ((i+4)<N&&(j+4)<N&&sor.yes[i][j]!=0&& sor.yes[i][j]==sor.yes[i+1][j+1]&& sor.yes[i+1][j+1]==sor.yes[i+2][j+2]&& sor.yes[i+2][j+2]==sor.yes[i+3][j+3]&& sor.yes[i+3][j+3]==sor.yes[i+4][j+4])|| ((i+4)<N&&j>4&&sor.yes[i][j]!=0&& sor.yes[i][j]==sor.yes[i+1][j-1]&& sor.yes[i+1][j-1]==sor.yes[i+2][j-2]&& sor.yes[i+2][j-2]==sor.yes[i+3][j-3]&& sor.yes[i+3][j-3]==sor.yes[i+4][j-4])) { if(sor.yes[i][j]==1) sor.ok=1; else sor.ok=2; break; } } if(sor.ok!=0) break; } } void gameover(void) { if(sor.ok==1) { drawmat(bai64H,64,488,119,0); drawmat(bai64H,64,490,120,4); } else { drawmat(hong64H,64,488,119,0); drawmat(hong64H,64,490,120,4); } drawmat(fang64H,64,488,189,0); drawmat(huo64H,64,488,259,0); drawmat(sheng64H,64,488,329,0); drawmat(fang64H,64,490,190,4); drawmat(huo64H,64,490,260,4); drawmat(sheng64H,64,490,330,4); } void xandy(void)/*显示光标的横纵坐标*/ { char str1[10],str2[10]; setfillstyle(SOLID_FILL,7); bar(50,440,205,470); setcolor(14); settextstyle(0,0,2); sprintf(str1,"X:%d",(sor.x-30)/20); sprintf(str2,"Y:%d",(sor.y-30)/20); outtextxy(60,450,str1); outtextxy(135,450,str2); } void gameplay(void) { for(i=1;i<N;i++)/*棋盘初始化*/ for(j=1;j<N;j++) sor.yes[i][j]=0; sor.kao=1; /*白棋先走*/ sor.ok=0;/*双方胜负未分*/ sor.x=(N-1)*10+40; sor.y=(N-1)*10+40;/*初始化光标,将光标定位在棋盘的中心*/ setcolor(15); place(); while(1) { xandy(); key=bioskey(0); if(key==esc) break; /*白棋键盘移动*/ else if(key==up&&sor.y>50&&sor.kao==1) { setcolor(0);place(); sor.y-=20; } else if(key==down&&sor.y<(N-1)*20+30&&sor.kao==1) { setcolor(0);place(); sor.y+=20; } else if(key==left&&sor.x>50&&sor.kao==1) { setcolor(0);place(); sor.x-=20; } else if(key==right&&sor.x<(N-1)*20+30&&sor.kao==1) { setcolor(0);place(); sor.x+=20; } /*红方键盘移动*/ else if(key==W&&sor.y>50&&sor.kao==2) { setcolor(0);place(); sor.y-=20; } else if(key==S&&sor.y<(N-1)*20+30&&sor.kao==2) { setcolor(0);place(); sor.y+=20; } else if(key==A&&sor.x>50&&sor.kao==2) { setcolor(0);place(); sor.x-=20; } else if(key==D&&sor.x<(N-1)*20+30&&sor.kao==2) { setcolor(0);place(); sor.x+=20; } else if(key==space&&sor.yes[(sor.x-30)/20][(sor.y-30)/20]==0&&sor.kao==2) { setcolor(13); for(i=1;i<=9;i++) { circle(sor.x,sor.y,i); delay(10000); } sor.yes[(sor.x-30)/20][(sor.y-30)/20]=2; sor.kao=1; win(); if(sor.ok!=0) { gameover(); break; } } else if(key==enter&&sor.yes[(sor.x-30)/20][(sor.y-30)/20]==0&&sor.kao==1) { setcolor(15); for(i=1;i<=9;i++) { circle(sor.x,sor.y,i); delay(10000); } sor.yes[(sor.x-30)/20][(sor.y-30)/20]=1; sor.kao=2; win(); if(sor.ok!=0) { gameover(); break; } } else continue; if(sor.ok!=0) break; if(sor.kao==1) setcolor(15); else setcolor(13); place(); }/*endwhile(1)*/ } main() { while(1) { init(); cleardevice(); clew(); drawqp(); setfillstyle(SOLID_FILL,7); bar(430,50,620,410); show(); gameplay(); setcolor(15); settextstyle(0,0,2); outtextxy(230,450,"CONTINUE(Y/N)?"); while(1) { key=bioskey(0); if(key==Y||key==n||key==esc) break; } if(key==n||key==esc) break; } closegraph(); }