From 14240925ba8fb37ff721e01b9ad3012c33d01e9f Mon Sep 17 00:00:00 2001 From: BroPlasmaNinja Date: Wed, 27 Mar 2024 13:30:13 +0400 Subject: [PATCH] VariantChange --- ProjectAntiAircraftGun/DrawingAntiAircraft.cs | 57 ------------- ProjectAntiAircraftGun/DrawingLiner.cs | 82 +++++++++++++++++++ ...tGun.Designer.cs => FormLiner.Designer.cs} | 32 ++++---- .../{FormAntiAircraftGun.cs => FormLiner.cs} | 17 ++-- ...ormAntiAircraftGun.resx => FormLiner.resx} | 0 ProjectAntiAircraftGun/GameObject.cs | 2 +- .../{AntiAircraft.cs => Liner.cs} | 30 ++++--- ProjectAntiAircraftGun/Program.cs | 4 +- ...AircraftGun.csproj => ProjectLiner.csproj} | 0 ...ctAntiAircraftGun.sln => ProjectLiner.sln} | 2 +- ProjectAntiAircraftGun/Vector2.cs | 2 +- 11 files changed, 128 insertions(+), 100 deletions(-) delete mode 100644 ProjectAntiAircraftGun/DrawingAntiAircraft.cs create mode 100644 ProjectAntiAircraftGun/DrawingLiner.cs rename ProjectAntiAircraftGun/{FormAntiAircraftGun.Designer.cs => FormLiner.Designer.cs} (84%) rename ProjectAntiAircraftGun/{FormAntiAircraftGun.cs => FormLiner.cs} (75%) rename ProjectAntiAircraftGun/{FormAntiAircraftGun.resx => FormLiner.resx} (100%) rename ProjectAntiAircraftGun/{AntiAircraft.cs => Liner.cs} (70%) rename ProjectAntiAircraftGun/{ProjectAntiAircraftGun.csproj => ProjectLiner.csproj} (100%) rename ProjectAntiAircraftGun/{ProjectAntiAircraftGun.sln => ProjectLiner.sln} (86%) diff --git a/ProjectAntiAircraftGun/DrawingAntiAircraft.cs b/ProjectAntiAircraftGun/DrawingAntiAircraft.cs deleted file mode 100644 index bfd1d2a..0000000 --- a/ProjectAntiAircraftGun/DrawingAntiAircraft.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Drawing; - -namespace ProjectAntiAircraftGun -{ - internal class DrawingAntiAircraft - { - AntiAircraft aag; - private readonly int _width = 0; - private readonly int _height = 0; - public DrawingAntiAircraft(AntiAircraft aag) - { - this.aag = aag; - } - public DrawingAntiAircraft() - { - aag = new AntiAircraft(); - } - public void SetPos(Point pos) - { - aag.position.X = Math.Clamp(pos.X + aag.position.X, 0, Program.faag.ClientSize.Width-_width); - aag.position.Y = Math.Clamp(pos.Y + aag.position.Y, 0, Program.faag.ClientSize.Height-_height); - } - public void MoveTransport(Vector2 way) - { - if(way == null) - { - throw new NullReferenceException(); - } - SetPos(new Point((int)(way.x*aag.Step), (int)(way.y*aag.Step))); - } - public void Draw(Graphics g) - { - Pen pen = new Pen(Color.Black); - Brush brush1 = new SolidBrush(aag.FirstColor); - Brush brush2 = new SolidBrush(aag.SecondColor); - - // Отрисовка гусениц - g.DrawLine(pen, aag.position.X, aag.position.Y + 30, aag.position.X + 90, aag.position.Y + 30); - g.DrawLine(pen, aag.position.X + 90, aag.position.Y + 30, aag.position.X + 90, aag.position.Y + 15); - g.DrawLine(pen, aag.position.X + 90, aag.position.Y + 15, aag.position.X, aag.position.Y + 15); - g.DrawLine(pen, aag.position.X, aag.position.Y + 15, aag.position.X, aag.position.Y + 30); - - // Отрисовка катков - g.FillEllipse(brush1, aag.position.X, aag.position.Y + 15, 15, 15); - g.FillEllipse(brush1, aag.position.X + 75, aag.position.Y + 15, 15, 15); - for (int i = 1; i <= aag.NumOfRollers - 2; i++) - g.FillEllipse(brush2, aag.position.X +(75/(aag.NumOfRollers-1))*i, aag.position.Y + 15, 15, 15); - - // Отрисовка кузова - g.FillRectangle(brush1, aag.position.X + 15, aag.position.Y, 60, 15); - - brush1.Dispose(); - brush2.Dispose(); - pen.Dispose(); - } - } -} diff --git a/ProjectAntiAircraftGun/DrawingLiner.cs b/ProjectAntiAircraftGun/DrawingLiner.cs new file mode 100644 index 0000000..75f61ab --- /dev/null +++ b/ProjectAntiAircraftGun/DrawingLiner.cs @@ -0,0 +1,82 @@ +using System.Drawing; + +namespace ProjectLiner +{ + internal class DrawingLiner + { + Liner aag; + private readonly int _width = 0; + private readonly int _height = 0; + public DrawingLiner(Liner aag) + { + this.aag = aag; + _height = 60 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15); + _width = 150; + } + public DrawingLiner() + { + aag = new Liner(); + } + public void SetPos(Point pos) + { + aag.position.X = Math.Clamp(pos.X + aag.position.X, 0, Program.faag.ClientSize.Width-_width); + aag.position.Y = Math.Clamp(pos.Y + aag.position.Y, 0, Program.faag.ClientSize.Height-_height); + } + public void MoveTransport(Vector2 way) + { + if(way == null) + { + throw new NullReferenceException(); + } + SetPos(new Point((int)(way.x*aag.Step), (int)(way.y*aag.Step))); + } + public void Draw(Graphics g) + { + Pen pen = new Pen(Color.Black); + Brush brush1 = new SolidBrush(aag.FirstColor); + Brush brush2 = new SolidBrush(aag.SecondColor); + + //deck + g.DrawPolygon(pen, new Point[] { + new Point(0 + aag.position.X, 15 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(150 + aag.position.X, 15 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(120 + aag.position.X, 45 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(30 + aag.position.X, 45 + aag.position.Y +((int)(aag.NumOfBoxes / 8 + 0.5) * 15)), + new Point(0 + aag.position.X, 15 + aag.position.Y +((int)(aag.NumOfBoxes / 8 + 0.5) * 15))}); + g.FillPolygon(brush1, new Point[] { + new Point(0 + aag.position.X, 15 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(150 + aag.position.X, 15 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(120 + aag.position.X, 45 + aag.position.Y+((int)(aag.NumOfBoxes/8+0.5)*15)), + new Point(30 + aag.position.X, 45 + aag.position.Y +((int)(aag.NumOfBoxes / 8 + 0.5) * 15)), + new Point(0 + aag.position.X, 15 + aag.position.Y +((int)(aag.NumOfBoxes / 8 + 0.5) * 15))}); + //mark + if (aag.HasMark) + { + g.DrawLine(new Pen(aag.SecondColor),30+aag.position.X, 20 + aag.position.Y + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 30 + aag.position.X, 35 + aag.position.Y + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15)); + g.DrawLine(new Pen(aag.SecondColor), 20+aag.position.X, 25 + aag.position.Y + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 40 + aag.position.X, 25 + aag.position.Y + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15)); + } + //block + for (int j = 0; j <= (int)(aag.NumOfBoxes / 8 + 0.5); j++) + { + if(aag.NumOfBoxes - j * 8 >= 8) + for (int i = 0; i < 8; i++) + { + g.FillRectangle(brush2, 15 + aag.position.X + i * 15, aag.position.Y - j * 15+((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + g.DrawRectangle(pen, 15 + aag.position.X + i * 15, aag.position.Y - j * 15 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + } + else + for (int i = 0; i < aag.NumOfBoxes%8; i++) + { + if(aag.NumOfBoxes % 8 == 1) + { + g.FillRectangle(brush2, 8 + 15 + aag.position.X + (90 / 2), aag.position.Y - j * 15 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + g.DrawRectangle(pen, 8 + 15 + aag.position.X + (90 / 2), aag.position.Y - j * 15 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + continue; + } + g.FillRectangle(brush2,8 +15 + aag.position.X + (90 / (aag.NumOfBoxes % 8 - 1)) * i, aag.position.Y - j * 15 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + g.DrawRectangle(pen,8 + 15 + aag.position.X + (90 / (aag.NumOfBoxes % 8 - 1)) * i, aag.position.Y - j * 15 + ((int)(aag.NumOfBoxes / 8 + 0.5) * 15), 15, 15); + } + } + } + } +} diff --git a/ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs b/ProjectAntiAircraftGun/FormLiner.Designer.cs similarity index 84% rename from ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs rename to ProjectAntiAircraftGun/FormLiner.Designer.cs index 30b8095..d02ac01 100644 --- a/ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs +++ b/ProjectAntiAircraftGun/FormLiner.Designer.cs @@ -1,6 +1,6 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { - partial class FormAntiAircraftGun + partial class FormLiner { /// /// Required designer variable. @@ -28,23 +28,23 @@ /// private void InitializeComponent() { - pictureBoxAntiAircraftGun = new PictureBox(); + pictureBoxLiner = new PictureBox(); CreateButton = new Button(); buttonRight = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonUp = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit(); SuspendLayout(); // - // pictureBoxAntiAircraftGun + // pictureBoxLiner // - pictureBoxAntiAircraftGun.Dock = DockStyle.Fill; - pictureBoxAntiAircraftGun.Location = new Point(0, 0); - pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun"; - pictureBoxAntiAircraftGun.Size = new Size(800, 450); - pictureBoxAntiAircraftGun.TabIndex = 5; - pictureBoxAntiAircraftGun.TabStop = false; + pictureBoxLiner.Dock = DockStyle.Fill; + pictureBoxLiner.Location = new Point(0, 0); + pictureBoxLiner.Name = "pictureBoxLiner"; + pictureBoxLiner.Size = new Size(800, 450); + pictureBoxLiner.TabIndex = 5; + pictureBoxLiner.TabStop = false; // // CreateButton // @@ -110,16 +110,16 @@ Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(CreateButton); - Controls.Add(pictureBoxAntiAircraftGun); - Name = "FormAntiAircraftGun"; - Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).EndInit(); + Controls.Add(pictureBoxLiner); + Name = "FormLiner"; + Text = "Liner"; + ((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit(); ResumeLayout(false); } #endregion - private PictureBox pictureBoxAntiAircraftGun; + private PictureBox pictureBoxLiner; private Button CreateButton; private Button buttonRight; private Button buttonDown; diff --git a/ProjectAntiAircraftGun/FormAntiAircraftGun.cs b/ProjectAntiAircraftGun/FormLiner.cs similarity index 75% rename from ProjectAntiAircraftGun/FormAntiAircraftGun.cs rename to ProjectAntiAircraftGun/FormLiner.cs index 794aca0..d738aad 100644 --- a/ProjectAntiAircraftGun/FormAntiAircraftGun.cs +++ b/ProjectAntiAircraftGun/FormLiner.cs @@ -1,9 +1,9 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { - public partial class FormAntiAircraftGun : Form + public partial class FormLiner : Form { - private DrawingAntiAircraft? _drawer; - public FormAntiAircraftGun() + private DrawingLiner? _drawer; + public FormLiner() { InitializeComponent(); } @@ -12,10 +12,10 @@ namespace ProjectAntiAircraftGun if (_drawer == null) return; - Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); + Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height); Graphics gr = Graphics.FromImage(bmp); _drawer.Draw(gr); - pictureBoxAntiAircraftGun.Image = bmp; + pictureBoxLiner.Image = bmp; } private void ButtonMove_Click(object sender, EventArgs e) { @@ -38,16 +38,15 @@ namespace ProjectAntiAircraftGun _drawer.MoveTransport(new Vector2(1, 0)); break; } - Draw(); } private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new Random(); - _drawer = new DrawingAntiAircraft(new AntiAircraft(rnd.Next(1,100),rnd.Next(1,10), + _drawer = new DrawingLiner(new Liner(rnd.Next(1,100),rnd.Next(1,10), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), - rnd.Next(2, 7))); + rnd.Next(2, 25), Convert.ToBoolean(rnd.Next(0,2)))); Draw(); } } diff --git a/ProjectAntiAircraftGun/FormAntiAircraftGun.resx b/ProjectAntiAircraftGun/FormLiner.resx similarity index 100% rename from ProjectAntiAircraftGun/FormAntiAircraftGun.resx rename to ProjectAntiAircraftGun/FormLiner.resx diff --git a/ProjectAntiAircraftGun/GameObject.cs b/ProjectAntiAircraftGun/GameObject.cs index a67dfbc..ba40162 100644 --- a/ProjectAntiAircraftGun/GameObject.cs +++ b/ProjectAntiAircraftGun/GameObject.cs @@ -1,4 +1,4 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { abstract public class GameObject { diff --git a/ProjectAntiAircraftGun/AntiAircraft.cs b/ProjectAntiAircraftGun/Liner.cs similarity index 70% rename from ProjectAntiAircraftGun/AntiAircraft.cs rename to ProjectAntiAircraftGun/Liner.cs index 5b2a6c8..40b1668 100644 --- a/ProjectAntiAircraftGun/AntiAircraft.cs +++ b/ProjectAntiAircraftGun/Liner.cs @@ -1,26 +1,29 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { - public class AntiAircraft : GameObject + public class Liner : GameObject { private int _speed; private int _weight; private Color _firstCol; private Color _secondCol; - private int _numOfRollers; + private int _numOfBoxes; + private bool _haveMark; private int _step; public int Speed { get => _speed;} public int Weight { get => _weight;} public Color FirstColor { get => _firstCol; } public Color SecondColor { get => _secondCol; } - public int NumOfRollers { get => _numOfRollers; } + public int NumOfBoxes { get => _numOfBoxes; } public int Step { get => _step>0?_step:1; } - public AntiAircraft() + public bool HasMark { get => _haveMark;} + public Liner() { _speed = 1; _weight = 1; _firstCol = Color.Magenta; _secondCol = Color.Black; - _numOfRollers = 6; + _numOfBoxes = 6; + _haveMark = true; try { _step = _speed / _weight; @@ -33,17 +36,18 @@ /// (0,int.MaxValue] /// /// - /// [2,6] + /// [2,6] /// - public AntiAircraft(int speed, int weight, Color firstCol, Color secondCol, int numOfRollers) + public Liner(int speed, int weight, Color firstCol, Color secondCol, int numOfBoxes,bool haveMark) { - if (numOfRollers < 2 || numOfRollers > 6) - throw new Exception("numOfRollers out of range [2,6]"); + if (numOfBoxes > 24||numOfBoxes<2) + throw new ArgumentOutOfRangeException($"{nameof(numOfBoxes)} out of range [2,24]"); _speed = speed; _weight = weight; _firstCol = firstCol; _secondCol = secondCol; - _numOfRollers = numOfRollers; + _numOfBoxes = numOfBoxes; + _haveMark = haveMark; try { _step = _speed / _weight; @@ -56,12 +60,12 @@ /// /// (0,int.MaxValue] /// - public AntiAircraft(int speed, int weight, Color firstCol) + public Liner(int speed, int weight, Color firstCol) { _speed = speed; _weight = weight; _firstCol = firstCol; - _numOfRollers = 6; + _numOfBoxes = 6; try { _step = _speed / _weight; diff --git a/ProjectAntiAircraftGun/Program.cs b/ProjectAntiAircraftGun/Program.cs index a09edc2..fff1540 100644 --- a/ProjectAntiAircraftGun/Program.cs +++ b/ProjectAntiAircraftGun/Program.cs @@ -1,11 +1,11 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { internal static class Program { /// /// The main entry point for the application. /// - public static FormAntiAircraftGun faag = new FormAntiAircraftGun(); + public static FormLiner faag = new FormLiner(); [STAThread] static void Main() { diff --git a/ProjectAntiAircraftGun/ProjectAntiAircraftGun.csproj b/ProjectAntiAircraftGun/ProjectLiner.csproj similarity index 100% rename from ProjectAntiAircraftGun/ProjectAntiAircraftGun.csproj rename to ProjectAntiAircraftGun/ProjectLiner.csproj diff --git a/ProjectAntiAircraftGun/ProjectAntiAircraftGun.sln b/ProjectAntiAircraftGun/ProjectLiner.sln similarity index 86% rename from ProjectAntiAircraftGun/ProjectAntiAircraftGun.sln rename to ProjectAntiAircraftGun/ProjectLiner.sln index 71ca527..1b46542 100644 --- a/ProjectAntiAircraftGun/ProjectAntiAircraftGun.sln +++ b/ProjectAntiAircraftGun/ProjectLiner.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectAntiAircraftGun", "ProjectAntiAircraftGun.csproj", "{0C215558-2860-459F-A04D-5BCE3792F5CC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectLiner", "ProjectLiner.csproj", "{0C215558-2860-459F-A04D-5BCE3792F5CC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ProjectAntiAircraftGun/Vector2.cs b/ProjectAntiAircraftGun/Vector2.cs index d92680b..c48cd3e 100644 --- a/ProjectAntiAircraftGun/Vector2.cs +++ b/ProjectAntiAircraftGun/Vector2.cs @@ -1,4 +1,4 @@ -namespace ProjectAntiAircraftGun +namespace ProjectLiner { public class Vector2 {