# 2048

 ``` 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158``` ```program p2014; uses graphABC; var n,s,mon:integer; var r:array[,] of string; procedure move(ch:string);begin; var i1,i2:integer; for var g:=0 to n do begin //ДЕЛАЕММНОЖЕСТВОПЕРЕМЕЩЕНИЙЧТОБЗБСПРЯМ for var i:=0 to n-1 do begin for var j:=0 to n-1 do begin if ch='left' then begin if i<>0 then begin if r[i,j]<>'empty' then begin if r[i,j]=r[i-1,j] then begin i1:=strtoint(r[i,j]); i2:=strtoint(r[i-1,j]); r[i-1,j]:=inttostr(i1+i2); r[i,j]:='empty'; mon:=mon+(i1+i2); end; end; if r[i-1,j]='empty' then begin r[i-1,j]:=r[i,j]; r[i,j]:='empty'; end; end; end; if ch='right' then begin if i<>n-1 then begin if r[i,j]<>'empty' then begin if r[i,j]=r[i+1,j] then begin i1:=strtoint(r[i,j]); i2:=strtoint(r[i+1,j]); r[i+1,j]:=inttostr(i1+i2); r[i,j]:='empty'; mon:=mon+(i1+i2); end; end; if r[i+1,j]='empty' then begin r[i+1,j]:=r[i,j]; r[i,j]:='empty'; end; end; end; if ch='up' then begin if j<>0 then begin if r[i,j]<>'empty' then begin if r[i,j]=r[i,j-1] then begin i1:=strtoint(r[i,j]); i2:=strtoint(r[i,j-1]); r[i,j-1]:=inttostr(i1+i2); r[i,j]:='empty'; mon:=mon+(i1+i2); end; end; if r[i,j-1]='empty' then begin r[i,j-1]:=r[i,j]; r[i,j]:='empty'; end; end; end; if ch='down' then begin if j<>n-1 then begin if r[i,j]<>'empty' then begin if r[i,j]=r[i,j+1] then begin i1:=strtoint(r[i,j]); i2:=strtoint(r[i,j+1]); r[i,j+1]:=inttostr(i1+i2); r[i,j]:='empty'; mon:=mon+(i1+i2); end; end; if r[i,j+1]='empty' then begin r[i,j+1]:=r[i,j]; r[i,j]:='empty'; end; end; end; end; end; end; s:=0; repeat i1:=random(n); i2:=random(n); if r[i1,i2]='empty' then begin s:=1; r[i1,i2]:='2'; end; until s=1; end; procedure KeyDown(Key: integer); begin case Key of VK_Left: move('left'); VK_Right: move('right'); VK_Up: move('up'); VK_Down: move('down'); end; end; procedure drawing;begin; LockDrawing; Window.Title:=inttostr(mon); setpencolor(clblack); sleep(30);window.Clear; for var i:=0 to n-1 do begin for var j:=0 to n-1 do begin drawrectangle((i*100),(j*100),(i*100)+100,(j*100)+100); if r[i,j]<>'empty' then begin setbrushcolor(rgb(round(strtoint(r[i,j])*5.5),120,round(strtoint(r[i,j])*10.5))); rectangle((i*100),(j*100),(i*100)+100,(j*100)+100); textout(i*100+50,j*100+50,r[i,j]); end; end; end; Redraw; end; begin n:=4;mon:=0; r:=new string[n,n]; for var i:=0 to n-1 do begin for var j:=0 to n-1 do begin r[i,j]:='empty'; if random(10)=5 then begin if s<>1 then begin s:=1; r[i,j]:='2'; end; end; end; end; if s<>1 then r[random(n),random(n)]:='2'; while 0=0 do begin drawing; OnKeyDown := KeyDown; end; end. ```