Игры на Делфи [Сергей Вячеславович Хвощев глобус] (pdf) читать постранично

-  Игры на Делфи   2.55 Мб, 480с. скачать: (pdf) - (pdf+fbd)  читать: (полностью) - (постранично) - Сергей Вячеславович Хвощев (глобус)

Книга в формате pdf! Изображения и текст могут не отображаться!


 [Настройки текста]  [Cбросить фильтры]

Создание игр
1. Стрелялка

Первая кнопка поворачивает наш кубик влево. Вторая двигает вперед. Третья назад.
Четвертая в право. Пятая стреляет шариком. Шестая возвращает видимость обоим
кубикам. Враг двигается и стреляет под управлением таймера. Можно включить поворот
врага на вас.
// влево
procedure TForm1.Button1Click(Sender: TObject);
begin
Cube2.RotationAngle.Y := Cube2.RotationAngle.Y - 1;
Caption:=Cube2.RotationAngle.Y.ToString;
if Cube2.RotationAngle.Y=90 then Cube2.RotationAngle.Y:=89;
end;
// выстрел
procedure TForm1.Button5Click(Sender: TObject);
begin
if Cube2.Visible = true then
begin
S := TSphere.Create(Viewport3D1);
S.Parent := Viewport3D1;
S.Position.X := Cube2.Position.X;
S.Position.Y := Cube2.Position.Y;
S.Position.Z := Cube2.Position.Z;
S.Width := 1;
S.Height := 1;
while (S.Position.Z < 100) do
begin
S.Position.Z := S.Position.Z + 1 *
sin(DegToRad(Cube2.RotationAngle.Y + 90));
S.Position.X := S.Position.X - 1 *
cos(DegToRad(Cube2.RotationAngle.Y + 90));
if (S.Position.X >= Cube1.Position.X) and
(S.Position.X + S.Width = Cube1.Position.Y) and
(S.Position.Y + S.Height = Cube1.Position.Z) and
(S.Position.Z + S.Depth -11) do
begin
S.Position.Z := S.Position.Z - 1 *
sin(DegToRad(Cube1.RotationAngle.Y + 90));
S.Position.X := S.Position.X + 1 *
cos(DegToRad(Cube1.RotationAngle.Y + 90));
if (S.Position.X >= Cube2.Position.X) and
(S.Position.X + S.Width = Cube2.Position.Y) and
(S.Position.Y + S.Height = Cube2.Position.Z) and
(S.Position.Z + S.Depth = Cube1.Position.X) and

(S.Position.X + S.Width = Cube1.Position.Y) and
(S.Position.Y + S.Height = Cube1.Position.Z) and
(S.Position.Z + S.Depth = Panel2.Height then
begin
lv := lv + 1;
if lv >= 4 then
begin
lv := 0;
Timer1.Interval := 1000;
end;
Label3.Text := 'Уровень ' + lv.ToString;
Timer1.Interval := round(Timer1.Interval / 2);
Image2.Position.Y := ToolBar1.Position.Y;
end;
end;
// влево
procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Position.X := Image1.Position.X - 50;
end;
// вправо
procedure TForm1.Button2Click(Sender: TObject);
begin
Image1.Position.X := Image1.Position.X + 50;
end;
// выстрел
procedure TForm1.Button3Click(Sender: TObject);
begin
if (Image1.Visible = true) and (Image2.Visible = true) then
begin
C := TCircle.Create(Panel2);
C.Parent := Panel2;
C.Position.X := Image1.Position.X + Image1.Width / 2;
C.Position.Y := Image1.Position.Y;
C.Width := 10;
C.Height := 10;
while (C.Position.Y >= 50) do
begin
C.Position.Y := C.Position.Y - 50;
if (C.Position.X >= Image2.Position.X) and
(C.Position.X = Image2.Position.Y) and
(C.Position.Y = 50) do
begin
C.Position.Y := C.Position.Y - 50;
if (C.Position.X >= Image2.Position.X) and
(C.Position.X = Image2.Position.Y) and
(C.Position.Y Image1.Position.X) and
(Ellipse2.Position.X < Image1.Position.X + Image1.Width) and
(Ellipse2.Position.Y > Image1.Position.Y) and
(Ellipse2.Position.Y < Image1.Position.Y + Image1.Height) then
begin
blue := blue + 1;
Label2.Text := IntToStr(blue);
end;
end;

// tanks move
procedure TForm2.Timer1Timer(Sender: TObject);
begin
try
Image1.Position.X := Image1.Position.X + s * cos(DegToRad(u - 90));
Image1.Position.Y := Image1.Position.Y + s * sin(DegToRad(u - 90));
// за рамки
if Image1.Position.X = Panel4.Width then
Image1.Position.X := Panel4.Width - Image1.Width;
if Image1.Position.Y = Panel4.Height then
Image1.Position.Y := Panel4.Height - Image1.Height;
//
IdTCPClient1.Socket.WriteLn(FloatToStrF(Image1.Position.X, ffFixed, 6, 1) +
' ' + FloatToStrF(Image1.Position.Y, ffFixed, 6, 1) + ';' +
FloatToStrF(Image1.RotationAngle, ffFixed, 5, 1));
except
Timer1.Enabled := false;
end;
end;
// topedoRed
procedure TForm2.Timer2Timer(Sender: TObject);
begin
Ellipse1.Position.X := Ellipse1.Position.X + v *
cos(DegToRad(Ellipse1.RotationAngle - 90));
Ellipse1.Position.Y := Ellipse1.Position.Y + v *
sin(DegToRad(Ellipse1.RotationAngle - 90));
// za ramki
if Ellipse1.Position.X < 0 then
Timer2.Enabled := false;
if Ellipse1.Position.X > Panel4.Height then
Timer2.Enabled := false;
if Ellipse1.Position.Y < 0 then
Timer2.Enabled := false;
if Ellipse1.Position.Y > Panel4.Height then
Timer2.Enabled := false;
if (Ellipse1.Position.X > Image2.Position.X) and
(Ellipse1.Position.X < Image2.Position.X + Image2.Width) and
(Ellipse1.Position.Y > Image2.Position.Y) and
(Ellipse1.Position.Y < Image2.Position.Y + Image1.Height) then
begin
red := red + 1;
Label1.Text := IntToStr(red);

end;
IdTCPClient2.Socket.WriteLn(FloatToStrF(Ellipse1.Position.X, ffFixed, 6, 1) +
' ' + FloatToStrF(Ellipse1.Position.Y, ffFixed, 6, 1) + ';' +
FloatToStrF(Ellipse1.RotationAngle, ffFixed, 5, 1));
end;
end.
7. Игра Шахматы локальная.

Для пк и телефона. Правильность ходов не контролируется. Для хода нужно
сначала щелкнуть на фигуру, а потом на свободную клетку. Для сруба нужно
сначала выбрать кого будет есть а потом нажать кнопку удалить и после этого
сделать фигурой, которая срубает.
var
Form1: TForm1;
n: integer;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
if n = 1 then

begin
Image1.Position.Y := -60;
Image1.Visible := false;
end;
if n = 2 then
begin
Image2.Position.Y := -60;
Image2.Visible := false;
end;
if n = 3 then
begin
Image3.Position.Y := -60;
Image3.Visible := false;
end;
if n = 4 then
begin
Image4.Position.Y := -60;
Image4.Visible := false;
end;
if n = 5 then
begin
Image5.Position.Y := -60;
Image5.Visible := false;
end;
if n = 6 then
begin
Image6.Position.Y := -60;
Image6.Visible := false;
end;
if n = 7 then
begin
Image7.Position.Y := -60;
Image7.Visible := false;
end;
if n = 8 then
begin
Image8.Position.Y := -60;
Image8.Visible := false;
end;
if n = 9 then
begin
Image9.Position.Y := -60;
Image9.Visible := false;
end;
if n = 10 then
begin
Image10.Position.Y := -60;
Image10.Visible := false;

end;
if n = 11 then
begin
Image11.Position.Y := -60;
Image11.Visible := false;
end;
if n = 12 then
begin
Image12.Position.Y := -60;
Image12.Visible := false;
end;
if n = 13 then
begin
Image13.Position.Y := -60;
Image13.Visible := false;
end;
if n = 14 then
begin
Image14.Position.Y := -60;
Image14.Visible := false;
end;
if n = 15 then
begin
Image15.Position.Y := -60;
Image15.Visible := false;
end;
if n = 16 then
begin
Image16.Position.Y := -60;
Image16.Visible := false;
end;
if n = 17 then
begin
Image17.Position.Y := -60;
Image17.Visible := false;
end;
if n = 18 then
begin
Image18.Position.Y := -60;
Image18.Visible := false;
end;
if n = 19 then
begin
Image19.Position.Y := -60;
Image19.Visible := false;
end;
if n = 20 then
begin

Image20.Position.Y := -60;
Image20.Visible := false;
end;
if n = 21 then
begin
Image21.Position.Y := -60;
Image21.Visible := false;
end;
if n = 22 then
begin
Image22.Position.Y := -60;
Image22.Visible := false;
end;
if n = 23 then
begin
Image23.Position.Y := -60;
Image23.Visible := false;
end;
if n = 24 then
begin
Image24.Position.Y := -60;
Image24.Visible := false;
end;
if n = 25 then
begin
Image25.Position.Y := -60;
Image25.Visible := false;
end;
if n = 26 then
begin
Image26.Position.Y := -60;
Image26.Visible := false;
end;
if n = 27 then
begin
Image27.Position.Y := -60;
Image27.Visible := false;
end;
if n = 28 then
begin
Image28.Position.Y := -60;
Image28.Visible := false;
end;
if n = 29