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

📄 gameworld.java

📁 手机版泡泡龙游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            roundPara[x + 1][y + 1] == color)
          return false;
      }
    } //else
    return true;
  }

  private void dealWithHit(int i, int j)
  {
    int a = 8 << 1;
    if (nowX == paintW - 8)
    {
      if (i % 2 == 0)
      {
        roundPara[i + 1][j - 1] = isMovingColor;
        checkConnect(i + 1, j - 1, isMovingColor);
      }
      else
      {
        roundPara[i + 1][j + 1] = isMovingColor;
        checkConnect(i + 1, j + 1, isMovingColor);
      }
    }
    else if (nowX == 8)
    {
      roundPara[i + 1][0] = isMovingColor;
      checkConnect(i + 1, 0, isMovingColor);
    }
    else if (i % 2 == 0)
    {
      if (nowX < 8 + j * 16) //left
      {
        if (j >= 1 && Math.abs(nowY - (i * 14 + 8)) < localStand &&
            roundPara[i][j - 1] == 0)
        {
          roundPara[i][j - 1] = isMovingColor;
          checkConnect(i, j - 1, isMovingColor);
        }
        else if (roundPara[i + 1][j - 1] == 0)
        {
          roundPara[i + 1][j - 1] = isMovingColor;
          checkConnect(i + 1, j - 1, isMovingColor);
        }
        else
        {
//if(roundPara[i][j - 1] == 0)
          // {
          //  roundPara[i][j - 1] = isMovingColor;
//checkConnect(i,j - 1,isMovingColor);
          //}
//else
          {
            roundPara[i + 1][j] = isMovingColor;
            checkConnect(i + 1, j, isMovingColor);
          }
        }

      }
      else if (nowX >= 8 + j * 16)
      {
        if (j <= 6 && Math.abs(nowY - (i * 14 + 8)) < localStand &&
            roundPara[i][j + 1] == 0)
        {
          roundPara[i][j + 1] = isMovingColor;
          checkConnect(i, j + 1, isMovingColor);
        }
        else if (roundPara[i + 1][j] == 0)
        {
          roundPara[i + 1][j] = isMovingColor;
          checkConnect(i + 1, j, isMovingColor);
        }
        else
        {
          roundPara[i + 1][j - 1] = isMovingColor;
          checkConnect(i + 1, j - 1, isMovingColor);
        }
      }
    }
    else if (i % 2 == 1)
    {

      if (nowX < 8 + j * 16 + 8) //left
      {
        if (j >= 1 && Math.abs(nowY - (i * 14 + 8)) < localStand &&
            roundPara[i][j - 1] == 0)
        {
          roundPara[i][j - 1] = isMovingColor;
          checkConnect(i, j - 1, isMovingColor);
        }
        else if (j >= 0 && roundPara[i + 1][j] == 0)
        {
          roundPara[i + 1][j] = isMovingColor;
          checkConnect(i + 1, j, isMovingColor);
        }
        else
        {
          roundPara[i + 1][j + 1] = isMovingColor;
          checkConnect(i + 1, j + 1, isMovingColor);
        }

      }
      else if (nowX >= 8 + j * 16 + 8)
      {
        if (j <= 5 && Math.abs(nowY - (i * 14 + 8)) < localStand &&
            roundPara[i][j + 1] == 0) //down
        {
          roundPara[i][j + 1] = isMovingColor;
          checkConnect(i, j + 1, isMovingColor);
        }

        else if (roundPara[i + 1][j + 1] == 0)
        {
          roundPara[i + 1][j + 1] = isMovingColor;
          checkConnect(i + 1, j + 1, isMovingColor);
        }

        else
        {
          roundPara[i + 1][j] = isMovingColor;
          checkConnect(i + 1, j, isMovingColor);
        }

      }
    }
    for (int x = 0; x < 10; x++)
    {
      for (int y = 0; y < (x % 2 == 0 ? 8 : 7); y++)
        System.out.print(roundPara[x][y]);
    }
    if (checkDisappear()) // if this round three or more ball disappeared
      checkFall();
    isMoving = false;

  } //dealWithHit()

  private boolean gameOver()
  {
    for (int i = 11 - nowTop; i < 12; i++)
    {
      for (int j = 0; j < (i % 2 == 0 ? 8 : 7); j++)
        if (roundPara[i][j] > 0 && roundPara[i][j] < 9)
          return true;
    }
    return false;
  }

  private boolean isCollided(int x1, int y1, int x2, int y2)
  {
    if ( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) <=
        (8 + effectiveR) * (8 + effectiveR))
      return true;
    else return false;
  }

  /** Required paint implementation */
  protected void paint(Graphics g)
  {
    g.setColor(0, 0, 0);
    g.fillRect(0, 0, screenW, screenH);
    drawBackGround(g);
    g.translate(7, 3);
    g.setClip(0, 0, paintW, paintH);
    DirectGraphics dg = DirectUtils.getDirectGraphics(g);
    drawForeGround(g, dg);
    /** @todo Add paint codes */
  }

  private void addBalls(int floors)
  {
    for (int i = 0; i < 8; i++) //往最底层加上一层泡泡
    {
      for (int j = 10; j > 0; j--)
      {
        if (roundPara[i][j] != 0)
        {
          if (i % 2 == 0)
          {
            if (roundPara[i][j + 1] == 0)
              addOneBall(i, j + 1);
            break;
          }
          else if (i % 2 == 1) // i % 2 == 1
          {
            roundPara[i + 1][j - 1] = roundPara[i + 1][j - 1] == 0 ?
                1 + ( ( (Resource.random.nextInt() % 8) << 1) >> 1) :
                roundPara[i + 1][j - 1];
            roundPara[i + 1][j] = roundPara[i + 1][j] == 0 ?
                1 + ( ( (Resource.random.nextInt() % 8) << 1) >> 1) :
                roundPara[i + 1][j];
          }
        }
      }
    }
  }

  private void addOneBall(int x, int y)
  {
    if (
        (x % 2 == 0 && y < 8 && roundPara[x][y] == 0) ||
        (x % 2 == 1 && y < 7 && roundPara[x][y] == 0)
        )

      roundPara[x][y] = 1 + Math.abs(Resource.random.nextInt() % 8);

  }

  private void drawScore(Graphics g)
  {
    g.setClip(102, 192, 74, 16);
    g.setColor(100, 255, 100);
    g.drawString("score:" + score, 104, 194, Graphics.LEFT | Graphics.TOP);
    g.setClip(0, 0, 176, 208);
  }

  private void drawPaoPao(Graphics g)
  {
    for (int i = 0; i < 11; i++)
    {
      if (i % 2 == 0)
        for (int j = 0; j < 8; j++)
        {
          if (roundPara[i][j] > 0 && roundPara[i][j] < 9)
          {
            g.setClip(16 * j, 14 * i, 16, 16);
            g.drawImage(Resource.getImage(Resource.BALL),
                        j * 16 - (roundPara[i][j] - 1) * 16 +
                        (shaking ? shakeOffX[shakeCount] : 0),
                        i * 14, Graphics.LEFT | Graphics.TOP);
            g.setClip(0, 0, paintW, paintH);
          }
          else if (roundPara[i][j] > 8 && roundPara[i][j] < 17)
          {
            g.setClip(16 * j, 14 * i, 16, 16);
            switch (disappearCount)
            {
              case 5:
                g.drawImage(Resource.getImage(Resource.BALL),
                            j * 16 - (roundPara[i][j] - 8 - 1) * 16 +
                            (shaking ? shakeOffX[shakeCount] : 0),
                            i * 14, Graphics.LEFT | Graphics.TOP);
                break;
              case 4:
              case 3:
              case 2:
              case 1:
                g.drawImage(Resource.getImage(Resource.BALL),
                            j * 16 - (15 - disappearCount / 3) * 16 +
                            (shaking ? shakeOffX[shakeCount] : 0),
                            i * 14, Graphics.LEFT | Graphics.TOP);
                break;
              default:
                break;
            }
            g.setClip(0, 0, paintW, paintH);
          }
        }
      else if (i % 2 == 1)
        for (int j = 0; j < 7; j++)
        {
          if (roundPara[i][j] > 0 && roundPara[i][j] < 9)
          {
            g.setClip(8 + 16 * j, 14 * i, 16, 16);
            g.drawImage(Resource.getImage(Resource.BALL),
                        8 + 16 * j - (roundPara[i][j] - 1) * 16 +
                        (shaking ? shakeOffX[shakeCount] : 0),
                        i * 14, Graphics.TOP | Graphics.LEFT);
            g.setClip(0, 0, paintW, paintH);
          }
          else if (roundPara[i][j] > 8 && roundPara[i][j] < 17)
          {
            g.setClip(16 * j + 8, 14 * i, 16, 16);
            switch (disappearCount / 3)
            {
              case 5:
                g.drawImage(Resource.getImage(Resource.BALL),
                            j * 16 + 8 - (roundPara[i][j] - 8 - 1) * 16 +
                            (shaking ? shakeOffX[shakeCount] : 0),
                            i * 14, Graphics.LEFT | Graphics.TOP);
                break;
              case 4:
              case 3:
              case 2:
              case 1:
                g.drawImage(Resource.getImage(Resource.BALL),
                            j * 16 + 8 - (15 - disappearCount / 3) * 16 +
                            (shaking ? shakeOffX[shakeCount] : 0),
                            i * 14, Graphics.LEFT | Graphics.TOP);
                break;
              default:
                break;
            }
            g.setClip(0, 0, paintW, paintH);

          }
        }
    }
  }

  private void drawForeGround(Graphics g, DirectGraphics dg)
  {
    //drawTop(g);
    drawToBeShoot(g);
    drawNextOne(g);
    drawIsMoving(g);
    drawPointer(dg);
    drawPaoPao(g);
    drawFalling(g);
    if (roundStart)
    {
      ;
    }
    else
    {
      if (overThread)
      {
        g.setClip(0, paintH - overCount, paintW, overCount);
        for (int i = 0; i < 12; i++)
          for (int j = 0; j < (i % 2 == 0 ? 8 : 7); j++)
            if (roundPara[i][j] != 0)
              g.drawImage(Resource.getImage(Resource.BBALL),
                          j * 16 + 8 + (i % 2 == 0 ? 0 : 8),
                          i * 14, Graphics.VCENTER | Graphics.HCENTER);
        g.setClip(0, 0, paintW, paintH);
      }
      else
      {

      }

    }
    if (roundStart)
      drawRoundStart(dg);
  }

  private void drawBackGround(Graphics g)
  {
    g.drawImage(Resource.getImage(Resource.BG), 0, 0,
                Graphics.LEFT | Graphics.TOP);
    drawScore(g);
  }

  private void drawTop(Graphics g)
  {

  }

  private void drawPointer(DirectGraphics dg)
  {
    if (angle <= 90)
      dg.drawImage(Resource.getImage(angle / 6), 71 - orgX, 170 - orgY,
                   Graphics.VCENTER | Graphics.HCENTER, 0);
    else if (angle >= 90)
      dg.drawImage(Resource.getImage( (180 - angle) / 6), 71 - orgX, 170 - orgY,
                   Graphics.VCENTER | Graphics.HCENTER,
                   DirectGraphics.FLIP_HORIZONTAL);

  }

  private void drawIsMoving(Graphics g)
  {
    if (isMoving)
    {
      g.setClip(nowX - 8, nowY - 8, 16, 16);
      g.drawImage(Resource.getImage(Resource.BALL),
                  nowX - 8 - (isMovingColor - 1) * 16, nowY - 8,
                  Graphics.LEFT | Graphics.TOP);
      g.setClip(0, 0, paintW, paintH);
    }
  }

  private void drawToBeShoot(Graphics g)
  {
    g.setClip(71 - orgX - 8, 170 - orgY - 8, 16, 16);
    g.drawImage(Resource.getImage(Resource.BALL),
                71 - orgX - 8 - (toBeShootColor - 1) * 16,
                170 - orgY - 8, Graphics.LEFT | Graphics.TOP);
    g.setClip(0, 0, paintW, paintH);
  }

  private void drawNextOne(Graphics g)
  {
    g.setClip(54 - orgX - 8, 190 - orgY - 16, 16, 16);
    g.drawImage(Resource.getImage(Resource.BALL),
                54 - orgX - 8 - (nextOneColor - 1) * 16,
                190 - orgY - 16, Graphics.TOP | Graphics.LEFT);
    g.setClip(0, 0, paintW, paintH);
  }

  private void drawFalling(Graphics g)
  {
    if (fallingNum > 0)
    {
      for (int i = 0; i < fallingNum; i++)
      {
        g.setClip(fallingPara[i][1] - 8, fallingPara[i][2] - 8, 16, 16);
        g.drawImage(Resource.getImage(Resource.BALL),
                    fallingPara[i][1] - 8 - 16 * (fallingPara[i][0] - 1),
                    fallingPara[i][2] - 8, Graphics.LEFT | Graphics.TOP);
        g.setClip(0, 0, paintW, paintH);
      }
    }
  }

  public static void drawRoundStart(Graphics g)
  {

  }

  private void drawRoundStart(DirectGraphics dg)
  {
    if (roundStartCount <= 16)
    {
    }
    else if (roundStartCount <= 32)
    {
      if (roundStartCount >= 48)
      {

      }
    }
    else
    {
    }
  }

  private void drawGameOver(Graphics g)
  {

  }
}

⌨️ 快捷键说明

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