VariantChange
This commit is contained in:
parent
de79772313
commit
14240925ba
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
82
ProjectAntiAircraftGun/DrawingLiner.cs
Normal file
82
ProjectAntiAircraftGun/DrawingLiner.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
partial class FormAntiAircraftGun
|
partial class FormLiner
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -28,23 +28,23 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxAntiAircraftGun = new PictureBox();
|
pictureBoxLiner = new PictureBox();
|
||||||
CreateButton = new Button();
|
CreateButton = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxAntiAircraftGun
|
// pictureBoxLiner
|
||||||
//
|
//
|
||||||
pictureBoxAntiAircraftGun.Dock = DockStyle.Fill;
|
pictureBoxLiner.Dock = DockStyle.Fill;
|
||||||
pictureBoxAntiAircraftGun.Location = new Point(0, 0);
|
pictureBoxLiner.Location = new Point(0, 0);
|
||||||
pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun";
|
pictureBoxLiner.Name = "pictureBoxLiner";
|
||||||
pictureBoxAntiAircraftGun.Size = new Size(800, 450);
|
pictureBoxLiner.Size = new Size(800, 450);
|
||||||
pictureBoxAntiAircraftGun.TabIndex = 5;
|
pictureBoxLiner.TabIndex = 5;
|
||||||
pictureBoxAntiAircraftGun.TabStop = false;
|
pictureBoxLiner.TabStop = false;
|
||||||
//
|
//
|
||||||
// CreateButton
|
// CreateButton
|
||||||
//
|
//
|
||||||
@ -110,16 +110,16 @@
|
|||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(CreateButton);
|
Controls.Add(CreateButton);
|
||||||
Controls.Add(pictureBoxAntiAircraftGun);
|
Controls.Add(pictureBoxLiner);
|
||||||
Name = "FormAntiAircraftGun";
|
Name = "FormLiner";
|
||||||
Text = "Form1";
|
Text = "Liner";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxAntiAircraftGun;
|
private PictureBox pictureBoxLiner;
|
||||||
private Button CreateButton;
|
private Button CreateButton;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
@ -1,9 +1,9 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
public partial class FormAntiAircraftGun : Form
|
public partial class FormLiner : Form
|
||||||
{
|
{
|
||||||
private DrawingAntiAircraft? _drawer;
|
private DrawingLiner? _drawer;
|
||||||
public FormAntiAircraftGun()
|
public FormLiner()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
@ -12,10 +12,10 @@ namespace ProjectAntiAircraftGun
|
|||||||
if (_drawer == null)
|
if (_drawer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawer.Draw(gr);
|
_drawer.Draw(gr);
|
||||||
pictureBoxAntiAircraftGun.Image = bmp;
|
pictureBoxLiner.Image = bmp;
|
||||||
}
|
}
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -38,16 +38,15 @@ namespace ProjectAntiAircraftGun
|
|||||||
_drawer.MoveTransport(new Vector2(1, 0));
|
_drawer.MoveTransport(new Vector2(1, 0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
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)),
|
||||||
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();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
abstract public class GameObject
|
abstract public class GameObject
|
||||||
{
|
{
|
||||||
|
@ -1,26 +1,29 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
public class AntiAircraft : GameObject
|
public class Liner : GameObject
|
||||||
{
|
{
|
||||||
private int _speed;
|
private int _speed;
|
||||||
private int _weight;
|
private int _weight;
|
||||||
private Color _firstCol;
|
private Color _firstCol;
|
||||||
private Color _secondCol;
|
private Color _secondCol;
|
||||||
private int _numOfRollers;
|
private int _numOfBoxes;
|
||||||
|
private bool _haveMark;
|
||||||
private int _step;
|
private int _step;
|
||||||
public int Speed { get => _speed;}
|
public int Speed { get => _speed;}
|
||||||
public int Weight { get => _weight;}
|
public int Weight { get => _weight;}
|
||||||
public Color FirstColor { get => _firstCol; }
|
public Color FirstColor { get => _firstCol; }
|
||||||
public Color SecondColor { get => _secondCol; }
|
public Color SecondColor { get => _secondCol; }
|
||||||
public int NumOfRollers { get => _numOfRollers; }
|
public int NumOfBoxes { get => _numOfBoxes; }
|
||||||
public int Step { get => _step>0?_step:1; }
|
public int Step { get => _step>0?_step:1; }
|
||||||
public AntiAircraft()
|
public bool HasMark { get => _haveMark;}
|
||||||
|
public Liner()
|
||||||
{
|
{
|
||||||
_speed = 1;
|
_speed = 1;
|
||||||
_weight = 1;
|
_weight = 1;
|
||||||
_firstCol = Color.Magenta;
|
_firstCol = Color.Magenta;
|
||||||
_secondCol = Color.Black;
|
_secondCol = Color.Black;
|
||||||
_numOfRollers = 6;
|
_numOfBoxes = 6;
|
||||||
|
_haveMark = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_step = _speed / _weight;
|
_step = _speed / _weight;
|
||||||
@ -33,17 +36,18 @@
|
|||||||
/// <param name="weight">(0,int.MaxValue]</param>
|
/// <param name="weight">(0,int.MaxValue]</param>
|
||||||
/// <param name="firstCol"></param>
|
/// <param name="firstCol"></param>
|
||||||
/// <param name="secondCol"></param>
|
/// <param name="secondCol"></param>
|
||||||
/// <param name="numOfRollers">[2,6]</param>
|
/// <param name="numOfBoxes">[2,6]</param>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
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)
|
if (numOfBoxes > 24||numOfBoxes<2)
|
||||||
throw new Exception("numOfRollers out of range [2,6]");
|
throw new ArgumentOutOfRangeException($"{nameof(numOfBoxes)} out of range [2,24]");
|
||||||
_speed = speed;
|
_speed = speed;
|
||||||
_weight = weight;
|
_weight = weight;
|
||||||
_firstCol = firstCol;
|
_firstCol = firstCol;
|
||||||
_secondCol = secondCol;
|
_secondCol = secondCol;
|
||||||
_numOfRollers = numOfRollers;
|
_numOfBoxes = numOfBoxes;
|
||||||
|
_haveMark = haveMark;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_step = _speed / _weight;
|
_step = _speed / _weight;
|
||||||
@ -56,12 +60,12 @@
|
|||||||
/// <param name="speed"></param>
|
/// <param name="speed"></param>
|
||||||
/// <param name="weight">(0,int.MaxValue]</param>
|
/// <param name="weight">(0,int.MaxValue]</param>
|
||||||
/// <param name="firstCol"></param>
|
/// <param name="firstCol"></param>
|
||||||
public AntiAircraft(int speed, int weight, Color firstCol)
|
public Liner(int speed, int weight, Color firstCol)
|
||||||
{
|
{
|
||||||
_speed = speed;
|
_speed = speed;
|
||||||
_weight = weight;
|
_weight = weight;
|
||||||
_firstCol = firstCol;
|
_firstCol = firstCol;
|
||||||
_numOfRollers = 6;
|
_numOfBoxes = 6;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_step = _speed / _weight;
|
_step = _speed / _weight;
|
@ -1,11 +1,11 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static FormAntiAircraftGun faag = new FormAntiAircraftGun();
|
public static FormLiner faag = new FormLiner();
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.6.33815.320
|
VisualStudioVersion = 17.6.33815.320
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectAntiAircraftGun
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
public class Vector2
|
public class Vector2
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user