Zakharov V. V. LabWork 1 #1
49
Traktor/Traktor/DrawField.Designer.cs
generated
49
Traktor/Traktor/DrawField.Designer.cs
generated
@ -46,8 +46,9 @@
|
||||
//
|
||||
this.pictureBoxTraktor.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxTraktor.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxTraktor.Name = "pictureBoxTraktor";
|
||||
this.pictureBoxTraktor.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxTraktor.Size = new System.Drawing.Size(700, 338);
|
||||
this.pictureBoxTraktor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxTraktor.TabIndex = 0;
|
||||
this.pictureBoxTraktor.TabStop = false;
|
||||
@ -60,35 +61,37 @@
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 424);
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 316);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
|
||||
this.statusStrip.Size = new System.Drawing.Size(700, 22);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес: ";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(95, 20);
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(75, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет кузова:";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(29, 362);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(25, 272);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -99,50 +102,58 @@
|
||||
this.buttonLEFT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLEFT.BackgroundImage = global::Traktor.Properties.Resources.arrowLeft;
|
||||
this.buttonLEFT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLEFT.Location = new System.Drawing.Point(673, 361);
|
||||
this.buttonLEFT.Location = new System.Drawing.Point(589, 271);
|
||||
this.buttonLEFT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonLEFT.Name = "buttonLEFT";
|
||||
this.buttonLEFT.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLEFT.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonLEFT.TabIndex = 3;
|
||||
this.buttonLEFT.UseVisualStyleBackColor = true;
|
||||
this.buttonLEFT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRIGHT
|
||||
//
|
||||
this.buttonRIGHT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRIGHT.BackgroundImage = global::Traktor.Properties.Resources.arrowRight;
|
||||
this.buttonRIGHT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRIGHT.Location = new System.Drawing.Point(745, 361);
|
||||
this.buttonRIGHT.Location = new System.Drawing.Point(652, 271);
|
||||
this.buttonRIGHT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRIGHT.Name = "buttonRIGHT";
|
||||
this.buttonRIGHT.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRIGHT.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonRIGHT.TabIndex = 4;
|
||||
this.buttonRIGHT.UseVisualStyleBackColor = true;
|
||||
this.buttonRIGHT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDOWN
|
||||
//
|
||||
this.buttonDOWN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDOWN.BackgroundImage = global::Traktor.Properties.Resources.arrowDown;
|
||||
this.buttonDOWN.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDOWN.Location = new System.Drawing.Point(709, 379);
|
||||
this.buttonDOWN.Location = new System.Drawing.Point(620, 284);
|
||||
this.buttonDOWN.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDOWN.Name = "buttonDOWN";
|
||||
this.buttonDOWN.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDOWN.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonDOWN.TabIndex = 5;
|
||||
this.buttonDOWN.UseVisualStyleBackColor = true;
|
||||
this.buttonDOWN.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUP
|
||||
//
|
||||
this.buttonUP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUP.BackgroundImage = global::Traktor.Properties.Resources.arrowUp;
|
||||
this.buttonUP.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUP.Location = new System.Drawing.Point(709, 343);
|
||||
this.buttonUP.Location = new System.Drawing.Point(620, 257);
|
||||
this.buttonUP.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUP.Name = "buttonUP";
|
||||
this.buttonUP.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUP.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonUP.TabIndex = 6;
|
||||
this.buttonUP.UseVisualStyleBackColor = true;
|
||||
this.buttonUP.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// DrawField
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Controls.Add(this.buttonUP);
|
||||
this.Controls.Add(this.buttonDOWN);
|
||||
@ -150,8 +161,10 @@
|
||||
this.Controls.Add(this.buttonLEFT);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxTraktor);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "DrawField";
|
||||
this.Text = "Трактор";
|
||||
this.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTraktor)).EndInit();
|
||||
this.statusStrip.ResumeLayout(false);
|
||||
this.statusStrip.PerformLayout();
|
||||
|
@ -23,7 +23,7 @@ namespace Traktor
|
||||
{
|
||||
Random random = new Random();
|
||||
_Traktor = new TraktorDraw();
|
||||
_Traktor.Init(random.Next(10, 70), random.Next(2500, 7000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
_Traktor.Init(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
_Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_Traktor.Traktor.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_Traktor.Traktor.Weight}";
|
||||
@ -31,6 +31,28 @@ namespace Traktor
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//ïîëó÷àåì èìÿ êíîïêè
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUP":
|
||||
_Traktor?.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDOWN":
|
||||
_Traktor?.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLEFT":
|
||||
_Traktor?.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRIGHT":
|
||||
_Traktor?.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void PictureBoxTraktor_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_Traktor?.ChangeBorders(pictureBoxTraktor.Width, pictureBoxTraktor.Height);
|
||||
|
@ -22,9 +22,9 @@ namespace Traktor
|
||||
/// Высота окна отрисовки
|
||||
private int? pictureHeight = null;
|
||||
/// Ширина отрисовки сущности
|
||||
private readonly int entWidth = 0;
|
||||
private readonly int entWidth = 130;
|
||||
/// Высота отрисовки сущности
|
||||
private readonly int entHeight = 0;
|
||||
private readonly int entHeight = 100;
|
||||
|
||||
public void Init(int speed, float weight, Color bodycolor)
|
||||
{
|
||||
@ -33,12 +33,18 @@ namespace Traktor
|
||||
}
|
||||
|
||||
//Установка позиции сущности
|
||||
public void SetPosition(int x, int y, int widgh, int height)
|
||||
{//сделать проверку!!!!!
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || y < 0 || width < x + entWidth || height < y + entHeight)
|
||||
{
|
||||
pictureHeight = null;
|
||||
pictureWidth = null;
|
||||
return;
|
||||
}
|
||||
startPosX = x;
|
||||
startPosY = y;
|
||||
pictureHeight = height;
|
||||
pictureWidth = widgh;
|
||||
pictureWidth = width;
|
||||
}
|
||||
|
||||
//Изменение направления перемещения
|
||||
@ -57,7 +63,7 @@ namespace Traktor
|
||||
}
|
||||
break;
|
||||
case Direction.Left:
|
||||
if (startPosX - Traktor.Step > 0)
|
||||
if (startPosX-10 - Traktor.Step > 0)
|
||||
{
|
||||
startPosX -= Traktor.Step;
|
||||
}
|
||||
@ -85,9 +91,36 @@ namespace Traktor
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Blue);
|
||||
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
|
||||
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
|
||||
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY, 40, 30);
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 30, 100, 35);
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX+72, startPosY + 10, 5, 20);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX-15, startPosY+67, 30, 30);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX+85, startPosY + 67, 30, 30);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX + 20, startPosY + 82, 15, 15);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX + 40, startPosY + 82, 15, 15);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX + 60, startPosY + 82, 15, 15);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX + 35, startPosY + 68, 10, 10);
|
||||
g.DrawEllipse(pen_Black_1pxl, startPosX + 55, startPosY + 68, 10, 10);
|
||||
|
||||
g.DrawLine(pen_Black_2pxl, startPosX, startPosY + 67, startPosX + 100, startPosY + 67);
|
||||
g.DrawLine(pen_Black_2pxl, startPosX, startPosY + 97, startPosX + 100, startPosY + 97);
|
||||
|
||||
Brush br = new SolidBrush(Traktor?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, startPosX, startPosY, 40, 30);
|
||||
g.FillRectangle(br, startPosX, startPosY + 30, 100, 35);
|
||||
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, startPosX + 72, startPosY + 10, 5, 20);
|
||||
g.FillEllipse(brBlack, startPosX - 15, startPosY + 67, 30, 30);
|
||||
g.FillEllipse(brBlack, startPosX + 85, startPosY + 67, 30, 30);
|
||||
g.FillEllipse(brBlack, startPosX + 20, startPosY + 82, 15, 15);
|
||||
g.FillEllipse(brBlack, startPosX + 40, startPosY + 82, 15, 15);
|
||||
g.FillEllipse(brBlack, startPosX + 60, startPosY + 82, 15, 15);
|
||||
g.FillEllipse(brBlack, startPosX + 35, startPosY + 68, 10, 10);
|
||||
g.FillEllipse(brBlack, startPosX + 55, startPosY + 68, 10, 10);
|
||||
}
|
||||
|
||||
//Смена границ формы
|
||||
|
Loading…
Reference in New Issue
Block a user