Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm2.Button4Click(Sender: TObject);//pressing the "right" button
- var
- i, j: Integer;
- begin
- for i := 0 to Form2.StringGrid1.ColCount do
- for j := 0 to Form2.StringGrid1.RowCount do
- if StringGrid1.Cells[i, j] = 'P' then
- begin
- StringGrid1.Cells[i, j] := '0';
- StringGrid1.Cells[i+1, j] := 'P';
- { I have done the same for up, left and down (down would be j+1, left would be i-1, etc}
- break;
- end;
- end;
- private
- PColumn: Integer;
- PRow: Integer;
- procedure TForm2.FormCreate(Sender: TObject);
- begin
- // populate the grid as needed...
- // place 'P' somewhere on the grid and keep track of it...
- PColumn := ...;
- PRow := ...;
- end;
- // pressing the "up" button
- procedure TForm2.Button1Click(Sender: TObject);
- begin
- if PRow > 0 then
- begin
- Dec(PRow);
- StringGrid1.Cells[PColumn, PRow+1] := '0';
- StringGrid1.Cells[PColumn, PRow ] := 'P';
- end;
- end;
- // pressing the "left" button
- procedure TForm2.Button2Click(Sender: TObject);
- begin
- if PColumn > 0 then
- begin
- Dec(PColumn);
- StringGrid1.Cells[PColumn+1, PRow] := '0';
- StringGrid1.Cells[PColumn, PRow] := 'P';
- end;
- end;
- // pressing the "down" button
- procedure TForm2.Button3Click(Sender: TObject);
- begin
- if PRow < (StringGrid1.RowCount-1) then
- begin
- Inc(PRow);
- StringGrid1.Cells[PColumn, PRow-1] := '0';
- StringGrid1.Cells[PColumn, PRow ] := 'P';
- end;
- end;
- // pressing the "right" button
- procedure TForm2.Button4Click(Sender: TObject);
- begin
- if PColumn < (StringGrid1.ColCount-1) then
- begin
- Inc(PColumn);
- StringGrid1.Cells[PColumn-1, PRow] := '0';
- StringGrid1.Cells[PColumn, PRow] := 'P';
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement