课外天地 李树青学习天地C语言程序设计 → 同学写的最好的一个五子棋版本


  共有13532人关注过本帖树形打印复制链接

主题:同学写的最好的一个五子棋版本

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1939 积分:26594 威望:0 精华:34 注册:2003/12/30 16:34:32
同学写的最好的一个五子棋版本  发帖心情 Post By: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
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
admin
  2楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1939 积分:26594 威望:0 精华:34 注册:2003/12/30 16:34:32
  发帖心情 Post By:2015/12/22 12:52:57 [只看该作者]

程序还有问题,不过已经显示出明显的思路,继续努力!

 回到顶部