home *** CD-ROM | disk | FTP | other *** search
- Program Defense;
-
- {
- Program : DEFENSE
- Written by : John R. Naleszkiewicz
- Date : August 21, 1985
- }
-
- Const
- Version = 1.2;
- Xmin = 2;
- Xmax = 74;
- Ymin = 1;
- Ymax = 23;
- NumStars = 8;
-
- Type
- StarType = RECORD
- X,Y : integer;
- END;
-
- Var
- won, lost : boolean;
- ShotDown : boolean;
- continue : boolean;
- x,y,i : integer;
- NewX, NewY : integer;
- Rate : integer;
- down : integer;
- Eshots : integer;
- Tshots : integer;
- shots : integer;
- ship : string[5];
- blowup : array[1..6] of string[9];
- Ym,Yp : array[13..Ymax] of integer;
- Star : array[1..NumStars] of StarType;
- ch,ESC : char;
-
- Function GetChar : char;
- Var
- ch : char;
-
- Begin
- read ( ch ); { for use with Facilis }
- {
- read ( KBD, ch ); { for use with TurboPascal }
- GetChar := ch;
- End;
-
- Procedure DrawShip ( NewX, NewY : integer );
- Begin
- GotoXY ( x, y );
- write (' ');
- x := NewX;
- y := NewY;
- if ( x>Xmax ) OR ( x<Xmin ) OR ( y>Ymax ) OR ( y<Ymin ) then
- lost := true
- else
- Begin
- GotoXY ( x, y );
- write ( ship )
- End;
- TextColor ( 3 );
- GotoXY ( 40, 12 );
- write ( '+' );
- TextColor ( 14 );
- End;
-
- Procedure ShiftStars( Xinc, Yinc : integer );
- Var
- num,j : integer;
-
- Begin
- for num:=1 to NumStars do
- Begin
- GotoXY ( Star[num].X, Star[num].Y );
- write ( ' ' );
- Star[num].X := Star[num].X + Xinc;
- Star[num].Y := Star[num].Y + Yinc;
- if (Star[num].X < Xmin) then
- Star[num].X := Xmax
- else
- if (Star[num].X > Xmax) then
- Star[num].X := Xmin;
- if (Star[num].Y < Ymin) then
- Star[num].Y := Ymax
- else
- if (Star[num].Y > Ymax) then
- Star[num].Y := Ymin;
- TextColor ( 15 );
- GotoXY ( Star[num].X, Star[num].Y );
- write ( '∙' );
- TextColor ( 14 );
- GotoXY ( 40, 12 );
- End;
- End;
-
- Procedure Action ( Rate : integer );
- Var
- ch : char;
- i,j : integer;
-
- Begin
- Repeat
- if keypressed then
- Begin
- TextColor ( 3 );
- GotoXY ( 40, 12 );
- ch := GetChar;
- GotoXY ( 40, 12 );
- if (ch=ESC) AND keypressed then
- Begin
- ch := GetChar;
- GotoXY ( 40, 12 );
- write ( '+' );
- TextColor ( 14 );
- if (ch='H') OR (ch='P') OR (ch='K') OR (ch='M') OR (ch='R') then
- case ch of
- 'H' : Begin
- ShiftStars ( 0, 1 );
- DrawShip ( x, y+1 ); { Up arrow }
- Rate := Rate-50;
- End;
- 'P' : Begin
- ShiftStars ( 0, -1 );
- DrawShip ( x, y-1 ); { Down arrow }
- Rate := Rate-50;
- End;
- 'K' : Begin
- ShiftStars ( 1, 0 );
- DrawShip ( x+1, y ); { Left arrow }
- Rate := Rate-50;
- End;
- 'M' : Begin
- ShiftStars ( -1, 0 );
- DrawShip ( x-1, y ); { Right arrow }
- Rate := Rate-50;
- End;
- 'R' : Begin { Insert key }
- shots := shots + 1;
- Rate := Rate-50;
- TextColor ( 12 );
- for i:=Ymax downto 13 do
- Begin
- GotoXY ( Ym[i], i );
- write ( '/' );
- GotoXY ( Yp[i], i );
- write ( '\' );
- End;
- GotoXY ( 40, 12 );
- write ( '^' );
- delay ( 100 );
- TextColor ( 14 );
- for i:=Ymax downto 13 do
- Begin
- GotoXY ( Ym[i], i );
- write ( ' ' );
- GotoXY ( Yp[i], i );
- write ( ' ' );
- End;
- GotoXY ( 40, 12 );
- write ( ' ' );
- if (y=12) AND ( (x>35) AND (x<41) ) then
- Begin
- for i:=1 to 10 do
- Begin
- if odd( i ) then
- TextColor ( 12 )
- else
- TextColor ( 14 );
- delay ( 50 );
- GotoXY ( x, y );
- write ( ship );
- End;
- x := x-2;
- for i:=1 to 6 do
- for j:=1 to 6 do
- Begin
- if odd ( j ) then
- TextColor ( 12 )
- else
- TextColor ( 14 );
- delay ( 5 );
- GotoXY ( x, y );
- write ( blowup[i] );
- End;
- GotoXY ( x, y );
- write ( ' ' );
- Delay ( 1000 );
- TextColor ( 14 );
- won := true;
- End;
- End; { Case of ' ' }
- End; { Case }
- End { if ESC AND keypressed }
- else
- Begin
- GotoXY ( 40, 12 );
- write ( '+' );
- TextColor ( 14 );
- End;
- End; { if keypressed }
- Rate := Rate-1;
- Until Rate<1;
- End;
-
- Function NotNeg ( Value : integer ) : integer;
- Begin
- if Value > 0 then
- NotNeg := Value
- else
- NotNeg := 0;
- End;
-
- Function Fire ( Rate : integer ) : boolean;
- Var
- delta : real;
- i : integer;
-
- Begin
- if random < 0.05 then
- Begin
- Eshots := Eshots + 1;
- delta := NotNeg(7 - abs( 38-x )) * NotNeg(7 - (2 * abs( 12-y ))) / 100.0;
- if random < delta then
- Fire := true
- else
- Fire := false;
- TextColor ( 13 );
- for i:= y+1 to Ymax do
- Begin
- GotoXY ( x+2, i );
- write ( '│' );
- End;
- Delay ( 200 );
- TextColor ( 14 );
- for i:= y+1 to Ymax do
- Begin
- GotoXY ( x+2, i );
- write ( ' ' );
- End;
- End
- else
- Fire := false;
- End;
-
- Procedure StartUp;
- Begin
- x := Xmin;
- y := Ymin;
- shots := 0;
- Eshots := 0;
- won := false;
- NewX := trunc ( random * (Xmax-10) + Xmin + 5 );
- NewY := trunc ( random * (Ymax-6) + Ymin + 3 );
- ClrScr;
- ShiftStars ( 0, 0 ); { Draw the stars }
- DrawShip ( NewX, NewY );
- End;
-
- BEGIN
- ESC := chr(27);
- ship := '├─o─┤';
- blowup[1] := ' ╞═o═╡';
- blowup[2] := ' ╠═O═╣';
- blowup[3] := ' ╠ ═O═ ╣';
- blowup[4] := '├ ═ O ═ ┤';
- blowup[5] := ': - ░ - :';
- blowup[6] := ' · ';
-
- for i:=13 to Ymax do
- Begin
- Yp[i] := 40-12+i;
- Ym[i] := 40+12-i;
- End;
-
- for i:=1 to NumStars do
- Begin
- Star[i].X := trunc ( random * Xmax + 1 );
- Star[i].Y := trunc ( random * Ymax + 1 );
- End;
-
- ClrScr;
- GotoXY ( 1, 10 );
- writeln ( 'DEFENSE Version ', version: 3:1 );
- writeln;
- writeln ( 'Use the cursor control keys to move' );
- writeln ( 'the aiming target in the center of' );
- writeln ( 'screen. Use the Ins key to fire.' );
- writeln;
- writeln ( 'Strike any key when ready...' );
- ch := GetChar;
- continue := true;
- while continue do
- Begin
- down := 0;
- Tshots := 0;
- lost := false;
- ShotDown := false;
- Randomize;
- Rate := 500;
- StartUp;
- while NOT lost do
- Begin
- Action ( Rate );
- if won then
- Begin
- ClrScr;
- GotoXY ( 1, 5 );
- down := down + 1;
- Tshots := Tshots + shots;
- writeln ( ' Enemy Shot Down : ', down:4 );
- writeln ( 'Shots Enemy Fired : ', Eshots:4 );
- writeln;
- writeln ( ' Shots Fired : ', shots:4 );
- writeln ( 'Total Shots Fired : ',Tshots:4 );
- writeln ( ' Hit Percentage : ', down/Tshots*100 : 4:0 );
- writeln;
-
- Rate := trunc ( Rate * ((shots/10.0) + 0.55) );
- if Rate < 1 then
- Rate := 1;
- writeln ( ' New Rating : ', 1000-Rate:4 );
- for i:= 10 downto 1 do
- Begin
- GotoXY ( 1, 20 );
- write ( i:2, ' Seconds to next encounter...' );
- delay ( 1000 );
- End;
- Startup;
- End;
- DrawShip ( x+trunc( random * 4.0 - 2.0), y+trunc(random * 4.0 - 2.0) );
- ShotDown := Fire ( Rate );
- if ShotDown then
- lost := true;
- End;
- ClrScr;
- GotoXY ( 1, 12 );
- if ShotDown then
- Begin
- writeln ( 'He must have gotten a lucky shot, ''cause he got' );
- writeln ( 'your ship dead center and blew it to pieces...' );
- End
- else
- Begin
- writeln ( 'The enemy was able to get around your defenses' );
- writeln ( 'and destroy you from behind...');
- End;
- writeln;
- writeln ( 'Better luck next time.' );
- writeln;
- writeln ( 'Final Rating : ',1000-Rate:4 );
- writeln;
- writeln ( 'Would you like to try again? (Y/N)' );
- if UpCase ( GetChar )<>'Y' then
- continue := false;
- End
- END.
-