Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. procedure TForm2.Button4Click(Sender: TObject);//pressing the "right" button
  2. var
  3. i, j: Integer;
  4. begin
  5. for i := 0 to Form2.StringGrid1.ColCount do
  6. for j := 0 to Form2.StringGrid1.RowCount do
  7. if StringGrid1.Cells[i, j] = 'P' then
  8. begin
  9. StringGrid1.Cells[i, j] := '0';
  10. StringGrid1.Cells[i+1, j] := 'P';
  11. { I have done the same for up, left and down (down would be j+1, left would be i-1, etc}
  12. break;
  13. end;
  14. end;
  15.  
  16. private
  17. PColumn: Integer;
  18. PRow: Integer;
  19.  
  20. procedure TForm2.FormCreate(Sender: TObject);
  21. begin
  22. // populate the grid as needed...
  23. // place 'P' somewhere on the grid and keep track of it...
  24. PColumn := ...;
  25. PRow := ...;
  26. end;
  27.  
  28. // pressing the "up" button
  29. procedure TForm2.Button1Click(Sender: TObject);
  30. begin
  31. if PRow > 0 then
  32. begin
  33. Dec(PRow);
  34. StringGrid1.Cells[PColumn, PRow+1] := '0';
  35. StringGrid1.Cells[PColumn, PRow ] := 'P';
  36. end;
  37. end;
  38.  
  39. // pressing the "left" button
  40. procedure TForm2.Button2Click(Sender: TObject);
  41. begin
  42. if PColumn > 0 then
  43. begin
  44. Dec(PColumn);
  45. StringGrid1.Cells[PColumn+1, PRow] := '0';
  46. StringGrid1.Cells[PColumn, PRow] := 'P';
  47. end;
  48. end;
  49.  
  50. // pressing the "down" button
  51. procedure TForm2.Button3Click(Sender: TObject);
  52. begin
  53. if PRow < (StringGrid1.RowCount-1) then
  54. begin
  55. Inc(PRow);
  56. StringGrid1.Cells[PColumn, PRow-1] := '0';
  57. StringGrid1.Cells[PColumn, PRow ] := 'P';
  58. end;
  59. end;
  60.  
  61. // pressing the "right" button
  62. procedure TForm2.Button4Click(Sender: TObject);
  63. begin
  64. if PColumn < (StringGrid1.ColCount-1) then
  65. begin
  66. Inc(PColumn);
  67. StringGrid1.Cells[PColumn-1, PRow] := '0';
  68. StringGrid1.Cells[PColumn, PRow] := 'P';
  69. end;
  70. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement