一个基于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); } } 下载源码 |
| [] [返回上一页] [打 印] |
|
文章评论 |
