1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
program SPACE_INVADER;
{$PMTYPE VIO}
{$X+,Delphi+,Use32+}
uses Crt, VPSysLow, VPUtils;
(* LES TYPES ET OBJECTS *)
type TPoint = record
X,Y : Integer;
end;
type TDirection = (Droite, Gauche);
type TVaisseau = object
Body : String;
Point : TPoint;
constructor Init;
procedure Bouger(Direction : TDirection);
procedure Afficher;
procedure Effacer;
end;
type TMissile = object
Body : String;
Point : TPoint;
IsFire : Boolean;
Constructor Init;
procedure Deplacer;
procedure Afficher;
procedure Effacer;
end;
type PMissile = ^TMissile;
var
ThreadTirer : TSemHandle;
Vaisseau : TVaisseau;
Touche : Char;
Missile : PMissile;
constructor TMissile.init;
begin
Body := '|';
IsFire := False;
end;
procedure TMissile.Deplacer;
begin
Dec(Point.Y);
end;
procedure TMissile.Afficher;
begin
TextColor(Green);
GotoXY(Point.X,Point.Y);
Write(Body);
end;
procedure TMissile.Effacer;
begin
GotoXY(Point.X,Point.Y);
Write(' ');
end;
constructor TVaisseau.Init;
begin
Body := '/-^-\';
Point.X := 38;
Point.Y := 25;
end;
procedure TVaisseau.Bouger(Direction : TDirection);
begin
if (Direction=Droite) and (Point.X < 75) then
begin
Self.Effacer;
Inc(Point.X);
Self.Afficher;
end;
if (Direction=Gauche) and (Point.X > 1) then
begin
Self.Effacer;
Dec(Point.X);
Self.Afficher;
end;
end;
function Tirer(aPMissile : Pointer) : Longint;
begin
SemRequestMutex(ThreadTirer, 10);
while (Missile^.Point.Y > 1) do
begin
Missile^.Effacer;
Missile^.Deplacer;
Missile^.Afficher;
Delay(300);
end;
SemReleaseMutex(ThreadTirer);
SemCloseMutex(ThreadTirer);
Missile^.IsFire := false;
end;
procedure TVaisseau.Afficher;
begin
TextColor(Red);
GotoXY(Point.X,Point.Y);
Write(Body);
end;
procedure TVaisseau.Effacer;
begin
GotoXY(Point.X,Point.Y);
Write(' ');
end;
(* Programma principale *)
begin
HideCursor;
Vaisseau.Init;
Vaisseau.Afficher;
New(Missile,Init);
ThreadTirer := SemCreateMutex(nil, false, false);
while true do
begin
(*Events*)
while KeyPressed do Touche := ReadKey;
case Touche of
#77 : Vaisseau.Bouger(Droite);
#75 : Vaisseau.Bouger(Gauche);
#27 : Halt(0);
' ' : begin
if not Missile^.IsFire then
begin
Missile^.Point.X := Vaisseau.Point.X + 2;
Missile^.Point.Y := 24;
Missile.IsFire := True;
Missile^.IsFire := true;
VPBeginThread(Tirer, 1024*16, nil);
end;
end;
end;
Touche := #00;
end;
end. |
Partager