All pastes #19457 Raw Edit

load/save 2d array

public text v1 · immutable
#19457 ·published 2005-08-06 20:24 UTC
rendered paste body
// My array made as a var
//------------------------------------------------------------------------------------------------ 
arr: array[0..9, 0..9] of integer = ((3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
(3, 2, 2, 2, 2, 2, 2, 2, 2, 3),
(3, 2, 6, 1, 1, 1, 1, 1, 2, 3),
(3, 2, 7, 1, 1, 1, 1, 5, 2, 3),
(3, 2, 7, 1, 0, 0, 1, 1, 2, 3),
(3, 2, 7, 1, 0, 0, 1, 1, 2, 3),
(3, 2, 7, 1, 4, 1, 1, 1, 2, 3),
(3, 2, 8, 9, 1, 1, 1, 1, 2, 3),
(3, 2, 2, 2, 2, 2, 2, 2, 2, 3),
(3, 3, 3, 3, 3, 3, 3, 3, 3, 3));
//------------------------------------------------------------------------------------------------ 

// Painting method
//------------------------------------------------------------------------------------------------ 
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
x: integer;
y: integer;
begin
for x := 0 to 9 do begin
  for y := 0 to 9 do begin
    case arr[x, y] of
      0: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
TreeImg.Canvas, Rect(0, 0, 29, 29));
      1: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
GrassImg.Canvas, Rect(0, 0, 29, 29));
      2: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
WaterImg.Canvas, Rect(0, 0, 29, 29));
      3: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
WaterImg.Canvas, Rect(0, 0, 29, 29));
      4: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image5.Canvas, Rect(0, 0, 29, 29));
      5: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image6.Canvas, Rect(0, 0, 29, 29));
      6: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image7.Canvas, Rect(0, 0, 29, 29));
     7: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image8.Canvas, Rect(0, 0, 29, 29));
    8: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image9.Canvas, Rect(0, 0, 29, 29));
    9: PaintBox1.Canvas.CopyRect(Rect(x*30, y*30, (x*30)+29, (y*30)+29),
image10.Canvas, Rect(0, 0, 29, 29));
    end;
  end;
end;
end;
//------------------------------------------------------------------------------------------------ 


// im trying to save/load the array to a text file.. 
//------------------------------------------------------------------------------------------------ 
procedure SaveToFile(FileName: String);
var
  F: File of Integer;
  I, J: Integer;
begin
  AssignFile(F, FileName);
  Rewrite(F);
  for I := 1 to 10 do
    for J := 1 to 10 do
      Write(F, arr[I, J]);
  CloseFile(F);
End;
//------------------------------------------------------------------------------------------------ 

// the dump in the text file with the method above
//------------------------------------------------------------------------------------------------ 
                                                                                                                                                                                              	                                                                                 dp@ „o@ ÌA Ìo@ Ìn@ ´p@ ôp@ \q@  «A 4E „p@
//------------------------------------------------------------------------------------------------ 

// this is how it supporsed to look
//------------------------------------------------------------------------------------------------ 
(3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
(3, 2, 2, 2, 2, 2, 2, 2, 2, 3),
(3, 2, 6, 1, 1, 1, 1, 1, 2, 3),
(3, 2, 7, 1, 1, 1, 1, 5, 2, 3),
(3, 2, 7, 1, 0, 0, 1, 1, 2, 3),
(3, 2, 7, 1, 0, 0, 1, 1, 2, 3),
(3, 2, 7, 1, 4, 1, 1, 1, 2, 3),
(3, 2, 8, 9, 1, 1, 1, 1, 2, 3),
(3, 2, 2, 2, 2, 2, 2, 2, 2, 3),
(3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
//------------------------------------------------------------------------------------------------