SHOW:
|
|
- or go back to the newest paste.
| 1 | program naval; | |
| 2 | uses crt; | |
| 3 | const | |
| 4 | - | fil=20; |
| 4 | + | fil=20; |
| 5 | - | col=15; |
| 5 | + | col=15; |
| 6 | - | type |
| 6 | + | type |
| 7 | - | batallaNaval = array [1..fil, 1..col] of boolean; |
| 7 | + | batallaNaval = array [1..fil, 1..col] of boolean; |
| 8 | - | |
| 8 | + | |
| 9 | var | |
| 10 | - | va: batallaNaval; |
| 10 | + | va: batallaNaval; |
| 11 | - | a,d,c,e,f : integer; |
| 11 | + | a,d,c,e,f : integer; |
| 12 | - | procedure indicarDisparo (var re,ra :integer; var prom : integer); |
| 12 | + | procedure indicarDisparo (var re,ra :integer; var prom : integer); |
| 13 | - | var |
| 13 | + | var |
| 14 | - | cont,disp,aux : integer; |
| 14 | + | cont,disp,aux : integer; |
| 15 | - | resp : char; |
| 15 | + | resp : char; |
| 16 | - | begin |
| 16 | + | begin |
| 17 | - | cont:=0; |
| 17 | + | cont:=0; |
| 18 | - | disp:=0; |
| 18 | + | disp:=0; |
| 19 | - | repeat |
| 19 | + | repeat |
| 20 | - | writeln ('Ingrese las coordenas donde va a efectuar el disparo');
|
| 20 | + | repeat |
| 21 | - | readln (re,ra); |
| 21 | + | writeln ('Ingrese las coordenas donde va a efectuar el disparo');
|
| 22 | - | while (re<0) and (ra<0) and (re>col) and (ra>fil) do |
| 22 | + | readln (re,ra); |
| 23 | - | begin |
| 23 | + | until (re>0) and (ra>0) and (re<fil) and (ra<col); |
| 24 | - | readln (re,ra); |
| 24 | + | disp:=disp+1; |
| 25 | - | writeln ('Los puntos indicados no son correctos');
|
| 25 | + | if va[ra,re] = true |
| 26 | - | end; |
| 26 | + | then |
| 27 | - | disp:=disp+1; |
| 27 | + | begin |
| 28 | - | if va[ra,re] = true |
| 28 | + | writeln ('Bien le diste a un barco');
|
| 29 | - | then |
| 29 | + | cont:=cont+1 |
| 30 | - | begin |
| 30 | + | end |
| 31 | - | writeln ('Bien le diste a un barco');
|
| 31 | + | else |
| 32 | - | cont:=cont+1 |
| 32 | + | begin |
| 33 | - | end |
| 33 | + | writeln ('Fallaste le diste al agua :D');
|
| 34 | - | else |
| 34 | + | end; |
| 35 | - | begin |
| 35 | + | writeln ('Cantidad de disparos efectuados ',disp);
|
| 36 | - | writeln ('Fallaste le diste al agua :D');
|
| 36 | + | writeln ('¿Desea efectuar otro disparo? s/n');
|
| 37 | - | end; |
| 37 | + | readln (resp); |
| 38 | - | writeln ('Cantidad de disparos efectuados ',disp);
|
| 38 | + | until (resp='n') or (disp=20); |
| 39 | - | writeln ('¿Desea efectuar otro disparo? s/n');
|
| 39 | + | aux:=(cont*100); |
| 40 | - | readln (resp); |
| 40 | + | prom:=(aux div disp); |
| 41 | - | until (resp='n') or (disp=20); |
| 41 | + | writeln ('Su promedio de disparos es %', prom);
|
| 42 | - | aux:=(cont*100); |
| 42 | + | end; |
| 43 | - | prom:=(aux div disp); |
| 43 | + | procedure barcos (var x,y : integer); |
| 44 | - | writeln ('Su promedio de disparos es %', prom);
|
| 44 | + | var |
| 45 | - | end; |
| 45 | + | z: char; |
| 46 | - | procedure barcos (var x,y : integer); |
| 46 | + | contador: integer; |
| 47 | - | var |
| 47 | + | begin |
| 48 | - | z: char; |
| 48 | + | contador:=0; |
| 49 | - | contador: integer; |
| 49 | + | repeat |
| 50 | - | begin |
| 50 | + | repeat |
| 51 | - | repeat |
| 51 | + | writeln ('Ingrese las coordenas donde se va a encontrar el barco');
|
| 52 | - | contador:=0; |
| 52 | + | readln (x,y); |
| 53 | - | writeln ('Ingrese las coordenas donde se va a encontrar el barco');
|
| 53 | + | until (x>0) and (y>0) and (x<fil) and (y<col); |
| 54 | - | readln (x,y); |
| 54 | + | contador:=contador+1; |
| 55 | - | while (x<0) and (y<0) and (x>col) and (y>fil) do |
| 55 | + | va [x,y]:= true; |
| 56 | - | begin |
| 56 | + | if contador<10 |
| 57 | - | readln (x,y); |
| 57 | + | then |
| 58 | - | writeln ('Los puntos indicados no son correctos');
|
| 58 | + | writeln ('¿Desea ingresar otro barco? s/n');
|
| 59 | - | end; |
| 59 | + | readln (z); |
| 60 | - | contador:=contador+1; |
| 60 | + | until (z='n') or (contador=10); |
| 61 | - | va [x,y]:= true; |
| 61 | + | end; |
| 62 | - | if contador<10 |
| 62 | + | procedure mostr (q,w : integer); |
| 63 | - | then |
| 63 | + | begin |
| 64 | - | writeln ('¿Desea ingresar otro barco? s/n');
|
| 64 | + | writeln('Los barcos se encontraban en estas coordenadas:');
|
| 65 | - | readln (z); |
| 65 | + | |
| 66 | - | until (z='n') or (contador=10); |
| 66 | + | |
| 67 | - | end; |
| 67 | + | begin |
| 68 | - | procedure mostr (q,w : integer); |
| 68 | + | w:= 1; |
| 69 | - | begin |
| 69 | + | repeat |
| 70 | - | writeln('Los barcos se encontraban en estas coordenadas:');
|
| 70 | + | if va[q,w]=true then |
| 71 | writeln(q,',', w); | |
| 72 | w:= w + 1; | |
| 73 | - | begin |
| 73 | + | until (w=Col); |
| 74 | - | w:= 1; |
| 74 | + | q:= q + 1; |
| 75 | - | repeat |
| 75 | + | end; |
| 76 | - | if va[q,w]=true then |
| 76 | + | end; |
| 77 | - | writeln(q,',', w); |
| 77 | + | |
| 78 | - | w:= w + 1; |
| 78 | + | clrscr; |
| 79 | - | until (w=Col); |
| 79 | + | textcolor (red+blue); |
| 80 | - | q:= q + 1; |
| 80 | + | barcos (c,e); |
| 81 | - | end; |
| 81 | + | clrscr; |
| 82 | - | end; |
| 82 | + | textcolor (blue); |
| 83 | indicarDisparo (a,d,f); | |
| 84 | - | clrscr; |
| 84 | + | textcolor (red+white); |
| 85 | - | textcolor (red+blue); |
| 85 | + | mostr (c,e); |
| 86 | - | barcos (c,e); |
| 86 | + | readkey; |
| 87 | - | clrscr; |
| 87 | + |