Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.12.2008, 21:50   #1
vmagdn
 
Регистрация: 14.12.2008
Сообщений: 3
По умолчанию ооп (игра)

как переделать игру в ООП?

unit UMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg;

type
TMainForm = class(TForm)
Car: TImage;
Block1: TImage;
Block2: TImage;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Bevel3: TBevel;
Timer1: TTimer;
Timer2: TTimer;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;
Bonus:integer;

implementation

{$R *.dfm}

procedure GameOver;
begin
MainForm.Timer1.Enabled:=false;
MainForm.Timer2.Enabled:=false;
ShowMessage('Аварія');
end;

procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//Управление машиной кнопками мышки
If (Button=mbLeft) and (Car.left>0) then
Car.left:=Car.left-(Car.width div 2);

If (Button=mbRight) and (Car.Left<(450-Car.Width)) then
Car.Left:=Car.Left+(Car.Width div 2);
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
close;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
//Располагаем препятсвия
Block1.Left:=128;
Block1.Top:=288;
Block2.Left:=320;
Block2.Top:=50;
Bonus:=0;
Label1.Caption:='0';
//Показываем препятствия
Block1.Show;
Block2.Show;
Car.Show;
//Включаем все таймеры;
Timer1.Enabled:=true;
Timer2.Enabled:=true;
end;

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
//Отображаем очки игрока
Label1.Caption:=IntToStr(Bonus);

//Задаем движение препятствия1
Block1.Top:=Block1.Top+(block1.heig ht div 2);

//Проверяем не произошла ли авария
if (Block1.Top+Block1.Height)>(Car.Top ) then
if (Block1.Left+1<=Car.Left) and (Car.Left<=(Block1.Left+Block1.Widt h-1))
then GameOver;

if (Block1.Top+Block1.Height)>(Car.Top ) then
if (Block1.Left+1<=(Car.Left+Car.Width )) and ((Car.Left+Car.Width)<=(Block1.Left +Block1.Width-1))
then GameOver;

//Дошло ли препятствие до нижней границы
If Block1.Top>=(MainForm.ClientHeight) then
begin
Bonus:=Bonus+10;
Block1.Hide;
Block1.Top:=1;

//препятствие не должно вылазить за левую границу
repeat
Block1.Left:=Random(450-Car.Width);
until (Block1.Left>10);
Block1.Show;
end;
end;

procedure TMainForm.Timer2Timer(Sender: TObject);
begin
//Отображаем очки игрока
Label1.Caption:=IntToStr(Bonus);

//Задаем движение препятствия1
Block2.Top:=Block2.Top+(Block2.Heig ht div 2);

//Проверяем не произошла ли авария
if (Block2.Top+Block2.Height)>(Car.Top ) then
if (Block2.Left+1<=Car.Left) and (Car.Left<=(Block2.Left+Block2.Widt h-1))
then GameOver;

if (Block2.Top+Block2.Height)>(Car.Top ) then
if (Block2.Left+1<=(Car.Left+Car.Width )) and ((Car.Left+Car.Width)<=(Block2.Left +Block2.Width-1))
then GameOver;

//Дошло ли препятствие до нижней границы
If Block2.Top>=(MainForm.ClientHeight) then
begin
Bonus:=Bonus+10;
Block2.Hide;
Block2.Top:=1;

//препятствие не должно вылазить за левую границу
repeat
Block2.Left:=Random(450-Car.Width);
until (Block2.Left>10);
Block2.Show;
end;
end;

end.
vmagdn вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
игра (ооп) vmagdn Компоненты Delphi 1 14.12.2008 23:01
задача по ООП Lenivec** Фриланс 2 17.07.2008 15:17
ООП Римма Общие вопросы Delphi 16 15.04.2008 11:32
ООП Andrey Gort Общие вопросы Delphi 1 22.11.2006 15:01