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

📄 main.pas

📁 刚从网上找到的连连看的源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      incTime1 := 0;
      FGameState := gtWait;
     end;
    exit;
  end;

  if FGameState = gtPaused then
  begin
    if DXDraw.CanDraw then
    for i1 := low(FSprites) to high(FSprites) do
    begin
      for j1 := low(FSprites[0]) to high(FSprites[0]) do
      begin
        if not(FSprites[i1][j1].dead) and (FSprites[i1][j1].MonoSprite<>nil) then
        begin
        if DXDraw.CanDraw then
        BackImage.Items[FStep-1].StretchDraw(DXDraw.Surface,Rect(FSprites[i1][j1].X,    //FSprites[i1][j1].Y,FSprites[i1][j1].X+FImageW+7,
                    FSprites[i1][j1].Y,FSprites[i1][j1].X+FBackImageW,
                    FSprites[i1][j1].Y+FBackImageH),0);
        end;
      end;
      with DXImageList1.Items.Find('back') do
      Draw(DXDraw.Surface,
          (DXDraw.Surface.Width - width) div 2,
            (DXDraw.Surface.Height - Height) div 2,0) ;
    end;

    DrawRegInfo;

    DXDraw.Flip;
    exit;
  end;

  inc(incTime);
  if incTime >= (1000 div DXTimer1.Interval) then
  begin
    inctime := 0;
    inc(FLostTime);
    if FLostTime = FTime then
      GameOver;
  end;

  if FGameState = gtWait then exit;


  {  Description  }
  DXDraw.Surface.Fill(0);
  
    //DXDraw.Surface.Canvas.Release;
    for i1 := low(FSprites) to high(FSprites) do
    begin
      for j1 := low(FSprites[0]) to high(FSprites[0]) do
      begin
        if not(FSprites[i1][j1].dead) and (FSprites[i1][j1].MonoSprite<>nil) then
        begin
        if DXDraw.CanDraw then
        BackImage.Items[FStep-1].StretchDraw(DXDraw.Surface,Rect(FSprites[i1][j1].X,    //FSprites[i1][j1].Y,FSprites[i1][j1].X+FImageW+7,
                    FSprites[i1][j1].Y,FSprites[i1][j1].X+FBackImageW,
                    FSprites[i1][j1].Y+FBackImageH),0);
        end;
      end
    end;

    //DXDraw.Surface.Canvas.Release;

    for i1 := low(FSprites) to high(FSprites) do
    begin
      for j1 := low(FSprites[0]) to high(FSprites[0]) do
      begin
        if not(FSprites[i1][j1].dead) and (FSprites[i1][j1].MonoSprite<>nil) then
        try
        if DXDraw.CanDraw then
        ImageList.Items[FSprites[i1][j1].ImageID].StretchDraw(DXDraw.Surface,Rect(FSprites[i1][j1].X,    //FSprites[i1][j1].Y,FSprites[i1][j1].X+FImageW+7,
                    FSprites[i1][j1].Y,FSprites[i1][j1].X+FImageW,
                    FSprites[i1][j1].Y+FImageH),0);
        //FSprites[i1][j1].MonoSprite.DoDraw;
        except
        end;
      end
    end;

  //DXSpriteEngine.Draw;
  //DXDraw.Surface.Canvas.Lock;
  if DXDraw.CanDraw then
  with DXDraw.Surface.Canvas do
  begin
    //DXDraw.Surface.Canvas.Release;
    if (FTime <> 0) and (FGameState = gtRuning) then
    begin

      //out information
      Brush.Color := clwhite;
      try
      except
      end;
      FillRect(Rect((Screen.width -FProgressW) div 2-1,FProgressT-1,
              (Screen.width -FProgressW) div 2 + FProgressW+1,
              FProgressT + FProgressH+1));

      Brush.Style := bsSolid;
      Brush.Color := FProgressC;
      FillRect(Rect((Screen.width -FProgressW) div 2,FProgressT,
              (Screen.width -FProgressW) div 2 + round(FProgressW*((FTime - FLostTime) / FTime)),
              FProgressT + FProgressH));
      Brush.Color := clblack;
      try
      if Font <> nil then
      begin
      DXDraw.Surface.Canvas.Font.Color := clwhite;
      DXDraw.Surface.Canvas.Font.Size := 9;
      end;
      except
      end;
      textout(10,10,FStrs[10]+inttostr(FTime - FLostTime)) ; //+':'+inttostr(100-inctime)
      textout(10,25,FStrs[11]+inttostr(FHint)+FStrs[13]);
      textout(10,40,FStrs[12]+inttostr(FWash)+FStrs[13]);
      textout(10,55,NumStrs[FStep]);
      //textout(10,70,FStrs[14]+inttostr(ImageCount)+FStrs[15]);
      //textout(10,85,FStrs[16]+inttostr(OneImageCount div 2)+FStrs[18]);
      //if DXSpriteEngine.Engine.Count > 0 then
        //textout(10,105,FStrs[17]+inttostr(DXSpriteEngine.Engine.Count div 2)+FStrs[18]);

      DrawRegInfo;

      try
      if Font <> nil then
      begin
      Font.Color := clyellow;
      Font.Size := 12;
      end;
      except
      end;
      if FStep < 10 then
        textout((Screen.width -textwidth(FStrs[FStep])) div 2,FProgressT
          + FProgressH + 10,FStrs[FStep])
      else
        textout((Screen.width -textwidth(FStrs[42])) div 2,FProgressT
          + FProgressH + 10,FStrs[42]);
      try
      Font.Color := clRed;
      Font.Size := 12;
      except
      end;
      textout((Screen.width -FProgressW) div 2 + FProgressW + 20,FProgressT,
              'Scores : '+inttostr(FScore));

      //out Random Envent
      if (FRanEventID.ID > 0) and (FRanEventID.ID < high(RanEventName)) then
      begin
        textout((Screen.width -textwidth(FRanEventName[FRanEventID.ID])) div 2,FProgressT
          + FProgressH + 10+textheight('A')+10,FRanEventName[FRanEventID.ID]+' '+inttostr(FRanEventID.Add));
        inc(incTime1);
         if incTime1 >= (3000 div DXTimer1.Interval) then
         begin
          incTime1 := 0;
          FRanEventID.ID := -1;
         end;
      end;
    end;
  end;

  //draw focuse
  for i := low(FocusedSprite) to high(FocusedSprite) do
  begin
    if FocusedSprite[i].ID = - 1 then continue;
    if DXDraw.CanDraw then
    with DXDraw.Surface.Canvas do
    begin
      Brush.Style := bsClear;

      try
      Pen.Color := clred;
      Pen.Width := 3;
      except
      end;
      R := Rect(FocusedSprite[i].X+3,FocusedSprite[i].Y+3,
                                FocusedSprite[i].X+FImageW-2,FocusedSprite[i].Y+FImageH-2);
      try
      Pen.Color := clblack;
      except
      end;
      PolyLine([Point(R.Left, R.Bottom), Point(R.Left, R.Top),
        Point(R.Right, R.Top)]);
      Pen.Color := clwhite;
      PolyLine([Point(R.Right, R.Top), Point(R.Right, R.Bottom),
        Point(R.Left, R.Bottom)]);
    end;
  end;
  //draw hint
  for i := low(FFirstRoadPoint) to high(FFirstRoadPoint) do
  begin
    if not(FFirstRoadPoint[i].show) then break;
    if DXDraw.CanDraw then
    with DXDraw.Surface.Canvas do
    begin
      inc(incTime2);
      Brush.Style := bsClear;
      try
      Pen.Color := clred;
      Pen.Width := 3;
      except
      end;
      R := Rect(FFirstRoadPoint[i].X+3,FFirstRoadPoint[i].Y+3,
                                FFirstRoadPoint[i].X+FImageW-2,FFirstRoadPoint[i].Y+FImageH-2);
      try
      Pen.Color := clwhite;
      except
      end;
      PolyLine([Point(R.Left, R.Bottom), Point(R.Left, R.Top),
        Point(R.Right, R.Top)]);
      try
      Pen.Color := clblack;
      except
      end;
      PolyLine([Point(R.Right, R.Top), Point(R.Right, R.Bottom),
        Point(R.Left, R.Bottom)]);
      //Release;
    end;
    if incTime2 >= (1200 div DXTimer1.Interval) then
    begin
      FFirstRoadPoint[0].show := false;
      FFirstRoadPoint[1].show := false;
      incTime2 := 0;
    end;
  end;

  if (FGameState = gtRuning) and (DXSpriteEngine.Engine.Count = 0)  then
  begin
    if DXDraw.CanDraw then
    with DXDraw.Surface.Canvas do
    begin
    try
      Font.Size := 30;
      Font.Color := clred;
    except
    end;
      if FStep < 10 then
        TextOut((Screen.width - TextWidth(NumStrs[FStep+1])) div 2,
          (DXDraw.Height - TextHeight('第')) div 2,NumStrs[FStep+1]);
    end;

    inc(incTime1);
    if incTime1 >= (500 div DXTimer1.Interval) then
    begin
      incTime1 := 0;
      DoPassStep;
      CurLostIndex := 0;
    end;
  end;
  DXDraw.Surface.Canvas.Release;
  try
    DXDraw.Flip;
  except
  end

  finally
    //Application.HandleMessage;
  end;
end;

procedure TForm1.DXDrawMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  FX := X;
  FY := Y;

  if Button = mbLeft then
    FocusedSprites(X,Y)
  else if Button = mbRight then
    UnFocusedSprite;
  //Form1.DXInput.Mouse.Update;
  //DXInput.Update;
end;

procedure TForm1.FocusedSprites(AX, AY: integer);
var
  ID,i,j: integer;
begin
    //FocusedSprite[1].ID := ID;
  if FGameState <> gtRuning then
    exit;
  //InitializeID;

  for i := low(FSprites) to high(FSprites) do
  begin
    for j := low(FSprites[0]) to high(FSprites[0]) do
    begin
      if FSprites[i][j].Dead then continue;
      with FSprites[i][j].MonoSprite do
      begin
        if (Form1.FX >= X) and (Form1.FX <= X+FImageW)
        and (Form1.FY >= Y) and (Form1.FY <= Y+FImageH) then
        begin
          if (FocusedSprite[1].XID = i) and (FocusedSprite[1].YID = j) then
          begin
            if FocusedSprite[1].ID <> -1 then
              FocusedSprite[1].ID := -1
            else
            begin
              FocusedSprite[1].ID := 1;
              FocusedSprite[1].ImageID := FSprites[i][j].MonoSprite.ImageID;
            end;
            {FocusedSprite[1].X := FocusedSprite[0].X;
            FocusedSprite[1].Y := FocusedSprite[0].Y;
            FocusedSprite[1].ID := FocusedSprite[0].ID;
            FocusedSprite[1].ImageID := FocusedSprite[1].ImageID;
            FocusedSprite[1].XID := FocusedSprite[0].XID;
            FocusedSprite[1].YID := FocusedSprite[0].YID;  }
            //if FocusedSprite[1].ID = -1 then
            Continue;
          end
          else if (FocusedSprite[0].XID = i) and (FocusedSprite[0].YID = j) then
          begin
            if FocusedSprite[0].ID <> -1 then
              FocusedSprite[0].ID := -1
            else
            begin
              FocusedSprite[0].ID := 1;
              FocusedSprite[0].ImageID := FSprites[i][j].MonoSprite.ImageID;
            end;
            {if FocusedSprite[1].ID <> -1 then
            begin
            FocusedSprite[0].X := FocusedSprite[1].X;
            FocusedSprite[0].Y := FocusedSprite[1].Y;
            FocusedSprite[0].ID := FocusedSprite[1].ID;
            FocusedSprite[0].ImageID := FocusedSprite[1].ImageID;
            FocusedSprite[0].XID := FocusedSprite[1].XID;
            FocusedSprite[0].YID := FocusedSprite[1].YID;
            end; }
            //if FocusedSprite[0].ID = -1 then
            Continue;
          end;

          //if FocusedSprite[0].ID = TMonoSprite(DXSpriteEngine.Engine[i]).ID then
          //begin
            //FocusedSprite[0].ID := -1;
            //Continue;
          //end;

          if FocusedSprite[1].ID <> -1 then
          begin
          FocusedSprite[0].X := FocusedSprite[1].X;
          FocusedSprite[0].Y := FocusedSprite[1].Y;
          FocusedSprite[0].ID := FocusedSprite[1].ID;
          FocusedSprite[0].ImageID := FocusedSprite[1].ImageID;
          FocusedSprite[0].XID := FocusedSprite[1].XID;
          FocusedSprite[0].YID := FocusedSprite[1].YID;
          end;

          FocusedSprite[1].X := round(X);
          FocusedSprite[1].Y := round(Y);
          FocusedSprite[1].ID := FSprites[i][j].MonoSprite.ID;
          FocusedSprite[1].ImageID := FSprites[i][j].MonoSprite.ImageID;
          FocusedSprite[1].XID := i;//FSprites[i][j].MonoSprite.XID;
          FocusedSprite[1].YID := j;//FSprites[i][j].MonoSprite.YID;
          if FMusic then
          DXWaveList1.Items.Find('Alert').Play(false);

          break;
        end;
      end;
    end;
  end;
  DeadSprite;
end;

procedure TForm1.DeadSprite;
  procedure Dead;
  begin
    //InitializeID;
    if (FRoadPoint[0].throut ) and (FRoadPoint[1].throut) then
    begin
      if FSprites[FocusedSprite1[0].XID][FocusedSprite1[0].YID].dead then exit;
      FSprites[FocusedSprite1[0].XID][FocusedSprite1[0].YID].dead := true;
      FSprites[FocusedSprite1[1].XID][FocusedSprite1[1].YID].dead := true;

      FSprites[FocusedSprite1[0].XID][FocusedSprite1[0].YID].MonoSprite.Dead;
      FSprites[FocusedSprite1[1].XID][FocusedSprite1[1].YID].MonoSprite.Dead;
      //DXSpriteEngine.Dead;
      FSprites[FocusedSprite1[0].XID][FocusedSprite1[0].YID].MonoSprite.ISDead := true;
      FSprites[FocusedSprite1[1].XID][FocusedSprite1[1].YID].MonoSprite.ISDead := true;
      FocusedSprite[0].ID := -1;
      FocusedSprite[1].ID := -1;
      FocusedSprite[1].ImageID := -1;
      FocusedSprite[0].ImageID := -1;

      FRoadPoint[0].throut := false;
      FRoadPoint[1].throut := false;
      FRoadPoint[0].ID := -1;
      FRoadPoint[1].ID := -1;

      inc(CurLostIndex);

      //Move Sprite
      if DXSpriteEngine.Engine.Count > 2 then
      MoveSprite(FStep);

      //get score
      if FLostTime = 0 then FLostTime := 1;
      FScore := FScore +  round(((CurLostIndex*FOneTime)/FLostTime)*FOneSpriteScore);

      if FMusic then
        DXWaveList1.Items.Find('recycle').Play(false);

      //random event
      Randomize;
      if RandomRange(1,50+(FLevel-1)*50) in[1..4] then
        RandomEvent;

      getFirstRaodPoint(FFirstRoadPoint[0],FFirstRoadPoint[1],false);
      //InitializeID;
      if DXDraw.CanDraw then
      DrawLine(FocusedSprite[0].X + FImageW div 2,FocusedSprite[0].Y+ FImageH div 2,
            FocusedSprite[1].X + FImageW div 2,FocusedSprite[1].Y+FImageH div 2,DXDraw.Surface.Canvas,CLGreen);
    end;
  end;
begin
  if (FocusedSprite[0].ID = - 1) or (FocusedSprite[1].ID = -1) then exit;
  if (FocusedSprite[0].XID = FocusedSprite[1].XID ) and
  (FocusedSprite[0].YID = FocusedSprite[1].YID ) then exit;

  AssignPoint(FocusedSprite[0],FocusedSprite1[0]);

⌨️ 快捷键说明

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