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

📄 gameworld.java

📁 手机游戏 泡泡龙 J2ME源代码+详细注释
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                     {
                          hitted = true;
                          nowX = preX;
                          nowY = preY;
                          hittedI = i;
                          hittedJ = j;
                            break;
                                     }
                                   }
               return;
            }
          }
        }

      }       //for(int i = 0;i < 10; i ++)

 }
private boolean checkDisappear()
 {
int sameColorCount = 0;
 for(int i = 0;i < 10;i ++)
   if(i % 2 == 0)
   {
for(int j = 0 ;j < 8 ;j ++)
       if(roundPara[i][j] > 8 && roundPara[i][j] < 17)

         sameColorCount ++;
   }
   else if(i % 2 == 1)
   {
      for(int j = 0;j < 7;j ++)
        if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
          sameColorCount ++;
   }
if(sameColorCount >= 3)
   {
score += sameColorCount;
disappearCount = 5;
/*
for(int i = 0;i < 10;i ++)
     {
     for(int j = 0;j < (i % 2 == 0 ? 8 : 7);j ++)
      {
      if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
        roundPara[i][j] = 0;
      }
     }
*/
return true;
   }
   for(int i = 0;i < 10;i ++)
        {
        for(int j = 0;j < (i % 2 == 0 ? 8 : 7);j ++)
         {
         if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
           roundPara[i][j] -= 8;
         }
        }

 return false;
 }
private void checkConnect(int x,int y,int color)         //let all round have the same color disappear
 {
if(x == 10 && haveNoSameRound(x,y,color))
   {
     overThread = true;
     return;
   }
if(roundPara[x][y] == color)
     roundPara[x][y] += 8;
if(haveNoSameRound(x,y,color))
     return;
else
   {
   if(x == 9)
   {
   if(y == 0)
    {
     if(roundPara[9][1] == color)
     checkConnect(9,1,color);
     if(roundPara[8][1] == color)
     checkConnect(8,1,color);
     if(roundPara[8][2] == color)
       checkConnect(8,2,color);
    }
   else if(y == 6)
    {
if(roundPara[9][7] == color)
        checkConnect(10,6,color);
if(roundPara[8][6] == color)
        checkConnect(8,6,color);
    }
   else
    {
   if(roundPara[8][y] == color)
     checkConnect(8,y,color);
  if(roundPara[8][y + 1] == color)
    checkConnect(8,y + 1,color);
   if(roundPara[9][y - 1] == color)
     checkConnect(9,y - 1,color);
   if(roundPara[9][y + 1] == color)
     checkConnect(9,y + 1,color);
    if(roundPara[10][y] == color)
      checkConnect(10,y,color);
    if(roundPara[10][y + 1] == color)
      checkConnect(10,y + 1,color);
    }
   }            //if(x == 10)
else if(x == 0)                              //the first row
   {
   if(y == 0)
      {
if(roundPara[0][1] == color)
   checkConnect(0,1,color);
if(roundPara[1][0] == color)
   checkConnect(1,0,color);
      }
   else if(y == 7)
      {
      if(roundPara[0][6] == color)
        checkConnect(0,6,color);
      if(roundPara[1][6] == color)
        checkConnect(1,6,color);
      }
   else
     {
     if(roundPara[x][y - 1] == color)
       checkConnect(x,y - 1,color);
     if(roundPara[x][y + 1] == color)
       checkConnect(x,y + 1,color);
     if(roundPara[x + 1][y - 1] == color)
       checkConnect(x + 1,y - 1,color);
     if(roundPara[x + 1][y] == color)
       checkConnect(x + 1,y,color);
     }
   }
else if(y == 0)
   {
  if(x % 2 == 1)
     {
    if(roundPara[x - 1][y] == color)
      checkConnect(x - 1,y,color);
    if(roundPara[x - 1][y + 1] == color)
      checkConnect(x- 1,y + 1,color);
    if(roundPara[x][y + 1] == color)
      checkConnect(x,y + 1,color);
    if(roundPara[x + 1][y] == color)
      checkConnect(x + 1,y,color);
    if(roundPara[x + 1][y + 1] == color)
      checkConnect(x + 1,y + 1,color);
     }
  else if(x % 2 == 0)
     {
if(roundPara[x - 1][y] == color)
         checkConnect(x - 1,y,color);
if(roundPara[x][y + 1] == color)
         checkConnect(x, y + 1,color);
if(roundPara[x + 1][y] == color)
         checkConnect(x + 1,y ,color);
     }
   }
else if(y == 6 && x % 2 == 1)
   {
if(roundPara[x - 1][y] == color)
       checkConnect(x - 1,y,color);
if(roundPara[x - 1][y + 1] == color)
       checkConnect(x - 1,y + 1,color);
if(roundPara[x][y - 1] == color)
       checkConnect(x,y - 1,color);
if(roundPara[x + 1][y] == color)
       checkConnect(x + 1,y,color);
if(roundPara[x + 1][y + 1] == color)
       checkConnect(x + 1,y + 1,color);
   }
else if(y == 7 && x % 2 == 0)
   {
if(roundPara[x - 1][y - 1] == color)
       checkConnect(x - 1,y - 1,color);
if(roundPara[x][y - 1] == color)
       checkConnect(x,y - 1,color);
if(roundPara[x + 1][y - 1] == color)
       checkConnect(x + 1,y - 1,color);
   }
else
   {
   if(x % 2 == 0)
     {
if(roundPara[x - 1][y] == color)
         checkConnect(x - 1,y,color);
if(roundPara[x - 1][y - 1] == color)
         checkConnect(x - 1,y - 1,color);
if(roundPara[x][y - 1] == color)
         checkConnect(x,y - 1,color);
if(roundPara[x][y + 1] == color)
         checkConnect(x,y + 1,color);
if(roundPara[x + 1][y] == color)
         checkConnect(x + 1,y,color);
if(roundPara[x + 1][y - 1] == color)
         checkConnect(x + 1,y - 1,color);

     }
   else if(x % 2 == 1)
     {
       if(roundPara[x - 1][y] == color)
                checkConnect(x - 1,y,color);
       if(roundPara[x - 1][y + 1] == color)
                checkConnect(x - 1,y + 1,color);
       if(roundPara[x][y - 1] == color)
                checkConnect(x,y - 1,color);
       if(roundPara[x][y + 1] == color)
                checkConnect(x,y + 1,color);
       if(roundPara[x + 1][y] == color)
                checkConnect(x + 1,y,color);
       if(roundPara[x + 1][y + 1] == color)
                checkConnect(x + 1,y + 1,color);

     }

    }
   }
                          //
 }
private void checkFall()
 {
int color;
for(int i = 0;i < 10;i ++)            //have no connectting with the top wall
   {
       if(i % 2 == 0)
     {
for(int j = 0;j < 8 ;j ++)
       {
color = roundPara[i][j];
  if(roundPara[i][j] > 0 && roundPara[i][j] < 9 && !connectWithTopWall(i,j))
         {
           fallingNum ++;
           score ++;
           roundPara[i][j] = 0;
         fallingPara[fallingNum - 1][0] = color;
         fallingPara[fallingNum - 1][1] = 16 * j + 8;
         fallingPara[fallingNum - 1][2] = 14 * i + 8;
        }
        for(int x = 0;x < 10;x ++)
                 {
                   for(int y = 0;y < (x % 2 == 0 ? 8 : 7);y ++)
                  if(roundPara[x][y] > 16 && roundPara[x][y] < 25)
                    roundPara[x][y] = roundPara[x][y] - 16;
                 }
       }
     }
else if(i % 2 == 1)
     {
for(int j = 0;j < 7;j ++)
       {
color = roundPara[i][j];
     if(roundPara[i][j] > 0 && roundPara[i][j] < 9 && !connectWithTopWall(i,j))
         {
           fallingNum ++;
           score ++;
           roundPara[i][j] = 0;
           fallingPara[fallingNum - 1][0] = color;
           fallingPara[fallingNum - 1][1] = 16 * j + 8;
           fallingPara[fallingNum - 1][2] = 14 * i + 8;

         }
         for(int x = 0;x < 10;x ++)
                    {
                      for(int y = 0;y < (x % 2 == 0 ? 8 : 7);y ++)
                      if(roundPara[x][y] > 16 && roundPara[x][y] < 25)
                        roundPara[x][y] = roundPara[x][y] - 16;
                    }

       }
     }
   }                  //for(int i = 1;i < 10;i ++)
for(int m = 0;m < 10;m ++)
   {
     for(int n = 0;n < (m % 2 == 0 ? 8 : 7);n ++)
       System.out.print(roundPara[m][n]);
   }
 }
private boolean connectWithTopWall(int i,int j)
 {
if(i == 0 && roundPara[i][j] > 0 && roundPara[i][j] < 9)
     return true;
else   if(roundPara[i][j] > 0 && roundPara[i][j] < 9)
         {
        roundPara[i][j] += 16;
  if(i == 9)
   {
   if(j == 0)
    {
    if(connectWithTopWall(8,0) || connectWithTopWall(8,1) || connectWithTopWall(9,1))
      return true;
    }
   else if(j == 6)
    {
     if(connectWithTopWall(8,6) || connectWithTopWall(8,7) || connectWithTopWall(9,5))
     return true;
    }
   else if(connectWithTopWall(9,j - 1) || connectWithTopWall(9,j + 1)
         ||connectWithTopWall(8,j) || connectWithTopWall(8,j + 1))
     return true;
   }
else if(i == 0)
   {

   }
else if(j == 0)
   {
  if(i % 2 == 1)
     {
       if(connectWithTopWall(i - 1,j + 1) || connectWithTopWall(i - 1,j)
       ||connectWithTopWall(i,j + 1)
       ||connectWithTopWall(i + 1,j + 1) || connectWithTopWall(i + 1,j))
    return true;
     }
  else if(i % 2 == 0)
     {
     if(connectWithTopWall(i - 1,j)
     || connectWithTopWall(i,j + 1) ||
     connectWithTopWall(i + 1,j))
       return true;
     }
   }
else if(j == 6 && i % 2 == 1)
   {
if(connectWithTopWall(i - 1,j) || connectWithTopWall(i - 1,j + 1)
   || connectWithTopWall(i,j - 1)
   || connectWithTopWall(i + 1,j) || connectWithTopWall(i + 1,j + 1))
      return true;
   }
else if(j == 7 && i % 2 == 0)
   {
   if(connectWithTopWall(i,j - 1)
   || connectWithTopWall(i - 1,j - 1)
   || connectWithTopWall(i + 1,j - 1))
     return true;
   }
else
   {
   if(i % 2 == 0)
     {
     if(connectWithTopWall(i - 1,j - 1)|| connectWithTopWall(i - 1,j)
        || connectWithTopWall(i, j - 1) || connectWithTopWall(i, j + 1)
        || connectWithTopWall(i + 1,j - 1) || connectWithTopWall(i + 1, j))
    return true;
     }
   else if(i % 2 == 1)
     {
     if(connectWithTopWall(i - 1,j) || connectWithTopWall(i - 1,j + 1)
        || connectWithTopWall(i, j - 1) || connectWithTopWall(i,j + 1)
        || connectWithTopWall(i + 1,j) || connectWithTopWall(i + 1,j + 1))
     return true;
     }
   }
 return false;
 }
else return false;
 }
private boolean haveNoSameRound(int x,int y,int color)
 {
if(x == 10)
   {
    if(roundPara[9][y - 1] == color || roundPara[9][y] == color)
     return false;
   }
else if(x == 0)                              //the first row
   {
   if(y == 0)
      {
      if(roundPara[0][1] == color || roundPara[1][0] == color)
        return false;
      }
   else if(y == 7)
      {
      if(roundPara[0][6] == color || roundPara[1][6] == color)
        return false;
      }
   else if(roundPara[0][y - 1] == color || roundPara[0][y + 1] == color
        || roundPara[1][y] == color || roundPara[1][y - 1] == color)
        return false;
   }
else if(y == 0)
   {
  if(x % 2 == 1)
     {
    if(roundPara[x - 1][y] == color || roundPara[x - 1][y + 1] == color || roundPara[x][y + 1] == color
    ||roundPara[x + 1][y] == color || roundPara[x + 1][y + 1] == color)
    return false;
     }
  else if(x % 2 == 0)
     {
     if(roundPara[x - 1][y] == color || roundPara[x][y + 1] == color || roundPara[x + 1][y] == color)
       return false;
     }
   }
else if(y == 6 && x % 2 == 1)
   {
   if(roundPara[x][y - 1] == color || roundPara[x - 1][y] == color || roundPara[x - 1][y + 1] == color
    ||roundPara[x + 1][y] == color || roundPara[x + 1][y + 1] == color)
   return false;
   }
else if(y == 7 && x % 2 == 0)
   {

⌨️ 快捷键说明

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