Aleikin A.M. LabWork02 #2

Merged
eegov merged 9 commits from LabWork02 into LabWork01 2022-10-28 09:12:52 +04:00
5 changed files with 125 additions and 8 deletions
Showing only changes of commit cf4b1b18ec - Show all commits

View File

@ -8,9 +8,9 @@ namespace AirBomber
{
internal class DrawningBomber
{
public EntityAirBomber AirBomber { private set; get; }
private float _startPosX;
private float _startPosY;
public EntityAirBomber AirBomber { protected set; get; }
protected float _startPosX;
protected float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
private readonly int _airBomberWidth = 100;
@ -21,6 +21,13 @@ namespace AirBomber
AirBomber = new EntityAirBomber(speed, weight, bodyColor);
}
protected DrawningBomber(int speed, float weight, Color bodyColor, int airBomberWidth, int airBomberHeight) :
this (speed, weight, bodyColor)
{
_airBomberWidth = airBomberWidth;
_airBomberHeight = airBomberHeight;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x + _airBomberWidth > width || x < 0) return;
@ -66,7 +73,7 @@ namespace AirBomber
}
}
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
@ -101,8 +108,7 @@ namespace AirBomber
new Point((int)(_startPosX), (int)(_startPosY + _airBomberHeight / 2)),
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 - 5)),
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 + 5)),
});
});
}
public void ChangeBorders(int width, int height)

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class DrawningWarplane : DrawningBomber
{
public DrawningWarplane(int speed, float weight, Color bodyColor, Color dopColor, bool engines, bool weapons) :
base(speed, weight, bodyColor, 120, 120)
{
AirBomber = new EntityWarplane(speed, weight, bodyColor, dopColor, engines, weapons);
}
public override void DrawTransport(Graphics g)
{
if (AirBomber is not EntityWarplane warplane)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush dopBrush = new SolidBrush(warplane.DopColor);
if (warplane.Engines)
{
g.FillEllipse(dopBrush, _startPosX + 50, _startPosY + 15, 30, 15);
g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 35, 35, 15);
g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 70, 35, 15);
g.FillEllipse(dopBrush, _startPosX + 50, _startPosY + 90, 30, 15);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 15, 30, 15);
g.DrawEllipse(pen, _startPosX + 45, _startPosY + 35, 35, 15);
g.DrawEllipse(pen, _startPosX + 45, _startPosY + 70, 35, 15);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 90, 30, 15);
}
if (warplane.Weapons)
{
g.FillRectangle(dopBrush, _startPosX + 40, _startPosY, 30, 5);
g.FillRectangle(dopBrush, _startPosX + 40, _startPosY + 115, 30, 5);
g.DrawRectangle(pen, _startPosX + 40, _startPosY, 30, 5);
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 115, 30, 5);
}
base.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class EntityWarplane : EntityAirBomber
{
public Color DopColor { get; private set; }
public bool Engines { get; private set; }
public bool Weapons { get; private set; }
public EntityWarplane(int speed, float weight, Color bodyColor, Color dopColor, bool engines, bool weapons) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
Engines = engines;
Weapons = weapons;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@ -141,11 +142,23 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonCreate_Move);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(109, 455);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(110, 35);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// FormAirBomber
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(874, 515);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -175,5 +188,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
}
}

View File

@ -1,3 +1,5 @@
using System;
namespace AirBomber
{
public partial class FormAirBomber : Form
@ -16,14 +18,20 @@ namespace AirBomber
pictureBoxAirBomber.Image = bmp;
}
private void ButtonCreate_Click(object sender, EventArgs e)
private void SetData()
{
Random rnd = new();
_airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airBomber.AirBomber.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airBomber.AirBomber.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airBomber.AirBomber.BodyColor}";
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData();
Draw();
}
@ -53,5 +61,16 @@ namespace AirBomber
_airBomber?.ChangeBorders(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
Draw();
}
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_airBomber = new DrawningWarplane(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)),
Convert.ToBoolean(rnd.Next(0,2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
}
}