unit CazaSubmarino;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, MMSystem;
type
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Shape1: TShape;
Shape2: TShape;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
private
public
end;
var
Form1: TForm1;
RatonX, RatonY: Integer; RatonX2, RatonY2: Integer; Animacion, detectado: Boolean;
Contador: Integer; Columna1: Integer; Fila1: Integer; LugarPulsado, Submarino: Integer;
implementation
{$R *.lfm}
Procedure ColocaSubmarino();
Begin
Randomize; Submarino := Random(100) + 1; End;
Procedure MoverSubmarino(); Var
Moviendo: Integer;
Begin
Form1.Label2.Caption := '¡El Submarino se mueve!';
Form1.Label2.Visible := True;
Moviendo := Random(10); Case Submarino of
1, 10, 91, 100: Begin Case Submarino of
1: Begin Case Moviendo of
0, 1, 3:
Submarino := Submarino + 1; 4, 5, 6:
Submarino := Submarino + 10; 2, 7, 8:
Submarino := Submarino + 11; end;
end;
10: Begin Case Moviendo of
0, 1, 3:
Submarino := Submarino - 1; 4, 5, 6:
Submarino := Submarino + 10; 2, 7, 8:
Submarino := Submarino + 9; end;
end;
91: Begin Case Moviendo of
0, 1, 3:
Submarino := Submarino + 1; 4, 5, 6:
Submarino := Submarino - 10; 2, 7, 8:
Submarino := Submarino - 9; end;
end;
100: Begin Case Moviendo of
0, 1, 3:
Submarino := Submarino - 1; 4, 5, 6:
Submarino := Submarino - 10; 7, 8:
Submarino := Submarino - 11; end;
end;
End;
End; 2, 3, 4, 5, 6, 7, 8, 9: Begin
Case Moviendo of
0, 1:
Submarino := Submarino - 1; 2, 3:
Submarino := Submarino + 1; 4:
Submarino := Submarino + 9; 5, 8:
Submarino := Submarino + 11; 6, 7:
Submarino := Submarino + 10; end;
End;
92, 93, 94, 95, 96, 97, 98, 99: Begin Case Moviendo of
0, 1:
Submarino := Submarino - 1; 2, 3:
Submarino := Submarino + 1; 4:
Submarino := Submarino - 11; 5, 8:
Submarino := Submarino - 9; 6, 7:
Submarino := Submarino - 10; end;
End;
11, 21, 31, 41, 51, 61, 71, 81: Begin Case Moviendo of
0, 1:
Submarino := Submarino + 1; 2, 3:
Submarino := Submarino - 10; 4:
Submarino := Submarino - 9; 5, 8:
Submarino := Submarino + 11; 6, 7:
Submarino := Submarino + 10; end;
End;
20, 30, 40, 50, 60, 70, 80, 90: Begin Case Moviendo of
0, 1:
Submarino := Submarino - 1; 2, 3:
Submarino := Submarino - 10; 4:
Submarino := Submarino - 11; 5, 8:
Submarino := Submarino + 9; 6, 7:
Submarino := Submarino + 10; end;
End;
Else Begin
Case Moviendo of
0:
Submarino := Submarino - 11;
1:
Submarino := Submarino - 10;
2:
Submarino := Submarino - 9;
3:
Submarino := Submarino - 1;
4:
Submarino := Submarino + 1;
5:
Submarino := Submarino + 9;
6:
Submarino := Submarino + 10;
7, 8:
Submarino := Submarino + 11;
end;
End;
end;
End;
Procedure Ubicacion(); Begin
detectado := False;
Case RatonX Of 0 .. 29: Begin
RatonX2 := 0;
Columna1 := 1;
Form1.Shape2.Width := 60;
Form1.Shape2.Left := 0;
End;
30 .. 58: Begin
RatonX2 := 30;
Columna1 := 2;
Form1.Shape2.Width := 90; Form1.Shape2.Left := 0; End;
59 .. 87: Begin
RatonX2 := 59;
Columna1 := 3;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 30;
End;
88 .. 116: Begin
RatonX2 := 88;
Columna1 := 4;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 59;
End;
117 .. 145: Begin
RatonX2 := 117;
Columna1 := 5;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 88;
End;
146 .. 174: Begin
RatonX2 := 146;
Columna1 := 6;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 117;
End;
175 .. 203: Begin
RatonX2 := 175;
Columna1 := 7;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 146;
End;
204 .. 232: Begin
RatonX2 := 204;
Columna1 := 8;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 175;
End;
233 .. 261: Begin
RatonX2 := 233;
Columna1 := 9;
Form1.Shape2.Width := 90;
Form1.Shape2.Left := 204;
End;
262 .. 289: Begin
RatonX2 := 262;
Columna1 := 10;
Form1.Shape2.Width := 60;
Form1.Shape2.Left := 233;
End;
End;
Case RatonY Of 0 .. 29: Begin RatonY2 := 0; Fila1 := 0; Form1.Shape2.Height := 60; Form1.Shape2.Top := 0; End;
30 .. 58: Begin
RatonY2 := 30;
Fila1 := 1;
Form1.Shape2.Height := 90; Form1.Shape2.Top := 0; End;
59 .. 87: Begin
RatonY2 := 59;
Fila1 := 2;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 30;
End;
88 .. 116: Begin
RatonY2 := 88;
Fila1 := 3;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 59;
End;
117 .. 145: Begin
RatonY2 := 117;
Fila1 := 4;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 88;
End;
146 .. 174: Begin
RatonY2 := 146;
Fila1 := 5;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 117;
End;
175 .. 203: Begin
RatonY2 := 175;
Fila1 := 6;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 146;
End;
204 .. 232: Begin
RatonY2 := 204;
Fila1 := 7;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 175;
End;
233 .. 261: Begin
RatonY2 := 233;
Fila1 := 8;
Form1.Shape2.Height := 90;
Form1.Shape2.Top := 204;
End;
262 .. 289: Begin
RatonY2 := 262;
Fila1 := 9;
Form1.Shape2.Height := 60;
Form1.Shape2.Top := 233;
End;
End;
LugarPulsado := Fila1 * 10 + Columna1; Case LugarPulsado of
1: Begin Case Submarino of
1, 2, 11, 12E tectado := True;
End;
End;
10:
Begin
Case Submarino of
9, 10, 19, 20E tectado := True;
End;
End;
91:
Begin
Case Submarino of
81, 82, 91, 92E tectado := True;
End;
End;
100:
Begin
Case Submarino of
89, 90, 99, 100E tectado := True;
End;
End;
2, 3, 4, 5, 6, 7, 8, 9:
Begin if LugarPulsado - 1 = Submarino then
detectado := True;
if LugarPulsado = Submarino then
detectado := True;
if LugarPulsado + 1 = Submarino then
detectado := True;
if LugarPulsado + 9 = Submarino then
detectado := True;
if LugarPulsado + 10 = Submarino then
detectado := True;
if LugarPulsado + 11 = Submarino then
detectado := True;
End;
92, 93, 94, 95, 96, 97, 98, 99: Begin
if (LugarPulsado - 11) = Submarino then
detectado := True;
if (LugarPulsado - 10) = Submarino then
detectado := True;
if LugarPulsado - 9 = Submarino then
detectado := True;
if LugarPulsado - 1 = Submarino then
detectado := True;
if LugarPulsado = Submarino then
detectado := True;
if LugarPulsado + 1 = Submarino then
detectado := True;
End;
11, 21, 31, 41, 51, 61, 71, 81: Begin
if (LugarPulsado - 10) = Submarino then
detectado := True;
if LugarPulsado - 9 = Submarino then
detectado := True;
if LugarPulsado = Submarino then
detectado := True;
if LugarPulsado + 1 = Submarino then
detectado := True;
if LugarPulsado + 10 = Submarino then
detectado := True;
if LugarPulsado + 11 = Submarino then
detectado := True;
end;
20, 30, 40, 50, 60, 70, 80, 90: Begin
if (LugarPulsado - 11) = Submarino then
detectado := True;
if (LugarPulsado - 10) = Submarino then
detectado := True;
if LugarPulsado - 9 = Submarino then
detectado := True;
if LugarPulsado - 1 = Submarino then
detectado := True;
if LugarPulsado = Submarino then
detectado := True;
if LugarPulsado + 1 = Submarino then
detectado := True;
End;
Else Begin
if (LugarPulsado - 11) = Submarino then
detectado := True;
if (LugarPulsado - 10) = Submarino then
detectado := True;
if LugarPulsado - 9 = Submarino then
detectado := True;
if LugarPulsado - 1 = Submarino then
detectado := True;
if LugarPulsado = Submarino then
detectado := True;
if LugarPulsado + 1 = Submarino then
detectado := True;
if LugarPulsado + 9 = Submarino then
detectado := True;
if LugarPulsado + 10 = Submarino then
detectado := True;
if LugarPulsado + 11 = Submarino then
detectado := True;
End;
End;
End;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Image2.Visible := True;
Form1.Image1.Visible := False; Form1.Timer1.interval := 5;
ColocaSubmarino;
Form1.Label1.Caption := 'El submarino no se mueve';
Form1.CheckBox1.Checked := False;
Form1.Button1.Caption := 'Iniciar Juego';
Form1.Label2.Visible := False;
Form1.Shape1.Brush.Style := bsClear;
end;
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
Var
Localtexto1, Localtexto2: string;
begin
Shape2.Visible := False;
RatonX := X;
RatonY := Y;
if (Button = mbLeft) then begin
Contador := 0;
Ubicacion;
Shape2.Brush.Color := clLime;
If detectado = True then Begin
Shape2.Visible := True;
Label1.Caption := 'Submarino detectado ';
End
Else
Label1.Caption := 'Sin detección ';
Animacion := True;
PlaySound('Sonar.wav', 0, SND_ASYNC);
If Form1.CheckBox1.Checked = True Then
MoverSubmarino
Else
Form1.Label2.Visible := False;
end
Else Begin Ubicacion;
PlaySound('Bexpl.wav', 0, SND_ASYNC);
Shape2.Height := 30; Shape2.Width := 30; Shape2.Brush.Color := clRed;
Shape2.Top := RatonY2;
Shape2.Left := RatonX2;
Shape2.Visible := True;
If LugarPulsado = Submarino Then Begin
Form1.Label1.Caption := 'Submarino destruido';
ShowMessage('Haz destruido al submarino');
Form1.Button1.Caption := '¿Otro juego?';
Form1.Label1.Caption := ' ';
Form1.Image2.Visible := True;
Form1.Shape2.Visible := False;
Form1.Image1.Visible := False;
Form1.Button1.Visible := True;
End
Else
Form1.Label1.Caption := 'Disparo fallido';
If Form1.CheckBox1.Checked = True Then
MoverSubmarino
Else
Form1.Label2.Visible := False;
End;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If Animacion = True Then Begin
if Contador < 12 Then Begin
Shape1.Left := RatonX2; Shape1.Top := RatonY2;
Shape1.Visible := True;
Shape1.Height := Shape1.Height + 6;
Shape1.Width := Shape1.Width + 6;
RatonX2 := RatonX2 - 3;
RatonY2 := RatonY2 - 3;
Contador := Contador + 1;
End
Else Begin
Animacion := False;
Contador := 0;
Shape1.Visible := False;
Shape2.Visible := False;
Shape1.Height := 30;
Shape1.Width := 30;
End;
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ColocaSubmarino;
Form1.Shape1.Visible := False;
Form1.Button1.Visible := False;
Form1.Shape2.Visible := False;
Form1.Image2.Visible := False;
Form1.Image1.Visible := True; end;
end.