diff --git a/ProjectAntiAircraftGun/AntiAircraft.cs b/ProjectAntiAircraftGun/AntiAircraft.cs new file mode 100644 index 0000000..7c25bb5 --- /dev/null +++ b/ProjectAntiAircraftGun/AntiAircraft.cs @@ -0,0 +1,77 @@ +namespace ProjectAntiAircraftGun +{ + public class AntiAircraft : GameObject + { + private int _speed; + private int _weight; + private Color _firstCol; + private Color _secondCol; + private bool _monoChrome; + private int _numOfRollers; + private int _step; + public int Speed { get => _speed;} + public int Weight { get => _weight;} + public Color FirstColor { get => _firstCol; } + public Color SecondColor { get => _secondCol; } + public bool MonoChrome { get => _monoChrome; } + public int NumOfRollers { get => _numOfRollers; } + public int Step { get => _step>0?_step:1; } + public AntiAircraft() + { + _speed = 1; + _weight = 1; + _firstCol = Color.Magenta; + _secondCol = Color.Black; + _monoChrome = true; + _numOfRollers = 6; + try + { + _step = _speed / _weight; + }catch(Exception e) { throw new Exception("Дурашка, какой ноль в весе?"); } + } + /// + /// + /// + /// + /// (0,int.MaxValue] + /// + /// + /// [2,6] + /// + public AntiAircraft(int speed, int weight, Color firstCol, Color secondCol, int numOfRollers) + { + if (numOfRollers < 2 || numOfRollers > 6) + throw new Exception("numOfRollers out of range [2,6]"); + _speed = speed; + _weight = weight; + _firstCol = firstCol; + _secondCol = secondCol; + _monoChrome = false; + _numOfRollers = numOfRollers; + try + { + _step = _speed / _weight; + } + catch (Exception e) { throw new Exception("Дурашка, какой ноль в весе?"); } + } + /// + /// + /// + /// + /// (0,int.MaxValue] + /// + public AntiAircraft(int speed, int weight, Color firstCol) + { + _speed = speed; + _weight = weight; + _firstCol = firstCol; + _monoChrome = false; + _numOfRollers = 6; + try + { + _step = _speed / _weight; + } + catch (Exception e) { throw e; } + } + } +} diff --git a/ProjectAntiAircraftGun/DrawingAntiAircraft.cs b/ProjectAntiAircraftGun/DrawingAntiAircraft.cs new file mode 100644 index 0000000..81bfe42 --- /dev/null +++ b/ProjectAntiAircraftGun/DrawingAntiAircraft.cs @@ -0,0 +1,52 @@ +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 brush = new SolidBrush(aag.FirstColor); + + // Отрисовка гусениц + 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(brush, aag.position.X, aag.position.Y + 15, 15, 15); + g.FillEllipse(brush, aag.position.X + 75, aag.position.Y + 15, 15, 15); + for (int i = 1; i <= aag.NumOfRollers - 2; i++) + g.FillEllipse(new SolidBrush(aag.SecondColor), aag.position.X +(75/(aag.NumOfRollers-1))*i, aag.position.Y + 15, 15, 15); + + // Отрисовка кузова + g.FillRectangle(brush, aag.position.X + 15, aag.position.Y, 60, 15); + } + } +} diff --git a/ProjectAntiAircraftGun/Form1.Designer.cs b/ProjectAntiAircraftGun/Form1.Designer.cs deleted file mode 100644 index f0a04d1..0000000 --- a/ProjectAntiAircraftGun/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectAntiAircraftGun -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/ProjectAntiAircraftGun/Form1.cs b/ProjectAntiAircraftGun/Form1.cs deleted file mode 100644 index c5553d6..0000000 --- a/ProjectAntiAircraftGun/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectAntiAircraftGun -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs b/ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs new file mode 100644 index 0000000..30b8095 --- /dev/null +++ b/ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs @@ -0,0 +1,129 @@ +namespace ProjectAntiAircraftGun +{ + partial class FormAntiAircraftGun + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxAntiAircraftGun = new PictureBox(); + CreateButton = new Button(); + buttonRight = new Button(); + buttonDown = new Button(); + buttonLeft = new Button(); + buttonUp = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit(); + SuspendLayout(); + // + // pictureBoxAntiAircraftGun + // + 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; + // + // CreateButton + // + CreateButton.Location = new Point(12, 408); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(90, 30); + CreateButton.TabIndex = 0; + CreateButton.Text = "Create"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += ButtonCreate_Click; + // + // buttonRight + // + buttonRight.Font = new Font("Segoe UI", 15F, FontStyle.Regular, GraphicsUnit.Point); + buttonRight.Location = new Point(748, 398); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(40, 40); + buttonRight.TabIndex = 1; + buttonRight.Text = "⇒"; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Font = new Font("Segoe UI", 15F, FontStyle.Regular, GraphicsUnit.Point); + buttonDown.Location = new Point(702, 398); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(40, 40); + buttonDown.TabIndex = 2; + buttonDown.Text = "⇓"; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // buttonLeft + // + buttonLeft.Font = new Font("Segoe UI", 15F, FontStyle.Regular, GraphicsUnit.Point); + buttonLeft.Location = new Point(656, 398); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(40, 40); + buttonLeft.TabIndex = 3; + buttonLeft.Text = "⇐"; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Font = new Font("Segoe UI", 15F, FontStyle.Regular, GraphicsUnit.Point); + buttonUp.Location = new Point(702, 352); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(40, 40); + buttonUp.TabIndex = 4; + buttonUp.Text = "⇑"; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // FormAntiAircraftGun + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonUp); + Controls.Add(buttonLeft); + Controls.Add(buttonDown); + Controls.Add(buttonRight); + Controls.Add(CreateButton); + Controls.Add(pictureBoxAntiAircraftGun); + Name = "FormAntiAircraftGun"; + Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxAntiAircraftGun; + private Button CreateButton; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/ProjectAntiAircraftGun/FormAntiAircraftGun.cs b/ProjectAntiAircraftGun/FormAntiAircraftGun.cs new file mode 100644 index 0000000..794aca0 --- /dev/null +++ b/ProjectAntiAircraftGun/FormAntiAircraftGun.cs @@ -0,0 +1,54 @@ +namespace ProjectAntiAircraftGun +{ + public partial class FormAntiAircraftGun : Form + { + private DrawingAntiAircraft? _drawer; + public FormAntiAircraftGun() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawer == null) + return; + + Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawer.Draw(gr); + pictureBoxAntiAircraftGun.Image = bmp; + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawer == null) + { + return; + } + switch (((Button)sender)?.Name ?? string.Empty) + { + case "buttonUp": + _drawer.MoveTransport(new Vector2(0, -1)); + break; + case "buttonDown": + _drawer.MoveTransport(new Vector2(0, 1)); + break; + case "buttonLeft": + _drawer.MoveTransport(new Vector2(-1, 0)); + break; + case "buttonRight": + _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), + 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))); + Draw(); + } + } +} \ No newline at end of file diff --git a/ProjectAntiAircraftGun/Form1.resx b/ProjectAntiAircraftGun/FormAntiAircraftGun.resx similarity index 93% rename from ProjectAntiAircraftGun/Form1.resx rename to ProjectAntiAircraftGun/FormAntiAircraftGun.resx index 1af7de1..af32865 100644 --- a/ProjectAntiAircraftGun/Form1.resx +++ b/ProjectAntiAircraftGun/FormAntiAircraftGun.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectAntiAircraftGun/GameObject.cs b/ProjectAntiAircraftGun/GameObject.cs new file mode 100644 index 0000000..a67dfbc --- /dev/null +++ b/ProjectAntiAircraftGun/GameObject.cs @@ -0,0 +1,11 @@ +namespace ProjectAntiAircraftGun +{ + abstract public class GameObject + { + public Point position; + public GameObject() + { + position = new Point(); + } + } +} diff --git a/ProjectAntiAircraftGun/Program.cs b/ProjectAntiAircraftGun/Program.cs index f60dd13..a09edc2 100644 --- a/ProjectAntiAircraftGun/Program.cs +++ b/ProjectAntiAircraftGun/Program.cs @@ -5,13 +5,14 @@ namespace ProjectAntiAircraftGun /// /// The main entry point for the application. /// + public static FormAntiAircraftGun faag = new FormAntiAircraftGun(); [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(faag); } } } \ No newline at end of file diff --git a/ProjectAntiAircraftGun/Vector2.cs b/ProjectAntiAircraftGun/Vector2.cs new file mode 100644 index 0000000..d92680b --- /dev/null +++ b/ProjectAntiAircraftGun/Vector2.cs @@ -0,0 +1,19 @@ +namespace ProjectAntiAircraftGun +{ + public class Vector2 + { + public float x, y; + public float lenght => MathF.Sqrt(x * x + y * y); + public Vector2 normilized => new Vector2(x/lenght, y/lenght); + public Vector2(float x, float y) + { + this.x = x; + this.y = y; + } + public Vector2() + { + x = 0; + y = 0; + } + } +}