-- 作者:admin
-- 发布时间:2015/12/22 12:52:16
-- 同学写的最好的一个五子棋版本
#include <iostream> #include <stdio.h>
#include "graphics.h" #define LEN 30 #define UNIT1 4 #define UNIT2 16 #define UNIT (UNIT1+UNIT2)
int main() { int driver=VGA,model=VGAHI; int i=0,j=0,count=0,x=0,y=0; int array[LEN+1][LEN+1]; initgraph(&driver,&model,""); ege::initgraph(LEN*UNIT,LEN*UNIT); setbkcolor(YELLOW); setcolor(BLACK);
for(i=0; i<LEN+1; i++) for(j=0; j<LEN+1; j++) array[i][j]=0;
setlinestyle(SOLID_FILL,0,4); for(i=0; i<LEN+1; i++) { line(0,UNIT*i,LEN*UNIT,UNIT*i); } for(j=0; j<LEN+1; j++) { line(j*UNIT,0,j*UNIT,LEN*UNIT); }
char str[25]; for ( ; is_run(); delay_fps(120)) { while (mousemsg()) { mouse_msg m = getmouse(); if (m.msg == mouse_msg_down) { x=(m.x+10)/UNIT; y=(m.y+10)/UNIT; if(array[x][y]==0) { count++; if(count%2==1) { array[x][y]=1; setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); sector(UNIT*x,UNIT*y,0,360,8,8); } else { array[x][y]=2; setcolor(WHITE); setfillstyle(SOLID_FILL,WHITE); sector(UNIT*x,UNIT*y,0,360,8,8); }
int sum=1,m=0,n=0; for(i=0; i<LEN+1; i++) { for(j=0; j<LEN+1; j++) { if(array[i][j]!=0) { if(array[i][j+4]==array[i][j] ) { m=j; for(m=j; m<j+5; m++) { sum=sum+array[i][m]; } } if(array[i+4][j]==array[i][j]) { n=i; for(n=i; n<i+5; n++) { sum=sum+array[n][j]; } } if(array[i+4][j+4]==array[i][j]) { m=j; n=i; for(m=j,n=i; m<j+5&&i<i+5; m++,n++) { sum=sum+array[n][m]; } } if(array[i-4][j+4]==array[i][j]) { m=j; n=i; for(m=j,n=i; m<j+5&&i<i+5; m++,n--) { sum=sum+array[n][m]; } } if(sum!=6||sum!=11) { j++; } } } } if(sum==6) { Sleep(1); MessageBox(NULL,itoa(1,str,10),"结果",MB_OK); } //MessageBox(NULL,itoa(sum,str,10),"结果",MB_OK); if(sum==11) { Sleep(1); MessageBox(NULL,itoa(0,str,10),"结果",MB_OK); } } } } } getch(); }
此主题相关图片如下:无标题.png

|