End of First Lab
This commit is contained in:
parent
5f67677ae8
commit
028d0d760d
77
ProjectAntiAircraftGun/AntiAircraft.cs
Normal file
77
ProjectAntiAircraftGun/AntiAircraft.cs
Normal file
@ -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("Дурашка, какой ноль в весе?"); }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight">(0,int.MaxValue]</param>
|
||||
/// <param name="firstCol"></param>
|
||||
/// <param name="secondCol"></param>
|
||||
/// <param name="numOfRollers">[2,6]</param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
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("Дурашка, какой ноль в весе?"); }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight">(0,int.MaxValue]</param>
|
||||
/// <param name="firstCol"></param>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
52
ProjectAntiAircraftGun/DrawingAntiAircraft.cs
Normal file
52
ProjectAntiAircraftGun/DrawingAntiAircraft.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
39
ProjectAntiAircraftGun/Form1.Designer.cs
generated
39
ProjectAntiAircraftGun/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
129
ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
Normal file
129
ProjectAntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
Normal file
@ -0,0 +1,129 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
{
|
||||
partial class FormAntiAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
54
ProjectAntiAircraftGun/FormAntiAircraftGun.cs
Normal file
54
ProjectAntiAircraftGun/FormAntiAircraftGun.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
11
ProjectAntiAircraftGun/GameObject.cs
Normal file
11
ProjectAntiAircraftGun/GameObject.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
{
|
||||
abstract public class GameObject
|
||||
{
|
||||
public Point position;
|
||||
public GameObject()
|
||||
{
|
||||
position = new Point();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,13 +5,14 @@ namespace ProjectAntiAircraftGun
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
19
ProjectAntiAircraftGun/Vector2.cs
Normal file
19
ProjectAntiAircraftGun/Vector2.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user