WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章J2ME技术程序开发一个基于MIDP的迷宫游戏

一个基于MIDP的迷宫游戏
作者:J2MEDEV  来源:J2MEDEV  发布时间:2006-7-25 9:08:00
uares[i].length) {
            if(mySquares[i][j + 2] == 3) {
                mySquares[i][j + 2] = 2;
                int[] newSquare = new int[2];
                newSquare[0] = i;
                newSquare[1] = j + 2;
                possibleSquares.addElement(newSquare);
            } else if(mySquares[i][j + 2] == 1) {
                links[2*linkCount] = i;
                links[2*linkCount + 1] = j + 1;
                linkCount++;
            }
        }
        if(j >= 3) {
            if(mySquares[i][j - 2] == 3) {
                mySquares[i][j - 2] = 2;
                int[] newSquare = new int[2];
                newSquare[0] = i;
                newSquare[1] = j - 2;
                possibleSquares.addElement(newSquare);
            } else if(mySquares[i][j - 2] == 1) {
                links[2*linkCount] = i;
                links[2*linkCount + 1] = j - 1;
                linkCount++;
            }
        }
        if(i + 3 <= mySquares.length) {
            if(mySquares[i + 2][j] == 3) {
                mySquares[i + 2][j] = 2;
                int[] newSquare = new int[2];
                newSquare[0] = i + 2;
                newSquare[1] = j;
                possibleSquares.addElement(newSquare);
            } else if(mySquares[i + 2][j] == 1) {
                links[2*linkCount] = i + 1;
                links[2*linkCount + 1] = j;
                linkCount++;
            }
        }
        if(linkCount > 0) {
            int linkChoice = getRandomInt(linkCount);
            int linkX = links[2*linkChoice];   int linkY = links[2*linkChoice + 1];
            mySquares[linkX][linkY] = 1;
            int[] removeSquare = new int[2];
            removeSquare[0] = linkX;
            removeSquare[1] = linkY;
            possibleSquares.removeElement(removeSquare);
        }
    }
   
    /**
     * a randomization utility.
     * @param upper the upper bound for the random int.
     * @return a random non-negative int less than the bound upper.
     */
    public int getRandomInt(int upper) {
        int retVal = myRandom.nextInt() % upper;
        if(retVal < 0) {
            retVal += upper;
        }
        return(retVal);
    }
   
}
下载源码

上一页  [1] [2] [3] [4] [5] 

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码