Thema: Delphi Fokus auf Form1 setzen

Einzelnen Beitrag anzeigen

funky

Registriert seit: 14. Nov 2010
15 Beiträge
 
#9

AW: Fokus auf Form1 setzen

  Alt 14. Nov 2010, 18:13
Also das ist der Teil wo er die Figur bewegt oder eben nicht bewegt:

Delphi-Quellcode:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin


    if (Key = VK_UP) then
  begin
     if (arFelder[PosY-1,PosX] = 0) or (arFelder[PosY-1,PosX] = 2) then
     begin
        PosY := PosY-1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
            ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



   else if (Key = VK_Down) then
  begin
     if (arFelder[PosY+1,PosX] = 0) or (arFelder[PosY+1,PosX] = 2) then
     begin
        PosY := PosY+1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
            ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



    else if (Key = VK_Right) then
  begin
     if (arFelder[PosY,PosX+1] = 0) or (arFelder[PosY,PosX+1] = 2) then
     begin
        PosX := PosX+1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
             ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



   else if (Key = VK_Left) then
  begin
     if (arFelder[PosY,PosX-1] = 0) or (arFelder[PosY,PosX-1] = 2) then
     begin
        PosX := PosX-1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
            begin
             ShowMessage('Sieg!')
            end;

     arFelder[PosY,PosX] := 4;
     end;

  end



end;

Und dann ist da noch der Teil wo das Spielfeld gezeichnet wird.

Geändert von mkinzler (14. Nov 2010 um 18:30 Uhr) Grund: Code-Tag durch Delphi-Tag ersetzt
  Mit Zitat antworten Zitat