home *** CD-ROM | disk | FTP | other *** search
- (****************************************************************************)
- (* TPONG-1.PAS Glenn A. Reiff 74035,400 4/5/85 *)
- (* *)
- (* Note: While this program is usable and will provide some fun, the *)
- (* Paddle control is not as responsive as it is in the original *)
- (* Basic program. Also, the side bounces could be better. If *)
- (* you are able to make any improvements I'd appreciate knowing *)
- (* about them. *)
- (****************************************************************************)
- type Str80 = string[80]; procedure CENTER(Y:integer; Bt:Str80); forward;
- procedure INTRODUCTION;
- BEGIN
- clrscr; CENTER(5,'TURBO PONG');
- CENTER(8,'This is an adaption to Turbo Pascal of the Basic program ');
- CENTER(9,'called PChallenge written by Karl Koessel and published in');
- CENTER(10,'a 1982 issue of PC Magazine. ');
- CENTER(12,'His was a simplification of Pong, the orignial video game.');
- CENTER(13,'Pong was developed in the early 1970''s by Nolan Bushnell. ');
- CENTER(20,'Tap a Key to Continue');
- writeln; gotoXY(80,25);
- repeat until keypressed;
- END; { INTRODUCTION }
-
-
- type CharSet = set of Char;
- Str9 = string[9];
-
- var Paddle : Str9;
- StartTime,EndTime,BestTime,Drag : integer;
- Ch : char;
-
-
- procedure CENTER;
- var Tab: integer;
- BEGIN Tab:=(80-Length(Bt)) div 2; gotoXY(Tab,Y); write(Bt); END;
-
- Procedure TEXTBORDER (color: integer);
- type result = record
- AL,AH,BL,BH,CL,CH,DL,DH: Byte;
- BP,SI,DI,DS,ES,Flags: Integer;
- end;
- var registers: result;
- BEGIN
- With registers do begin
- AH := 11; BH := 0; BL := color; Intr($10,registers); end;
- END; { TEXTBORDER }
-
- Procedure BEEP(N : Integer);
- BEGIN Sound(n); Delay(100); NoSound; END;
-
- function GET_TIME: integer;
- type register = Record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
- End;
- var allregs : register;
- BEGIN
- allregs.ax := $2C * 256;
- MsDos(allregs);
- GET_TIME := 3600 * (allregs.cx div 256) + 60 * (allregs.cx mod 256) + allregs.dx div 256;
- END; { GET_TIME }
-
- procedure CHOOSE( X,Y : integer;
- Prompt : Str80;
- Term : CharSet;
- var TC : Char );
- var I : integer;
- Ch : char;
- BEGIN
- lowvideo; gotoXY(X,Y);
- for I:=1 to length(Prompt) do begin
- Ch:=copy(Prompt,I,1);
- if I>4 then begin
- lowvideo;
- if (copy(Prompt,I-2,1)=' ') and (copy(Prompt,I-1,1)=' ') then highvideo;
- if (copy(Prompt,I-1,1)='<') or (copy(Prompt,I-1,1)='/') then highvideo;
- end; { if I>3 }
- write(Ch);
- end; { for I }
- repeat
- Read(Kbd,Ch);
- TC := Upcase(Ch);
- if not (TC in Term) then BEEP(1000);
- until TC in Term;
- END; { CHOOSE }
-
- procedure RESET(var Drag: integer; var Paddle: Str9);
- BEGIN
- TEXTBORDER(Black); textbackground(Black); clrscr;
- CENTER(10,'Left and right cursor keys move paddle.');
- textcolor(LightCyan);
- CENTER(12,'Input drag factor: (100 is Medium...0 is FAST!) '); read(Drag);
- CHOOSE(17,14,'Pick a paddle size: Small, Medium or Large ',['S','M','L'],Ch);
- if Ch = 'S' then Paddle := ' '+chr(27)+' '+chr(26)+' '
- else if Ch = 'M' then Paddle := ' '+chr(27)+' '+chr(26)+' '
- else if Ch = 'L' then Paddle := ' '+chr(27)+' '+chr(26)+' ';
- END; { RESET }
-
- procedure RUN;
- label NewBall;
- var Used : array[1..10] of integer;
- var X,dX,Xpad,Y,dY,B,C,I,J,BallNr,Xstart : integer;
- Flag : boolean;
-
- procedure RANDOMIZE;
- BEGIN
- dX := random(7) - random(7);
- if dX < 0 then begin
- repeat
- dX := random(7) - random(7);
- if dX=0 then dX:=-1;
- until X-6/dX=trunc(X-6/dX)
- end; { if dX }
- if dX > 0 then begin
- repeat
- dX := random(7) - random(7);
- if dX=0 then dX:=1;
- until 59-X/dX=trunc(59-X/dX)
- end; { if dX }
- END; { RANDOMIZE }
-
- procedure POSITION_PADDLE;
- BEGIN
- gotoXY(Xpad,22); textbackground(LightGray);
- textcolor(DarkGray); write(Paddle); textbackground(C);
- END; { POSITION_PADDLE }
-
- procedure ONKEY;
- BEGIN
- read(kbd,Ch);
- if (Ch = #27) and keypressed then { it must be a function key }
- read(kbd,Ch);
- case Ch of
- 'K': if Xpad > 7 then begin
- Xpad:=Xpad-3; POSITION_PADDLE;
- gotoXY(Xpad+length(Paddle),22); write(' '); end;
- 'M': if Xpad + length(Paddle) < 60 then begin
- Xpad:=Xpad+2; POSITION_PADDLE;
- gotoXY(Xpad-3,22); write(' '); end;
- end; { case }
- END; { ONKEY }
-
-
- BEGIN
- J := 11; Xpad := 29; C := random(16);
- if (C=0) or (C=1) or (C=6) or (C=7) or (C=8) or (C=9) or (C=12) or (C=15) then C := 2;
- textbackground(C); clrscr; TEXTBORDER(C);
-
- for X:=8 to 17 do begin { Setup 10 Balls }
- J := J + 4; textbackground(red); textcolor(white);
- gotoXY(J,2); write(chr(2)); textbackground(C);
- end; { for X }
- textcolor(Blue);
- for X:=5 to 59 do begin gotoXY(X,3); write(chr(219)); end; { Draw Backboard }
- for Y:=3 to 21 do begin { Draw Walls }
- gotoXY(5,Y); write(chr(219),chr(219)); gotoXY(59,Y); write(chr(219),chr(219));
- end;
- POSITION_PADDLE; textcolor(Black);
- gotoXY(5,24);write('Best Time so far is ',BestTime,' seconds.');
- gotoXY(66,3);write('TURBOPONG');gotoXY(66,8);
- gotoXY(63,6);write('Initial Drag ',Drag);
- for I:=1 to 10 do Used[I]:=0;
- BallNr := 10;
- StartTime := GET_TIME;
-
- while BallNr > 0 do begin
- NewBall: Xstart := 1 + random(10); Flag:=false;
- for I:=1 to 10 do if Used[I] = Xstart then Flag:=true;
- if Flag then goto NewBall;
- Used[BallNr]:=Xstart;
- Xstart := 11 + 4 * Xstart;
- gotoXY(Xstart,2); write(' ');
- X := Xstart; Y := 4; dY := 1; Flag := false;
- RANDOMIZE;
- while Y < 23 do begin
- if keypressed then ONKEY;
- textbackground(C);
- if (Y > 4) and (X>6) and (X<59) then { Erase Previous Ball Below }
- begin gotoXY(X,Y-1); write(' '); end;
- if (Y<21) and (X>6) and (X<59)then
- begin gotoXY(X,Y+1); write(' '); end; { Erase Previous Ball Above }
- if (Y=21) and (X>=Xpad) and (X<=Xpad+length(Paddle)) then
- begin gotoXY(X,Y); write(' '); end; { Erase Ball On Paddle }
-
- X:=X + dX;
-
- textbackground(red); textcolor(white);
- gotoXY(X,Y);
- if (X>6) and (X<59) then write(chr(1)); { Print New Ball Position }
- gotoXY(80,25);
- if (X <= 7) or (X >=58) then begin
- BEEP(300+random(80*BallNr)); dX:=-dX; end; { Side Wall Bounce }
- if keypressed then ONKEY;
-
- if (Y=21) and (X>=Xpad) and (X<=Xpad+length(Paddle)) then
- begin
- dY := -dY; BEEP(700); { Bounce Off Of Paddle }
- if dX = 0 then RANDOMIZE;
- end; { if Y=21 }
-
- if Y = 22 then begin
- textbackground(C); gotoXY(X,Y); write(' ');
- textbackground(red); textcolor(white); { Park Used Ball }
- gotoXY(25+Xstart,Y+2); write(chr(1)); gotoXY(80,25);
- end;
- if keypressed then ONKEY;
- if (Y = 4) and (Flag) then begin { Bounce Off of Top Backboard }
- BEEP(300+random(80*BallNr)); Drag := Drag - 5; { Reduce Amout of Drag }
- if dX = 0 then RANDOMIZE; dX := dX + 1;
- dY := -dY; Y := Y + dY; end
- else begin Y := Y + dY; Flag := true;
- end; { if Y }
- if Drag <0 then Drag := 0;
- delay(50+Drag);
- end; { while Y }
- BallNr := BallNr - 1; textbackground(C);
- end; { while BallNr }
- gotoXY(1,22); clreol;
- textcolor(Black); gotoXY(63,8); if Drag < 0 then Drag := 0;
- write('Final Drag ',Drag);
- EndTime := GET_TIME;
- if EndTime - StartTime > BestTime then BestTime := EndTime - StartTime;
- gotoXY(5,24);write('Best Time so far is ',BestTime,' seconds.');
- gotoXY(63,11); write('This Run ',EndTime-StartTime, ' sec.');
- END; { RUN }
-
- {MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM}
- BEGIN
- BestTime := 0; Drag := 0; Paddle := '';
- INTRODUCTION;
- RESET(Drag,Paddle);
- repeat
- RUN;
- CHOOSE(19,22,' Quit Reset Continue ',['Q','R','C'],Ch);
- if Ch = 'R' then RESET(Drag,Paddle);
- until Ch = 'Q';
- TEXTBORDER(Black); textbackground(Black); clrscr;
- END.