Compare commits
2 Commits
028d0d760d
...
14240925ba
Author | SHA1 | Date | |
---|---|---|---|
14240925ba | |||
de79772313 |
@ -1,52 +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 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);
|
||||
}
|
||||
}
|
||||
}
|
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>
|
||||
/// Required designer variable.
|
||||
@ -28,23 +28,23 @@
|
||||
/// </summary>
|
||||
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;
|
@ -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();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
namespace ProjectLiner
|
||||
{
|
||||
abstract public class GameObject
|
||||
{
|
||||
|
@ -1,29 +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 bool _monoChrome;
|
||||
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 bool MonoChrome { get => _monoChrome; }
|
||||
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;
|
||||
_monoChrome = true;
|
||||
_numOfRollers = 6;
|
||||
_numOfBoxes = 6;
|
||||
_haveMark = true;
|
||||
try
|
||||
{
|
||||
_step = _speed / _weight;
|
||||
@ -36,18 +36,18 @@
|
||||
/// <param name="weight">(0,int.MaxValue]</param>
|
||||
/// <param name="firstCol"></param>
|
||||
/// <param name="secondCol"></param>
|
||||
/// <param name="numOfRollers">[2,6]</param>
|
||||
/// <param name="numOfBoxes">[2,6]</param>
|
||||
/// <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)
|
||||
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;
|
||||
_monoChrome = false;
|
||||
_numOfRollers = numOfRollers;
|
||||
_numOfBoxes = numOfBoxes;
|
||||
_haveMark = haveMark;
|
||||
try
|
||||
{
|
||||
_step = _speed / _weight;
|
||||
@ -60,13 +60,12 @@
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight">(0,int.MaxValue]</param>
|
||||
/// <param name="firstCol"></param>
|
||||
public AntiAircraft(int speed, int weight, Color firstCol)
|
||||
public Liner(int speed, int weight, Color firstCol)
|
||||
{
|
||||
_speed = speed;
|
||||
_weight = weight;
|
||||
_firstCol = firstCol;
|
||||
_monoChrome = false;
|
||||
_numOfRollers = 6;
|
||||
_numOfBoxes = 6;
|
||||
try
|
||||
{
|
||||
_step = _speed / _weight;
|
@ -1,11 +1,11 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
namespace ProjectLiner
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
public static FormAntiAircraftGun faag = new FormAntiAircraftGun();
|
||||
public static FormLiner faag = new FormLiner();
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
namespace ProjectAntiAircraftGun
|
||||
namespace ProjectLiner
|
||||
{
|
||||
public class Vector2
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user