1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
| var Form1: TForm1; mousex: integer; mousey: integer; var i:integer = 0; aup, adown, aleft, aright: boolean; arr: array[0..14, 0..14] of integer = ( (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1), (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1), (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1), (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1), (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1), (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1), (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1), (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1), (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1), (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1), (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1), (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1), (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1), (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
;
implementation
{$R *.dfm}
procedure TForm1.PaintBox1Paint(Sender: TObject); var x: integer; y: integer; begin for x := 0 to 14 do begin for y := 0 to 14 do begin case arr[y, x] of 0: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20), food.Canvas, Rect(0, 0, 20, 20)); 1: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20), wall.Canvas, Rect(0, 0, 20, 20)); 2: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20), empty.Canvas, Rect(0, 0, 20, 20)); end; end; end; end;
procedure TForm1.FormCreate(Sender: TObject); var i,j:integer; begin doublebuffered:=true; pacman.left:=paintbox1.left+20; pacman.top:=paintbox1.Top+20; memo1.Lines.loadfromfile(extractfilepath(application.exename)+'level.ini'); end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin label1.caption:=inttostr(pacman.left); label2.caption:=inttostr(pacman.top); label3.Caption:=inttostr(arr[pacman.Left,pacman.top]); if timer1.enabled=true then key:=vk_space; case key of vk_down: begin timer1.enabled:=true; adown:=true; aup:=false; aleft:=false; aright:=false; end; vk_right: begin timer1.enabled:=true; adown:=false; aup:=false; aleft:=false; aright:=true; end; vk_left: begin timer1.enabled:=true; adown:=false; aup:=false; aleft:=true; aright:=false; end; vk_up: begin timer1.enabled:=true; adown:=false; aup:=true; aleft:=false; aright:=false; end; end; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin if adown then begin pacman.Top:=pacman.Top+2; i:=i+1; if i=10 then begin timer1.enabled:=false; i:=0; end; end;
if aright then begin pacman.left:=pacman.left+2; i:=i+1; if i=10 then begin timer1.enabled:=false; i:=0; end; end;
if aleft then begin pacman.left:=pacman.left-2; i:=i+1; if i=10 then begin timer1.enabled:=false; i:=0; end; end;
if aup then begin pacman.top:=pacman.top-2; i:=i+1; if i=10 then begin timer1.enabled:=false; i:=0; end; end;
end;
end. |