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;
[B]
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;[/B]
[B]
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;[/B]
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.