program snake; uses crt; var isPaused,newGame: boolean; opGO,op,dir,newD: char; cx,cy,tamc,pt,pt2,nv,nv2,perdeu: integer; {cx,cx = posição da comida; tamc = tamanho da cobra; pt = pontos; pt2 = contador p/ mudar de nv; nv = nivel; nv2 velocidade} x,y: array[1..14] of integer;{posição das partes da cobra} procedure pause; var op,opt,p: char; begin p:='0'; sound(1000); delay(200); nosound; while (p='0') do begin textbackground(1);textcolor(7); gotoxy(30,10); write('É[Pausa]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); gotoxy(30,11); write('º º'); gotoxy(30,12); write('º [C] - Continuar º'); gotoxy(30,13); write('º [N] - Novo jogo º'); gotoxy(30,14); write('º [S] - Sair º'); gotoxy(30,15); write('º º'); gotoxy(30,16); write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); op:=upcase(readkey); if(op='C') then begin isPaused:=false; p:='1'; end; if(op='N') then begin clrscr; writeln('Tem certeza que deseja iniciar um novo jogo? ([S]Sim / [N]Nao)'); opt:=upcase(readkey); if(opt = 'S') then begin clrscr; randomize; cx:=random(80); cy:=random(25); tamc:=3; if (cy=1) then begin cy:=2; end; perdeu:=0; dir:='D'; newD:='D'; x[1]:=4; y[1]:=2; pt:=0; pt2:=0; nv2:=80; nv:=1; x[2]:=3; x[3]:=2; x[4]:=1; y[2]:=2; y[3]:=2; y[4]:=2; textbackground(green); gotoxy(1,1); write(' '); gotoxy(2,1); write('Pontos: ',pt); gotoxy(25,1); write('Nivel: ',nv); isPaused:=false; newGame := true; p:='1'; end; if(opt = 'N') then begin isPaused:=false; p:='1'; end; end; if (op='S') then begin opGO:='N'; p:='1'; perdeu:=1; end; end; end; procedure tamanho; begin if (tamc>2) then begin gotoxy(x[2],y[2]); write('O'); gotoxy(x[3],y[3]); write('O'); gotoxy(x[4],y[4]); write('O'); end; if (tamc>4) then begin gotoxy(x[5],y[5]); write('O'); end; if (tamc>5) then begin gotoxy(x[6],y[6]); write('O'); end; if (tamc>6) then begin gotoxy(x[7],y[7]); write('O'); end; if (tamc>7) then begin gotoxy(x[8],y[8]); write('O'); end; if (tamc>8) then begin gotoxy(x[9],y[9]); write('O'); end; if (tamc>9) then begin gotoxy(x[10],y[10]); write('O'); end; if (tamc>10) then begin gotoxy(x[11],y[11]); write('O'); end; if (tamc>11) then begin gotoxy(x[12],y[12]); write('O'); end; if (tamc>12) then begin gotoxy(x[13],y[13]); write('O'); end; if (tamc>13) then begin gotoxy(x[14],y[14]); write('O'); end; end; procedure mov; begin if (tamc=12) then begin x[14]:=x[13]; y[14]:=y[13]; end; if (tamc>12) then begin x[13]:=x[12]; y[13]:=y[12]; end; if (tamc>11) then begin x[12]:=x[11]; y[12]:=y[11]; end; if (tamc>10) then begin x[11]:=x[10]; y[11]:=y[10]; end; if (tamc>9) then begin x[10]:=x[9]; y[10]:=y[9]; end; if (tamc>8) then begin x[9]:=x[8]; y[9]:=y[8]; end; if (tamc>7) then begin x[8]:=x[7]; y[8]:=y[7]; end; if (tamc>6) then begin x[7]:=x[6]; y[7]:=y[6]; end; if (tamc>5) then begin x[6]:=x[5]; y[6]:=y[5]; end; if (tamc>4) then begin x[5]:=x[4]; y[5]:=y[4]; end; end; procedure inicio; begin clrscr; randomize; cx:=random(80); cy:=random(25); tamc:=3; if (cy=1) then begin cy:=2; end; perdeu:=0; dir:='D'; newD:='D'; x[1]:=4; y[1]:=2; pt:=0; pt2:=0; nv2:=80; nv:=1; x[2]:=3; x[3]:=2; x[4]:=1; y[2]:=2; y[3]:=2; y[4]:=2; textbackground(green); tamanho; gotoxy(1,1); write(' '); gotoxy(2,1); write('Pontos: ',pt); gotoxy(25,1); write('Nivel: ',nv); while perdeu<>1 do begin clrscr; textbackground(0); textcolor(7); gotoxy(1,1); write(' '); gotoxy(2,1); write('Pontos: ',pt); gotoxy(25,1); write('Nivel: ',nv); textbackground(green); tamanho; gotoxy(x[1],y[1]); write('@'); gotoxy(cx,cy); write('$'); mov; x[4]:=x[3]; x[3]:=x[2]; x[2]:=x[1]; y[4]:=y[3]; y[3]:=y[2]; y[2]:=y[1]; if (x[1]=cx)and(y[1]=cy) then begin randomize; cx:=random(80); cy:=random(25); if (cy=1) then begin cy:=2; end; sound(1000); delay(100); nosound; pt:=pt+10; pt2:=pt2+1; tamc:=tamc+1; textbackground(0); gotoxy(1,1); write(' '); gotoxy(2,1); write('Pontos: ',pt); gotoxy(25,1); write('Nivel: ',nv); textbackground(green); end; if keypressed then begin newD:=upcase(readkey); { label continue;} if (newD='W') and (dir<>'S') then {esta entrando aki mesmo se adir=s(aconte o mesmo nos outros)} begin dir:='W'; end; if (newD='S') and (dir<>'W') then begin dir:='S'; end; if (newD='A') and (dir<>'D') then begin dir:='A'; end; if (newD='D') and (dir<>'A') then begin dir:='D'; end; if (newD='#80') then begin newD:=dir; end; if (newD='P') and (isPaused = false) then begin isPaused:=true; end; if (newD<>'W')and(newD<>'S')and(newD<>'A')and(newD<>'D')and(newD<>'P') then begin newD:=dir; end; end; if (dir='W') then begin y[1]:=(y[1])-1; end; if (dir='S') then begin y[1]:=(y[1])+1; end; if (dir='A') then begin x[1]:=(x[1])-1; end; if (dir='D') then begin x[1]:=(x[1])+1; end; if (isPaused = true) then begin newD:=dir; pause; end; if (newD<>'W')and(newD<>'S')and(newD<>'A')and(newD<>'D')and(newD<>'P') then newD:=dir; if ((y[1])>25)or((x[1])>80)or((y[1])=1)or((x[1])=0) then {gameover} begin opGo:='S'; newGame:=false; perdeu:=1; end; {Mudando de nivel} if (pt2=10) then begin textcolor(yellow);textbackground(0); clrscr; x[1]:=4; y[1]:=2; dir:='D'; newD:='D'; x[2]:=3; x[3]:=2; x[4]:=1; y[2]:=2; y[3]:=2; y[4]:=2; nv2:=nv2-10; nv:=nv+1; tamc:=3; pt2:=0; gotoxy(35,12); write('Nivel ',nv); delay(3000); end; newD:=dir; delay(nv2); end; end; begin opGO:='S'; clrscr; inicio; while opGO='S' do begin if(not(newGame)) then begin clrscr; writeln('GAME OVER'); writeln('Deseja jogar novamente? ([S]Sim / [N]Nao)'); op:=upcase(readkey); case (op) of 'S': begin clrscr; inicio; end; 'N': break; end; end else begin opGO:='N'; inicio; end; end; end.