program sokoban; uses crt, graph, dos; var a,le,le1,i,j,xx,yy,x,y,x1,y1,sekundomer,pts: integer; x2,y2,n,m,G,H,k,k1,c,c1,c2,dalshe,kol: integer; t,t1,E,F,k2,b,bb: string; chas1,minuta1,sek1,sek101: word; u,p: array[1..17] of string[19]; key: array[1..4] of char; z: char; fail,fail1: text; label 1,2,3,4,5,6,7,8,9,10,11,12; Procedure kurout; BEGIN asm mov ah,1 mov ch,1 mov cl,0 int 10h end END; Procedure kurin; BEGIN asm mov ah,1 mov ch,6 mov cl,7 int 10h end END; procedure sokograf; var draiver, mood, viga: integer; begin draiver:=detect; Initgraph(draiver, mood, ''); viga:=GraphResult; if viga <> GrOK then begin writeln('Graafikaviga ',GraphErrorMsg(viga)); Halt(1); end; end; procedure sokobeg; begin textcolor(14); b:=' '; b:=b+'This programm was made by Vitali Alfjorov from TPU, Tallinn, Estonia. '; bb:=''; for c1:=1 to length(b)-77 do begin for c2:=c1 to c1+77 do bb:=bb+b[c2]; gotoxy(3,19); write(bb); bb:=''; delay(50); end; end; procedure sokoprev; begin clrscr; textcolor(1); gotoxy(13, 3); writeln(' ллл '); gotoxy(13, 4); writeln(' ллллл '); gotoxy(13, 5); writeln('ллллллл'); gotoxy(13, 6); writeln('лл лл'); gotoxy(13, 7); writeln('лл '); gotoxy(13, 8); writeln('лл '); gotoxy(13, 9); writeln(' ллл '); gotoxy(13,10); writeln(' ллл '); gotoxy(13,11); writeln(' лл'); gotoxy(13,12); writeln(' лл'); gotoxy(13,13); writeln('лл лл'); gotoxy(13,14); writeln('лл лл'); gotoxy(13,15); writeln('ллллллл'); gotoxy(13,16); writeln(' ллллл '); gotoxy(13,17); writeln(' ллл '); textcolor(2); gotoxy(21, 9); writeln(' ллл '); gotoxy(21,10); writeln(' ллллл '); gotoxy(21,11); writeln('ллллллл'); gotoxy(21,12); writeln('лл лл'); gotoxy(21,13); writeln('лл лл'); gotoxy(21,14); writeln('лл лл'); gotoxy(21,15); writeln('ллллллл'); gotoxy(21,16); writeln(' ллллл '); gotoxy(21,17); writeln(' ллл '); textcolor(3); gotoxy(29, 9); writeln('лл лл'); gotoxy(29,10); writeln('лл лл'); gotoxy(29,11); writeln('лл лл '); gotoxy(29,12); writeln('ллллл '); gotoxy(29,13); writeln('ллллл '); gotoxy(29,14); writeln('лл лл '); gotoxy(29,15); writeln('лл лл'); gotoxy(29,16); writeln('лл лл'); gotoxy(29,17); writeln('лл лл'); textcolor(4); gotoxy(37, 9); writeln(' ллл '); gotoxy(37,10); writeln(' ллллл '); gotoxy(37,11); writeln('ллллллл'); gotoxy(37,12); writeln('лл лл'); gotoxy(37,13); writeln('лл лл'); gotoxy(37,14); writeln('лл лл'); gotoxy(37,15); writeln('ллллллл'); gotoxy(37,16); writeln(' ллллл '); gotoxy(37,17); writeln(' ллл '); textcolor(5); gotoxy(45, 3); writeln('лл '); gotoxy(45, 4); writeln('лл '); gotoxy(45, 5); writeln('лл '); gotoxy(45, 6); writeln('лл '); gotoxy(45, 7); writeln('лл '); gotoxy(45, 8); writeln('лл '); gotoxy(45, 9); writeln('ллллл '); gotoxy(45,10); writeln('лллллл '); gotoxy(45,11); writeln('ллллллл'); gotoxy(45,12); writeln('лл лл'); gotoxy(45,13); writeln('лл лл'); gotoxy(45,14); writeln('лл лл'); gotoxy(45,15); writeln('ллллллл'); gotoxy(45,16); writeln('лллллл '); gotoxy(45,17); writeln('ллллл '); textcolor(6); gotoxy(53, 9); writeln(' ллллл'); gotoxy(53,10); writeln(' лллллл'); gotoxy(53,11); writeln('ллллллл'); gotoxy(53,12); writeln('лл лл'); gotoxy(53,13); writeln('лл лл'); gotoxy(53,14); writeln('лл лл'); gotoxy(53,15); writeln('ллллллл'); gotoxy(53,16); writeln('ллллллл'); gotoxy(53,17); writeln('ллллллл'); textcolor(7); gotoxy(61, 9); writeln('ллллл '); gotoxy(61,10); writeln('лллллл '); gotoxy(61,11); writeln('ллллллл'); gotoxy(61,12); writeln('лл лл'); gotoxy(61,13); writeln('лл лл'); gotoxy(61,14); writeln('лл лл'); gotoxy(61,15); writeln('лл лл'); gotoxy(61,16); writeln('лл лл'); gotoxy(61,17); writeln('лл лл'); sokobeg; gotoxy(28,23); textcolor(15+blink); write('Press any key to continue'); readkey; end; procedure sokoram; begin textcolor(8); for a:=2 to 79 do begin gotoxy(a,1); write('Э'); gotoxy(a,24); write('Э'); end; for a:=2 to 23 do begin gotoxy(1,a); write('К'); gotoxy(80,a); write('К'); end; gotoxy(1,1); write('Щ'); gotoxy(80,1); write('Л'); gotoxy(1,24); write('Ш'); gotoxy(80,24); write('М'); end; procedure sokomenu; begin clrscr; textcolor(8); for a:=2 to 79 do begin gotoxy(a,1); write('Э'); gotoxy(a,24); write('Э'); end; for a:=2 to 23 do begin gotoxy(1,a); write('К'); gotoxy(80,a); write('К'); end; gotoxy(1,1); write('Щ'); gotoxy(80,1); write('Л'); gotoxy(1,24); write('Ш'); gotoxy(80,24); write('М'); textcolor(4); for a:=32 to 46 do begin gotoxy(a,7); write('Ф'); gotoxy(a,14); write('Ф'); end; for a:=8 to 13 do begin gotoxy(31,a); write('Г'); gotoxy(47,a); write('Г'); end; gotoxy(31,7); write('к'); gotoxy(47,7); write('П'); gotoxy(31,14); write('Р'); gotoxy(47,14); write('й'); gotoxy(37,8); textcolor(10); writeln('MENU'); gotoxy(32,10); textcolor(14); write('C'); textcolor(2); writeln(' - Cursor keys'); gotoxy(32,11); textcolor(14); write('D'); textcolor(2); writeln(' - Define keys'); gotoxy(32,12); textcolor(14); write('S'); textcolor(2); writeln(' - Start game'); gotoxy(32,13); textcolor(14); write('Q'); textcolor(2); writeln(' - Quit game'); end; procedure curkeys; begin gotoxy(33,8); textcolor(10); writeln('CURSOR KEYS'); key[1]:='M'; gotoxy(34,10); textcolor(2); write('Right ':7); textcolor(14); writeln(chr(26)); key[2]:='K'; gotoxy(34,11); textcolor(2); write('Left ':7); textcolor(14); writeln(''); key[3]:='P'; gotoxy(34,12); textcolor(2); write('Down ':7); textcolor(14); writeln(''); key[4]:='H'; gotoxy(34,13); textcolor(2); write('Up ':7); textcolor(14); writeln(''); end; procedure defkeys; begin gotoxy(33,8); textcolor(10); writeln('DEFINE KEYS'); for k:=1 to 4 do begin if k=1 then begin gotoxy(34,10); textcolor(2); write('Right ':7); end; if k=2 then begin gotoxy(34,11); textcolor(2); write('Left ':7); end; if k=3 then begin gotoxy(34,12); textcolor(2); write('Down ':7); end; if k=4 then begin gotoxy(34,13); textcolor(2); write('Up ':7); end; key[k]:=readkey; textcolor(14); writeln(key[k]); end; delay(1000); end; procedure sokocool; var Color: word; begin clrscr; sokograf; Color:=15; Randomize; Rectangle(49,49,590,430); SetTextStyle(0, 0, 2); OutTextXY(125, 25, 'Congratulations, You WIN!'); repeat PutPixel(Random(540)+50, Random(380)+50, Color); { Plot "stars" } Delay(10); Color:=Random(15)+1; until KeyPressed; CloseGraph; textmode(lastmode); kurout; end; procedure sokomeco; var soko: string; so,sox,soy,soc: integer; label 15; begin randomize; soko:='OOOOOOO'; repeat 15:sox:=random(71)+2; soy:=random(22)+2; soc:=random(15)+1; if (soy>6) and (soy<15) then if (sox>23) and (sox<48) then goto 15; textcolor(soc); gotoxy(sox,soy); write(soko); textcolor(black); gotoxy(sox,soy); write(soko); until keypressed; end; procedure sokobaco; var soko1: string; so1,so1x,so1y,so1c,so1i: integer; chas1, minuta1, sek1, sek101: word; label 16; procedure sokoseku; var chas, minuta, sek, sek100: word; begin gettime(chas, minuta, sek, sek100); sekundomer:=sekundomer-(3600*(chas-chas1)+60*(minuta-minuta1)+sek-sek1); gotoxy(5,2); write('Time: ',sekundomer:3); end; begin soko1:='њ+*'; gettime(chas1, minuta1, sek1, sek101); 16:so1x:=random(77)+2; so1y:=random(20)+3; so1c:=random(15)+1; if (so1x>30) and (so1x<50) then goto 16; for so1i:=1 to 4 do begin textcolor(so1c); gotoxy(so1x,so1y); write(soko1[so1i]); delay(10); end; for so1i:=4 downto 1 do begin textcolor(so1c); gotoxy(so1x,so1y); write(soko1[so1i]); delay(10); end; gotoxy(so1x,so1y); write(' '); textcolor(red); sokoseku; end; procedure sokobest; var best: array[1..11] of integer; best1: array[1..11] of string; best2: array[1..10] of string; help, code: integer; name, help1: string; begin z:=readkey; textcolor(3); gotoxy(30,5); write('Your name: '); assign(fail1,'best.txt'); reset(fail1); for i:=1 to 10 do begin readln(fail1, best1[i]); readln(fail1, best2[i]); end; for i:=1 to 10 do val(best2[i], best[i], code); textcolor(9); kurin; readln(name); kurout; textcolor(3); gotoxy(28,6); write('You have ',' ',' points'); textcolor(1); gotoxy(37,6); write(pts); best[11]:=pts; best1[11]:=name; for i:=1 to 10 do for j:=i to 11 do if best[j]>best[i] then begin help:=best[i]; help1:=best1[i]; best[i]:=best[j]; best1[i]:=best1[j]; best[j]:=help; best1[j]:=help1; end; textcolor(4); gotoxy(34,8); write('Best results'); textcolor(11); reset(fail1); rewrite(fail1); for i:=1 to 10 do begin gotoxy(24,8+i); write(best1[i]); writeln(fail1, best1[i]); textcolor(1); gotoxy(35,8+i); write(best[i]:10); writeln(fail1, best[i]); textcolor(11); gotoxy(46,8+i); write(' points'); end; close(fail1); repeat delay(100); until keypressed; end; procedure gameover; var col: integer; size: word; begin clrscr; sokograf; for size:=1 to 5 do begin SetColor(white); SetTextStyle(DefaultFont, HorizDir, size); OutTextXY(150, 200, 'GAME OVER'); delay(750); SetColor(black); OutTextXY(150, 200, 'GAME OVER'); end; repeat col:=random(15)+1; SetColor(col); OutTextXY(150, 200, 'GAME OVER'); delay(100); until keypressed; CloseGraph; textmode(lastmode); kurout; end; begin kurout; sokoprev; assign(fail,'levels.txt'); c:=-1; 9:sokomenu; repeat sokomeco; z:=readkey; case z of 'c': begin c:=1; clrscr; sokoram; curkeys; delay(3000); goto 9; end; 'd': begin c:=0; clrscr; sokoram; defkeys; goto 9; end; 's': begin if c=-1 then begin c:=1; curkeys; end; goto 10; end; 'q': goto 1; else begin sound(1000); delay(50); nosound; end; end; until keypressed; 10:clrscr; reset(fail); le1:=0; while not Eof(fail) do begin readln(fail, t1); le1:=le1+1; end; reset(fail); le:=0; pts:=0; 8:clrscr; delay(1000); sokoram; sekundomer:=180; kol:=0; le:=le+1; if le>(le1/19) then begin sokocool; sokoram; sokobest; goto 9; end; gotoxy(34,1); textcolor(15) ; write(' Level: ',le:3,' '); gotoxy(10,23); textcolor(5+blink); write('Esc'); textcolor(7); write(' - return to menu'); gotoxy(35,23); textcolor(3); write('r'); textcolor(7); write(' - replay level'); gotoxy(56,23); textcolor(11); write('n'); textcolor(7); write(' - next level'); gotoxy(64,2); textcolor(blue); write('Points: ',pts:5); for i:=1 to 17 do begin readln(fail, u[i]); if u[i]=' ' then goto 2; for j:=1 to 19 do begin yy:=i+3; xx:=j+30; t:=u[i,j]; if t=' ' then p[i,j]:=' '; if t='В' then begin textcolor(6); p[i,j]:='В'; end; if t='ў' then begin textcolor(yellow); p[i,j]:=' '; kol:=kol+1; end; if t='њ' then begin textcolor(white); p[i,j]:='њ'; end; gotoxy(xx,yy); write(t); end; 2:end; readln(fail,X); readln(fail,Y); randomize; 5:gotoxy(x+30,y+3); textcolor(white); write(''); repeat if sekundomer=0 then begin gameover; sokoram; sokobest; goto 9; end; sokobaco; until keypressed; 12:if c=1 then begin z:=readkey; if (z=chr(0)) or (z='r') or (z='n') or (z=chr(27)) then goto 11 else goto 12; end; 11:z:=readkey; if z=key[1] then begin x1:=x+1; y1:=y; goto 3; end; if z=key[2] then begin x1:=x-1; y1:=y; goto 3; end; if z=key[3] then begin x1:=x; y1:=y+1; goto 3; end; if z=key[4] then begin x1:=x; y1:=y-1; goto 3; end; if z='r' then begin k1:=19*(le-1); reset(fail); for k:=1 to k1 do readln(fail,k2); le:=le-1; goto 8; end; if z='n' then begin if le=(le1/19) then goto 9; k1:=19*le; sekundomer:=180; reset(fail); for k:=1 to k1 do readln(fail,k2); goto 8; end; if z=chr(27) then goto 9; 3:if (u[y1,x1]<>' ') and (u[y1,x1]<>'њ') then goto 4; gotoxy(x+30,y+3); textcolor(white); write(p[y,x]); x:=x1; y:=y1; goto 5; 4:if u[y1,x1]='В' then goto 5; x2:=x1-x; y2:=y1-y; x2:=x1+x2; y2:=y1+y2; if (u[y2,x2]='В') or (u[y2,x2]='ў') then goto 5; gotoxy(x+30,y+3); textcolor(white); write(p[y,x]); x:=x1; y:=y1; u[y,x]:=p[y,x]; if p[y2,x2]='њ' then begin u[y2,x2]:='ў'; goto 6; end; u[y2,x2]:='ў'; if u[y2,x2]='ў' then begin gotoxy(x2+30,y2+3); textcolor(yellow); write('ў'); u[y,x]:=' '; goto 5; end; 6:if u[y2,x2]='ў' then begin gotoxy(x2+30,y2+3); textcolor(white); write('ў'); u[y,x]:=' '; end; gotoxy(x+30,y+3); textcolor(white); write(''); dalshe:=kol; for n:=1 to 17 do begin if u[n]=' ' then goto 7; for m:=1 to 19 do begin if (u[m,n]='ў') and (p[m,n]<>'њ') then dalshe:=dalshe-1; end; 7:end; if dalshe<>kol then goto 5; pts:=pts+sekundomer*kol; goto 8; close(fail); 1:delay(1000); kurin; textmode(lastmode); end.