Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
10/06/07 9:18
The Lizard King
Allora raga, ho bisogno di un aiuto: sto creando il gioco di Snake in Pascal, e sono arrivato ad un buon punto! :D
Per ora il programma è suddiviso in 12 sottoprogrammi:
4 (spostamenti) dedicati alla direzione del serpente, e 12 (nodi) dedicati allo spostamento del serpente da destra a giù o sù, e da sinistra a giù o sù, e viceversa! :D
Attualmente il serpente si può spostare ovunque nello schermo, anche se per il momento se il serpente tocca i bordi della finestra, il programma va in titl, cosa che correggerò in futuro. La cosa più difficile dei movimenti del serpente, è quella di far cambiare direzione mentre sta già cambiando un'altra direzione (scusate il gioco di parole :asd: ).

Questo è il codice, spero che c'è qualcuno quì che sa darmi una mano:

program snake;
uses crt;
var v:array[1..80,2..20] of char;
x,y,long,i,j:byte;
s:char;
 (*-----------------------------------------------------*)
procedure destragiu;  (*Nodo da destra a gi—*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x-long+i,y);
    v[x-long+i,y]:=' ';
    write(v[x-long+i,y]);
    gotoxy(x,y+i);
    v[x,y+i]:='Û';
    write(v[x,y+i])
   until i=long;
  y:=y+i
 end;
 (*-----------------------------------------------------*)
procedure destrasu;   (*Nodo da destra a s—*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x-long+i,y);
    v[x-long+i,y]:=' ';
    write(v[x-long+i,y]);
    gotoxy(x,y-i);
    v[x,y-i]:='Û';
    write(v[x,y-i])
   until i=long;
  y:=y-i
 end;
 (*-----------------------------------------------------*)
procedure destra;    (*Spostamento a destra*)
 begin
  repeat
   delay(100);
   gotoxy(x-long+1,y);
   v[x-long+1,y]:=' ';
   write(v[x-long+1,y]);
   x:=x+1;
   gotoxy(x,y);
   v[x,y]:='Û';
   write(v[x,y]);
   if keypressed then
    repeat
     s:=readkey
    until (s=#80) or (s<>#80)
  until (s=#80) or (s=#72) or (s='1')
 end;
 (*-----------------------------------------------------*)
procedure sinistra;  (*Spostamento a sinistra*)
 begin
  repeat
   delay(100);
   gotoxy(x+long-1,y);
   v[x+long-1,y]:=' ';
   write(v[x+long-1,y]);
   x:=x-1;
   gotoxy(x,y);
   v[x,y]:='Û';
   write(v[x,y]);
   if keypressed then
   repeat
    s:=readkey
   until (s=#80) or (s<>#80)
  until (s=#80) or (s=#72) or (s='1')
 end;
 (*-----------------------------------------------------*)
procedure sinistragiu; (*Nodo da sinistra a gi—*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x+long-i,y);
    v[x+long-i,y]:=' ';
    write(v[x+long-1,y]);
    gotoxy(x,y+i);
    v[x,y+i]:='Û';
    write(v[x,y+i])
   until i=long;
  y:=y+i
 end;
 (*-----------------------------------------------------*)
procedure sinistrasu; (*Nodo da sinistra a s—*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x+long-i,y);
    v[x+long-i,y]:=' ';
    write(v[x+long-1,y]);
    gotoxy(x,y-i);
    v[x,y-i]:='Û';
    write(v[x,y-i])
   until i=long;
  y:=y-i
 end;
 (*-----------------------------------------------------*)
procedure su;         (*Spostamento verso s—*)
 begin
  repeat
   delay(200);
   gotoxy(x,y+long-1);
   v[x,y+long-1]:=' ';
   write(v[x,y+long-1]);
   y:=y-1;
   gotoxy(x,y);
   v[x,y]:='Û';
   write(v[x,y]);
   if keypressed then
   repeat
    s:=readkey
   until (s=#77) or (s<>#77)
  until (s=#77) or (s=#75) or (s='1')
 end;
 (*-----------------------------------------------------*)
procedure giu;        (*Spostamento verso gi—*)
 begin
  repeat
   delay(200);
   gotoxy(x,y-long+1);
   v[x,y-long+1]:=' ';
   write(v[x,y-long+1]);
   y:=y+1;
   gotoxy(x,y);
   v[x,y]:='Û';
   write(v[x,y]);
   if keypressed then
   repeat
    s:=readkey
   until (s=#77) or (s<>#77)
  until (s=#77) or (s=#75) or (s='1')
 end;
 (*-----------------------------------------------------*)
procedure sudestra;   (*Nodo da s— a destra*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x,y+long-i);
    v[x,y+long-i]:=' ';
    write(v[x,y+long-1]);
    gotoxy(x+i,y);
    v[x+i,y]:='Û';
    write(v[x+i,y])
   until i=long;
  x:=x+i
 end;
 (*-----------------------------------------------------*)
procedure susinistra;  (*Nodo da s— a sinistra*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x,y+long-i);
    v[x,y+long-i]:=' ';
    write(v[x,y+long-1]);
    gotoxy(x-i,y);
    v[x-i,y]:='Û';
    write(v[x-i,y])
   until i=long;
  x:=x-i
 end;
 (*-----------------------------------------------------*)
procedure giudestra;   (*Nodo da gi— a destra*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x,y-long+i);
    v[x,y-long+i]:=' ';
    write(v[x,y-long+1]);
    gotoxy(x+i,y);
    v[x+i,y]:='Û';
    write(v[x+i,y])
   until i=long;
  x:=x+i
 end;
 (*-----------------------------------------------------*)
procedure giusinistra;  (*Nodo da gi— a sinistra*)
 begin
  i:=0;
   repeat
    i:=i+1;
    delay(200);
    gotoxy(x,y-long+i);
    v[x,y-long+i]:=' ';
    write(v[x,y-long+1]);
    gotoxy(x-i,y);
    v[x-i,y]:='Û';
    write(v[x-i,y])
   until i=long;
  x:=x-i
 end;
 (*-----------------------------------------------------*)
begin (***************INIZIO DEL PROGRAMMA****************)
 clrscr;
 for i:=1 to 80 do
  for j:=2 to 20 do      (*Inizializzazione del serpente*)
   v[i,j]:=' ';          (*e attributi*)
 long:=6;
 x:=long+10;y:=15;
 for i:=x-long+1 to long do v[i,y]:='Û';
 for i:=x-long+1 to long do
  begin
   gotoxy(i,y);
   write(v[i,y])
  end;
 (*-----------------------------------------------------*)
 repeat
  destra;
  if s=#72 then       (*Movimenti del serpente*)
     begin
      destrasu;
      su;
      if s=#77 then sudestra
      else
      if s=#75 then
         begin
          susinistra;
          repeat
          sinistra;
          if s=#72 then
             begin
              sinistrasu;
              su;
              if s=#75 then susinistra;
              if s=#77 then sudestra
             end
          else
          if s=#80 then
             begin
              sinistragiu;
              giu;
              if s=#75 then giusinistra;
              if s=#77 then giudestra
             end
          until (s=#77) or (s='1')
         end
     end
  else
  if s=#80 then
     begin
      destragiu;
      giu;
      if s=#77 then giudestra
      else
      if s=#75 then
         begin
          giusinistra;
          repeat
          sinistra;
          if s=#72 then
             begin
              sinistrasu;
              su;
              if s=#75 then susinistra;
              if s=#77 then sudestra
             end
          else
          if s=#80 then
             begin
              sinistragiu;
              giu;
              if s=#75 then giusinistra;
              if s=#77 then giudestra
             end
          until (s=#77) or (s='1')
         end
     end
 until s='1'
end.
aaa
03/07/07 14:47
Karl
.
Ultima modifica effettuata da Karl 03/07/07 14:49
aaa
03/07/07 14:47
Karl
Cerca Di Indentare Il Codice Sorgente Grazie Aiuterà di sicuro anche te hhe:k:
aaa
04/07/07 21:17
WARRIOR
Si, è buona norma creare una gerarchia nel codice, quindi renderlo piu chiaro ;) .
Cmq ognuno ha il suo stile :k:.
Ho visto che hai pubblicato il programma, quindi qui si puo chiudere.

Locked!
Luca :k:
aaa