⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccheck.java

📁 java开发的人机对战五子棋游戏!只有安装jdk环境,就可以运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:


public class CCheck extends Computer{
    int m=0,n,c,d;
    int un=0;
    qizi qi=new qizi();
    int x,y;
    int ch[][]=new int[18][18];
    public qizi checktwo(int ch_[][],int x_,int y_)
    {
        x = x_;
        y = y_;
        ch = ch_;
        qi.sider = 2;

        for (i = x + 1; i < (x + 5) && (i < 15); i++) { //横
            if (ch[i][y] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = y;
                    un = 1;
                    if (m == 1) {

                        return qi;
                    }
                }
            } else if (ch[x][y] == ch[i][y]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }

        for (i = x - 1; i > (x - 5) && (i > 0); i--) {
            if (ch[i][y] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = y;
                    un = 1;
                    if (m == 1)
                        return qi;
                }

            } else if (ch[x][y] == ch[i][y]) {
                m = 1;
                if (un == 1) {

                    return qi;
                } else
                    break;
            }
        }

        un = 0;
        m = 0;

        for (j = y + 1; j < (y + 5) && (j < 15); j++) { //纵向
            if (ch[x][j] == 0) {
                if (un == 0) {
                    qi.x = x;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }

            } else if (ch[x][y] == ch[x][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        for (j = y - 1; j > (y - 5) && (j > 0); j--) {
            if (ch[x][j] == 0) {
                if (un == 0) {
                    qi.x = x;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }

            } else if (ch[x][y] == ch[x][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        un = 0;
        m = 0;

        for (i = x + 1, j = y + 1; j < (y + 5) && (j < 15) && i < 15; i++, j++) { //左上右下
            if (ch[i][j] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }

            } else if (ch[x][y] == ch[i][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        for (i = x - 1, j = y - 1; j > (y - 5) && (j > 0) && (i > 0); j--, i--) {
            if (ch[i][j] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }

            } else if (ch[x][y] == ch[i][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        un = 0;
        m = 0;
        for (i = x - 1, j = y + 1; j < (y + 5) && (j < 15) && i > 0; i--, j++) { //左下右上
            if (ch[i][j] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }
            } else if (ch[x][y] == ch[i][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        for (i = x + 1, j = y - 1; j > (y - 5) && (j > 0) && (i < 15); j--, i++) {
            if (ch[i][j] == 0) {
                if (un == 0) {
                    qi.x = i;
                    qi.y = j;
                    un = 1;
                    if (m == 1)
                        return qi;
                }
            } else if (ch[x][y] == ch[i][j]) {
                m = 1;
                if (un == 1)
                    return qi;
            } else
                break;
        }
        return null;                           //没有结束
   }


       public qizi checkfour(int ch_[][],int x_,int y_)   //看人与电脑有没有联四棋,可以联五的.
    {
        x = x_;
        y = y_;
        ch = ch_;
        qi.sider = 2;
        c = 0;
        m=0;
        n=0;
        for (int z = 0; z < 2; z++) { //看横向
            for (i = x + 1; i < (x + 5) && (i <=17); i++) {
                if (ch[i][y] == ch[x][y])
                    m++;
                else if (ch[i][y] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = y;
                    c = 1;
                }

                else
                    break;
            }
            for (i = x - 1; i > (x - 5) && (i >=0); i--) {
                if (ch[i][y] == ch[x][y])
                    n++;
                else if (ch[i][y] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = y;
                    c = 1;
                } else
                    break;

            }
            if ((n + m + c) >= 4)
                return qi;
            c = 0;
            m=0;
            n=0;
        }

        for (int z = 0; z < 2; z++) { //看纵向
            for (j = y + 1; j < (y + 5) && (j <=17); j++) {
                if (ch[x][j] == ch[x][y])
                    m++;
                else if (ch[x][j] == 0 && c == 0 && c == z) {
                    qi.x = x;
                    qi.y = j;
                    c = 1;
                }

                else
                    break;
            }
            for (j = y - 1; j > (y - 5) && (j >=0); j--) {
                if (ch[x][j] == ch[x][y])
                    n++;
                else if (ch[x][j] == 0 && c == 0 && c == z) {
                    qi.x = x;
                    qi.y = j;
                    c = 1;
                } else
                    break;

            }
            if ((n + m + c) >= 4)
                return qi;
            c = 0;
            m=0;
            n=0;
        }

        for (int z = 0; z < 2; z++) { //看左上右下向
            for (i = x + 1, j = y + 1; j < (y + 5) && (j <=17) && (i <=17); j++, i++) {
                if (ch[i][j] == ch[x][y])
                    m++;
                else if (ch[i][j] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = j;
                    c = 1;
                }
                else
                    break;
            }
            for (i = x - 1, j = y - 1; j > (y - 5) && (j >= 0) && (i >= 0); i--, j--) {
                if (ch[i][j] == ch[x][y])
                    n++;
                else if (ch[i][j] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = j;
                    c = 1;
                } else
                    break;

            }
            if ((n + m + c) >= 4)
                return qi;
            c = 0;
            m=0;
            n=0;
        }

        for (int z = 0; z < 2; z++) { //看左下右上向
            for (i = x - 1, j = y + 1; j < (y + 5) && (j <= 17) && (i >= 0); j++, i--) {
                if (ch[i][j] == ch[x][y])
                    m++;
                else if (ch[i][j] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = j;
                    c = 1;
                }

                else
                    break;
            }
            for (i = x + 1, j = y - 1; j > (y - 5) && (j > 0) && (i <=17); i++, j--) {
                if (ch[i][j] == ch[x][y])
                    n++;
                else if (ch[i][j] == 0 && c == 0 && c == z) {
                    qi.x = i;
                    qi.y = j;
                    c = 1;
                } else
                    break;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -