Polevoy S.V Lab_work2 #2
39
SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
Normal file
39
SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingAdvancedArtillery : DrawingArtillery
|
||||
{
|
||||
public DrawingAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, bool weapon, bool salvoBattery) : base(speed, weight, bodyColor, 80, 50)
|
||||
{
|
||||
Artillery = new EntityAdvancedArtillery(speed, weight, bodyColor, dopColor, weapon, salvoBattery);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Artillery is not EntityAdvancedArtillery advancedArtillery)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(advancedArtillery.DopColor, 8);
|
||||
Brush brush = new SolidBrush(advancedArtillery.DopColor);
|
||||
|
||||
if (advancedArtillery.Weapon)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + _artilleryWidth / 2, _startPosY + _artilleryHeight / 10, _startPosX + _artilleryWidth, _startPosY);
|
||||
}
|
||||
|
||||
if (advancedArtillery.SalvoBattery)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -8,13 +10,13 @@ namespace Artilleries
|
||||
{
|
||||
internal class DrawingArtillery
|
||||
{
|
||||
public EntityArtillery Artillery { private set; get; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
public EntityArtillery Artillery { protected set; get; }
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
private readonly int _artilleryWidth = 80;
|
||||
private readonly int _artilleryHeight = 50;
|
||||
protected readonly int _artilleryWidth = 80;
|
||||
protected readonly int _artilleryHeight = 50;
|
||||
|
||||
public DrawingArtillery(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
@ -88,7 +90,7 @@ namespace Artilleries
|
||||
return;
|
||||
}
|
||||
Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
|
||||
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5);
|
||||
g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3);
|
||||
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
@ -121,5 +123,10 @@ namespace Artilleries
|
||||
_startPosY = _pictureHeight.Value - _artilleryHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs
Normal file
40
SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingObjectArtillery : IDrawningObject
|
||||
{
|
||||
private DrawingArtillery _artillery = null;
|
||||
|
||||
public DrawingObjectArtillery(DrawingArtillery artillery)
|
||||
{
|
||||
_artillery = artillery;
|
||||
}
|
||||
|
||||
public float Step => _artillery?.Artillery?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _artillery?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_artillery?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_artillery.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public void DrawingObject(Graphics g)
|
||||
{
|
||||
_artillery.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
14
SelfPropelledArtilleryUnit/FormArtillery.Designer.cs
generated
14
SelfPropelledArtilleryUnit/FormArtillery.Designer.cs
generated
@ -39,6 +39,7 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.createAdvancedButton = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -147,11 +148,23 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// createAdvancedButton
|
||||
//
|
||||
this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.createAdvancedButton.Location = new System.Drawing.Point(105, 382);
|
||||
this.createAdvancedButton.Name = "createAdvancedButton";
|
||||
this.createAdvancedButton.Size = new System.Drawing.Size(142, 23);
|
||||
this.createAdvancedButton.TabIndex = 7;
|
||||
this.createAdvancedButton.Text = "Создать модификацию";
|
||||
this.createAdvancedButton.UseVisualStyleBackColor = true;
|
||||
this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click);
|
||||
//
|
||||
// FormArtillery
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(624, 441);
|
||||
this.Controls.Add(this.createAdvancedButton);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -183,5 +196,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button createAdvancedButton;
|
||||
}
|
||||
}
|
@ -17,14 +17,34 @@ namespace Artilleries
|
||||
pictureBoxArtilleries.Image = bmp;
|
||||
}
|
||||
|
||||
private void Prepair()
|
||||
{
|
||||
Random rnd = new();
|
||||
_artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
SpeedStatusLabel.Text = $"Ñêîðîñòü: {_artillery.Artillery.Speed}";
|
||||
WeightStatusLabel.Text = $"Âåñ: {_artillery.Artillery.Weight}";
|
||||
ColorStatusLabel.Text = $"Öâåò: {_artillery.Artillery.BodyColor.Name}";
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
SpeedStatusLabel.Text = $"Скорость: {_artillery.Artillery.Speed}";
|
||||
WeightStatusLabel.Text = $"Вес: {_artillery.Artillery.Weight}";
|
||||
ColorStatusLabel.Text = $"Цвет: {_artillery.Artillery.BodyColor.Name}";
|
||||
Prepair();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void createAdvancedButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_artillery = new DrawingAdvancedArtillery(
|
||||
rnd.Next(100, 300),
|
||||
rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1
|
||||
);
|
||||
Prepair();
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user