unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Menus;
type
TForm1 =
class( TForm )
Timer1 : TTimer;
Shape1 : TShape;
Shape2 : TShape;
Shape3 : TShape;
Timer2 : TTimer;
court : TShape;
MainMenu1 : TMainMenu;
File1 : TMenuItem;
NewGame1 : TMenuItem;
Player1name1 : TMenuItem;
Player2name1 : TMenuItem;
HighScores1 : TMenuItem;
Game1 : TMenuItem;
Start1 : TMenuItem;
Stop1 : TMenuItem;
Pause1 : TMenuItem;
Exit1 : TMenuItem;
Shape4 : TShape;
Label1 : TLabel;
Label2 : TLabel;
Label3 : TLabel;
Label4 : TLabel;
Details1 : TMenuItem;
Author1 : TMenuItem;
Howtoplay1 : TMenuItem;
Shape5 : TShape;
procedure Timer1Timer( Sender : TObject );
procedure Timer2Timer( Sender : TObject );
procedure FormKeyDown( Sender : TObject;
var Key : Word; Shift : TShiftState );
procedure FormKeyPress( Sender : TObject;
var Key : Char );
procedure Start1Click( Sender : TObject );
procedure Stop1Click( Sender : TObject );
procedure Exit1Click( Sender : TObject );
procedure Player1name1Click( Sender : TObject );
procedure Player2name1Click( Sender : TObject );
procedure Pause1Click( Sender : TObject );
procedure NewGame1Click( Sender : TObject );
procedure HighScores1Click( Sender : TObject );
procedure Author1Click( Sender : TObject );
procedure FormCreate( Sender : TObject );
procedure Howtoplay1Click( Sender : TObject );
private
{ Private declarations }
public
horiz : integer;
horiz2 : integer;
direction : integer;
vert : integer;
player1 : integer;
player2 : integer;
end;
var
Form1 : TForm1;
implementation
uses
Unit2, Unit3, Unit4, Unit5, Unit6;
{$R *.dfm}
procedure TForm1.Timer1Timer( Sender : TObject );
begin
if ( player2 = 5 )
then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
messagedlg( '
Player 2 has won', mtinformation, [mbok], 0 ); player1 := 0; player2 := 0;
end;
Timer1.Interval := 10;
Timer2.Interval := 20;
Timer2.Enabled := false;
Shape3.Left := Shape3.Left - horiz;
Shape3.top := Shape3.top + vert;
if ( Shape3.Left < Shape1.Left )
then
begin
player2 := player2 + 1;
Timer1.Enabled := false;
messagedlg( '
Player 2 has scored' + chr( 13 ) + '
Click to continue', mtinformation, [mbok], 0 );
Shape3.Left := 240;
Shape3.top := 144;
Shape1.top := 152;
Shape2.top := 152;
horiz := 4;
vert := 0;
Timer1.Enabled := true;
end;
if ( Shape3.top >= Shape1.top )
and ( Shape3.top <= ( Shape1.top + Shape1.Height ) )
and ( vert = 0 )
then
vert := 2;
if ( Shape3.top <= court.top )
then
vert := +2;
if ( ( Shape3.top + Shape3.Height ) = 497 )
then
vert := -2;
if ( ( Shape3.Left <= Shape1.Left + Shape1.width )
and ( Shape3.top >= Shape1.top - 10 )
and ( Shape3.top <= Shape1.top + Shape1.Height ) )
then
direction := 5;
if direction = 1
then
Timer1.Enabled := false;
Timer2.Enabled := true;
end;
procedure TForm1.Timer2Timer( Sender : TObject );
begin
if ( player1 = 15 )
then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
messagedlg( '
Player 1 has won', mtinformation, [mbok], 0 ); player1 := 0; player2 := 0;
end;
Timer1.Interval := 20;
Timer2.Interval := 10;
Shape3.Left := Shape3.Left + horiz2;
Shape3.top := Shape3.top + vert;
Timer1.Enabled := false;
if ( Shape3.Left > Shape2.Left )
then
begin
player1 := player1 + 1;
Timer2.Enabled := false;
messagedlg( '
Player 1 has scored' + chr( 13 ) + '
Click to continue', mtinformation, [mbok], 0 );
Shape3.Left := 240;
Shape3.top := 144;
Shape1.top := 152;
Shape2.top := 152;
horiz := 4;
vert := 0;
Timer2.Enabled := true;
end;
if ( Shape3.top >= Shape1.top )
and ( Shape3.top <= ( Shape1.top + Shape1.Height ) )
and ( vert = 0 )
then
vert := -2;
if ( Shape3.top <= court.top )
then
vert := +2;
if ( ( Shape3.top + Shape3.Height ) = 497 )
then
vert := -2;
if ( ( Shape3.Left + Shape3.width >= Shape2.Left )
and ( Shape3.top >= Shape2.top - 10 )
and ( Shape3.top <= Shape2.top + Shape2.Height ) )
then
direction := 2;
if direction = 2
then
Timer2.Enabled := false;
Timer1.Enabled := true;
end;
procedure TForm1.FormKeyDown( Sender : TObject;
var Key : Word; Shift : TShiftState );
begin
if Key = vk_up
then
Shape1.top := Shape1.top - 15
else if Key = vk_down
then
Shape1.top := Shape1.top + 15;
if Key = vk_left
then
Shape1.Left := Shape1.Left - 15
else if Key = vk_right
then
Shape1.Left := Shape1.Left + 15;
end;
procedure TForm1.FormKeyPress( Sender : TObject;
var Key : Char );
begin
if Key = '
s'
then
Shape2.top := Shape2.top - 15
else if Key = '
x'
then
Shape2.top := Shape2.top + 15;
if Key = '
a'
then
Shape2.Left := Shape2.Left - 15
else if Key = '
d'
then
Shape2.Left := Shape2.Left + 15;
end;
procedure TForm1.Start1Click( Sender : TObject );
begin
with Form1
do
horiz := 4;
horiz2 := 4;
vert := -2;
Timer1.Enabled := true;
Timer2.Enabled := false;
end;
procedure TForm1.Stop1Click( Sender : TObject );
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
player1 := 0;
player2 := 0;
end;
procedure TForm1.Exit1Click( Sender : TObject );
begin
Form1.Close;
end;
procedure TForm1.Player1name1Click( Sender : TObject );
begin
form2.visible := true;
end;
procedure TForm1.Player2name1Click( Sender : TObject );
begin
form3.visible := true;
end;
procedure TForm1.Pause1Click( Sender : TObject );
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
end;
procedure TForm1.NewGame1Click( Sender : TObject );
begin
player1 := 0;
player2 := 0;
Shape3.Left := 216;
Shape3.top := 120;
messagedlg( '
Get ready to play', mtinformation, [mbok], 0 );
Timer1Timer( self );
end;
procedure TForm1.HighScores1Click( Sender : TObject );
begin
form4.visible := true;
end;
procedure TForm1.Author1Click( Sender : TObject );
begin
form5.visible := true;
end;
procedure TForm1.FormCreate( Sender : TObject );
begin
messagedlg( '
Get redy to play Martins Ping Pong Verion 1.0', mtinformation, [mbok], 0 );
messagedlg( '
Remember it is first to 5 wins', mtinformation, [mbok], 0 );
end;
procedure TForm1.Howtoplay1Click( Sender : TObject );
begin
form6.visible := true;
end;
end.