Лабораторная 3
This commit is contained in:
parent
af6582be5e
commit
a17318de92
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.6.33801.468
|
VisualStudioVersion = 17.7.34031.279
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{19BA0FA1-372B-490A-AA7F-757B0B8F322B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{5C602C58-ECEC-4FAB-BA10-FB671582D227}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,15 +11,15 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {5332F2FC-D1C2-4B42-B32E-53ECC094BBB7}
|
SolutionGuid = {73BF3262-E499-401F-BDBD-BD2BC7D3C324}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
135
Tank/Tank/CollectionsFrame.Designer.cs
generated
Normal file
135
Tank/Tank/CollectionsFrame.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
partial class CollectionsFrame
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
panel1 = new Panel();
|
||||||
|
UpdateButton = new Button();
|
||||||
|
DeleteButton = new Button();
|
||||||
|
AddButton = new Button();
|
||||||
|
InputNum = new TextBox();
|
||||||
|
label1 = new Label();
|
||||||
|
DrawTank = new PictureBox();
|
||||||
|
panel1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)DrawTank).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
panel1.Controls.Add(UpdateButton);
|
||||||
|
panel1.Controls.Add(DeleteButton);
|
||||||
|
panel1.Controls.Add(AddButton);
|
||||||
|
panel1.Controls.Add(InputNum);
|
||||||
|
panel1.Controls.Add(label1);
|
||||||
|
panel1.Dock = DockStyle.Right;
|
||||||
|
panel1.Location = new Point(550, 0);
|
||||||
|
panel1.Name = "panel1";
|
||||||
|
panel1.Size = new Size(250, 451);
|
||||||
|
panel1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
UpdateButton.Location = new Point(10, 241);
|
||||||
|
UpdateButton.Name = "UpdateButton";
|
||||||
|
UpdateButton.Size = new Size(229, 37);
|
||||||
|
UpdateButton.TabIndex = 4;
|
||||||
|
UpdateButton.Text = "Обновить коллекцию";
|
||||||
|
UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
UpdateButton.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
DeleteButton.Location = new Point(10, 176);
|
||||||
|
DeleteButton.Name = "DeleteButton";
|
||||||
|
DeleteButton.Size = new Size(229, 37);
|
||||||
|
DeleteButton.TabIndex = 3;
|
||||||
|
DeleteButton.Text = "Удалить технику";
|
||||||
|
DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
DeleteButton.Click += ButtonRemoveCar_Click;
|
||||||
|
//
|
||||||
|
// AddButton
|
||||||
|
//
|
||||||
|
AddButton.Location = new Point(10, 53);
|
||||||
|
AddButton.Name = "AddButton";
|
||||||
|
AddButton.Size = new Size(229, 37);
|
||||||
|
AddButton.TabIndex = 2;
|
||||||
|
AddButton.Text = "Добавить технику";
|
||||||
|
AddButton.UseVisualStyleBackColor = true;
|
||||||
|
AddButton.Click += ButtonAddTank_Click;
|
||||||
|
//
|
||||||
|
// InputNum
|
||||||
|
//
|
||||||
|
InputNum.Location = new Point(10, 133);
|
||||||
|
InputNum.Name = "InputNum";
|
||||||
|
InputNum.Size = new Size(228, 27);
|
||||||
|
InputNum.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(2, 3);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(103, 20);
|
||||||
|
label1.TabIndex = 0;
|
||||||
|
label1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// DrawTank
|
||||||
|
//
|
||||||
|
DrawTank.Dock = DockStyle.Fill;
|
||||||
|
DrawTank.Location = new Point(0, 0);
|
||||||
|
DrawTank.Name = "DrawTank";
|
||||||
|
DrawTank.Size = new Size(550, 451);
|
||||||
|
DrawTank.TabIndex = 1;
|
||||||
|
DrawTank.TabStop = false;
|
||||||
|
//
|
||||||
|
// CollectionsFrame
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 451);
|
||||||
|
Controls.Add(DrawTank);
|
||||||
|
Controls.Add(panel1);
|
||||||
|
Name = "CollectionsFrame";
|
||||||
|
Text = "Form1";
|
||||||
|
panel1.ResumeLayout(false);
|
||||||
|
panel1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Panel panel1;
|
||||||
|
private Button UpdateButton;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button AddButton;
|
||||||
|
private TextBox InputNum;
|
||||||
|
private Label label1;
|
||||||
|
private PictureBox DrawTank;
|
||||||
|
}
|
||||||
|
}
|
72
Tank/Tank/CollectionsFrame.cs
Normal file
72
Tank/Tank/CollectionsFrame.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using Tank.DrawningObjects;
|
||||||
|
using Tank.Generics;
|
||||||
|
using Tank.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
public partial class CollectionsFrame : Form
|
||||||
|
{
|
||||||
|
private readonly TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank> _tanks;
|
||||||
|
|
||||||
|
public CollectionsFrame()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_tanks = new TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>(DrawTank.Width, DrawTank.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddTank_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormTank form = new FormTank();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_tanks + form.SelectedCar != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
DrawTank.Image = _tanks.ShowCars();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = -1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pos = Convert.ToInt32(InputNum.Text);
|
||||||
|
}
|
||||||
|
catch (Exception ex) { }
|
||||||
|
if (_tanks - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
DrawTank.Image = _tanks.ShowCars();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DrawTank.Image = _tanks.ShowCars();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
Tank/Tank/CollectionsFrame.resx
Normal file
120
Tank/Tank/CollectionsFrame.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -5,12 +5,13 @@ using System.Security.Cryptography.Pkcs;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Tank.Entities;
|
using Tank.Entities;
|
||||||
|
using Tank.MovementStrategy;
|
||||||
|
|
||||||
namespace Tank
|
namespace Tank
|
||||||
{
|
{
|
||||||
public class DrawArmoVehicle
|
public class DrawArmoVehicle
|
||||||
{
|
{
|
||||||
public EntityBase? Tank { get; protected set; }
|
public EntityArmoVehicle? Tank { get; protected set; }
|
||||||
protected int _pictureWidth;
|
protected int _pictureWidth;
|
||||||
protected int _pictureHeight;
|
protected int _pictureHeight;
|
||||||
protected int _startPosX;
|
protected int _startPosX;
|
||||||
@ -29,7 +30,7 @@ namespace Tank
|
|||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
if (_pictureHeight < _Height || _pictureWidth < _Width)
|
if (_pictureHeight < _Height || _pictureWidth < _Width)
|
||||||
return;
|
return;
|
||||||
Tank = new EntityBase(speed, weight, bodyColor);
|
Tank = new EntityArmoVehicle(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawArmoVehicle(int speed, double weight, Color bodyColor, int width, int height, int tankWidth, int tankHeight)
|
protected DrawArmoVehicle(int speed, double weight, Color bodyColor, int width, int height, int tankWidth, int tankHeight)
|
||||||
@ -40,7 +41,7 @@ namespace Tank
|
|||||||
_Width = tankWidth;
|
_Width = tankWidth;
|
||||||
if (_pictureHeight < _Height || _pictureWidth < _Width)
|
if (_pictureHeight < _Height || _pictureWidth < _Width)
|
||||||
return;
|
return;
|
||||||
Tank = new EntityBase(speed, weight, bodyColor);
|
Tank = new EntityArmoVehicle(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanMove(Direction direction)
|
public bool CanMove(Direction direction)
|
||||||
@ -124,5 +125,7 @@ namespace Tank
|
|||||||
g.FillEllipse(ColorBlack, 85 + _startPosX, 42 + _startPosY, 20, 20);
|
g.FillEllipse(ColorBlack, 85 + _startPosX, 42 + _startPosY, 20, 20);
|
||||||
g.FillEllipse(ColorBlack, 110 + _startPosX, 42 + _startPosY, 20, 20);
|
g.FillEllipse(ColorBlack, 110 + _startPosX, 42 + _startPosY, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawingObjectTank(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,13 @@ namespace Tank.DrawningObjects
|
|||||||
{
|
{
|
||||||
if (Tank != null)
|
if (Tank != null)
|
||||||
{
|
{
|
||||||
Tank = new EntityAddBase(speed, weight, bodyColor, additionalColor, bodyKit, caterpillar, tower);
|
Tank = new EntityTank(speed, weight, bodyColor, additionalColor, bodyKit, caterpillar, tower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (Tank is not EntityAddBase ArmoVehicle)
|
if (Tank is not EntityTank ArmoVehicle)
|
||||||
return;
|
return;
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
if (ArmoVehicle.BodyKit)
|
if (ArmoVehicle.BodyKit)
|
||||||
@ -49,7 +49,7 @@ namespace Tank.DrawningObjects
|
|||||||
{
|
{
|
||||||
// Орудие
|
// Орудие
|
||||||
Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor);
|
Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor);
|
||||||
g.FillRectangle(bodyBrush, _startPosX + 111, _startPosY + 17, 70, 5);
|
g.FillRectangle(bodyBrush, _startPosX + 111, _startPosY + 17, 60, 5);
|
||||||
|
|
||||||
// Зенитное орудие
|
// Зенитное орудие
|
||||||
Point[] pointgun = { new Point(_startPosX + 44, _startPosY + 13), new Point(_startPosX + 45, _startPosY + 12), new Point(_startPosX + 41, _startPosY + 8), new Point(_startPosX + 41, _startPosY + 7),
|
Point[] pointgun = { new Point(_startPosX + 44, _startPosY + 13), new Point(_startPosX + 45, _startPosY + 12), new Point(_startPosX + 41, _startPosY + 8), new Point(_startPosX + 41, _startPosY + 7),
|
||||||
|
@ -6,13 +6,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank.Entities
|
namespace Tank.Entities
|
||||||
{
|
{
|
||||||
public class EntityBase
|
public class EntityArmoVehicle
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
public EntityBase(int speed, double weight, Color bodyColor)
|
public EntityArmoVehicle(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
@ -6,13 +6,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank.Entities
|
namespace Tank.Entities
|
||||||
{
|
{
|
||||||
public class EntityAddBase : EntityBase
|
public class EntityTank : EntityArmoVehicle
|
||||||
{
|
{
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
public bool BodyKit { get; private set; }
|
public bool BodyKit { get; private set; }
|
||||||
public bool Caterpillar { get; private set; }
|
public bool Caterpillar { get; private set; }
|
||||||
public bool Tower { get; private set; }
|
public bool Tower { get; private set; }
|
||||||
public EntityAddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor)
|
public EntityTank(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
BodyKit = bodyKit;
|
BodyKit = bodyKit;
|
63
Tank/Tank/FormTank.Designer.cs
generated
63
Tank/Tank/FormTank.Designer.cs
generated
@ -37,24 +37,23 @@
|
|||||||
buttonArmVechicle = new Button();
|
buttonArmVechicle = new Button();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
|
ChooseCar = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxTank
|
// pictureBoxTank
|
||||||
//
|
//
|
||||||
pictureBoxTank.Location = new Point(1, 0);
|
pictureBoxTank.Location = new Point(1, 0);
|
||||||
pictureBoxTank.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
pictureBoxTank.Name = "pictureBoxTank";
|
pictureBoxTank.Name = "pictureBoxTank";
|
||||||
pictureBoxTank.Size = new Size(913, 599);
|
pictureBoxTank.Size = new Size(799, 428);
|
||||||
pictureBoxTank.TabIndex = 0;
|
pictureBoxTank.TabIndex = 0;
|
||||||
pictureBoxTank.TabStop = false;
|
pictureBoxTank.TabStop = false;
|
||||||
//
|
//
|
||||||
// ButtonCreate
|
// ButtonCreate
|
||||||
//
|
//
|
||||||
ButtonCreate.Location = new Point(14, 500);
|
ButtonCreate.Location = new Point(12, 375);
|
||||||
ButtonCreate.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
ButtonCreate.Name = "ButtonCreate";
|
ButtonCreate.Name = "ButtonCreate";
|
||||||
ButtonCreate.Size = new Size(145, 53);
|
ButtonCreate.Size = new Size(127, 40);
|
||||||
ButtonCreate.TabIndex = 1;
|
ButtonCreate.TabIndex = 1;
|
||||||
ButtonCreate.Text = "Создание танка";
|
ButtonCreate.Text = "Создание танка";
|
||||||
ButtonCreate.UseVisualStyleBackColor = true;
|
ButtonCreate.UseVisualStyleBackColor = true;
|
||||||
@ -65,10 +64,9 @@
|
|||||||
keyDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
keyDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
keyDown.BackgroundImage = Properties.Resources.KeyDown;
|
keyDown.BackgroundImage = Properties.Resources.KeyDown;
|
||||||
keyDown.BackgroundImageLayout = ImageLayout.Stretch;
|
keyDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
keyDown.Location = new Point(821, 515);
|
keyDown.Location = new Point(718, 386);
|
||||||
keyDown.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
keyDown.Name = "keyDown";
|
keyDown.Name = "keyDown";
|
||||||
keyDown.Size = new Size(34, 40);
|
keyDown.Size = new Size(30, 30);
|
||||||
keyDown.TabIndex = 11;
|
keyDown.TabIndex = 11;
|
||||||
keyDown.UseVisualStyleBackColor = true;
|
keyDown.UseVisualStyleBackColor = true;
|
||||||
keyDown.Click += ButtonMove_Click;
|
keyDown.Click += ButtonMove_Click;
|
||||||
@ -78,10 +76,9 @@
|
|||||||
keyUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
keyUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
keyUp.BackgroundImage = Properties.Resources.KeyUp;
|
keyUp.BackgroundImage = Properties.Resources.KeyUp;
|
||||||
keyUp.BackgroundImageLayout = ImageLayout.Stretch;
|
keyUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
keyUp.Location = new Point(821, 467);
|
keyUp.Location = new Point(718, 350);
|
||||||
keyUp.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
keyUp.Name = "keyUp";
|
keyUp.Name = "keyUp";
|
||||||
keyUp.Size = new Size(34, 40);
|
keyUp.Size = new Size(30, 30);
|
||||||
keyUp.TabIndex = 12;
|
keyUp.TabIndex = 12;
|
||||||
keyUp.UseVisualStyleBackColor = true;
|
keyUp.UseVisualStyleBackColor = true;
|
||||||
keyUp.Click += ButtonMove_Click;
|
keyUp.Click += ButtonMove_Click;
|
||||||
@ -91,10 +88,9 @@
|
|||||||
keyLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
keyLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
keyLeft.BackgroundImage = Properties.Resources.KeyLeft;
|
keyLeft.BackgroundImage = Properties.Resources.KeyLeft;
|
||||||
keyLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
keyLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
keyLeft.Location = new Point(779, 515);
|
keyLeft.Location = new Point(682, 386);
|
||||||
keyLeft.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
keyLeft.Name = "keyLeft";
|
keyLeft.Name = "keyLeft";
|
||||||
keyLeft.Size = new Size(34, 40);
|
keyLeft.Size = new Size(30, 30);
|
||||||
keyLeft.TabIndex = 13;
|
keyLeft.TabIndex = 13;
|
||||||
keyLeft.UseVisualStyleBackColor = true;
|
keyLeft.UseVisualStyleBackColor = true;
|
||||||
keyLeft.Click += ButtonMove_Click;
|
keyLeft.Click += ButtonMove_Click;
|
||||||
@ -104,20 +100,18 @@
|
|||||||
keyRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
keyRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
keyRight.BackgroundImage = Properties.Resources.KeyRight;
|
keyRight.BackgroundImage = Properties.Resources.KeyRight;
|
||||||
keyRight.BackgroundImageLayout = ImageLayout.Stretch;
|
keyRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
keyRight.Location = new Point(861, 515);
|
keyRight.Location = new Point(753, 386);
|
||||||
keyRight.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
keyRight.Name = "keyRight";
|
keyRight.Name = "keyRight";
|
||||||
keyRight.Size = new Size(34, 40);
|
keyRight.Size = new Size(30, 30);
|
||||||
keyRight.TabIndex = 14;
|
keyRight.TabIndex = 14;
|
||||||
keyRight.UseVisualStyleBackColor = true;
|
keyRight.UseVisualStyleBackColor = true;
|
||||||
keyRight.Click += ButtonMove_Click;
|
keyRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonArmVechicle
|
// buttonArmVechicle
|
||||||
//
|
//
|
||||||
buttonArmVechicle.Location = new Point(176, 501);
|
buttonArmVechicle.Location = new Point(154, 376);
|
||||||
buttonArmVechicle.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonArmVechicle.Name = "buttonArmVechicle";
|
buttonArmVechicle.Name = "buttonArmVechicle";
|
||||||
buttonArmVechicle.Size = new Size(145, 53);
|
buttonArmVechicle.Size = new Size(127, 40);
|
||||||
buttonArmVechicle.TabIndex = 15;
|
buttonArmVechicle.TabIndex = 15;
|
||||||
buttonArmVechicle.Text = "Создание бронеавтомобиля";
|
buttonArmVechicle.Text = "Создание бронеавтомобиля";
|
||||||
buttonArmVechicle.UseVisualStyleBackColor = true;
|
buttonArmVechicle.UseVisualStyleBackColor = true;
|
||||||
@ -125,10 +119,9 @@
|
|||||||
//
|
//
|
||||||
// buttonStep
|
// buttonStep
|
||||||
//
|
//
|
||||||
buttonStep.Location = new Point(815, 71);
|
buttonStep.Location = new Point(713, 53);
|
||||||
buttonStep.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonStep.Name = "buttonStep";
|
buttonStep.Name = "buttonStep";
|
||||||
buttonStep.Size = new Size(86, 31);
|
buttonStep.Size = new Size(75, 23);
|
||||||
buttonStep.TabIndex = 17;
|
buttonStep.TabIndex = 17;
|
||||||
buttonStep.Text = "Шаг";
|
buttonStep.Text = "Шаг";
|
||||||
buttonStep.UseVisualStyleBackColor = true;
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
@ -138,17 +131,30 @@
|
|||||||
//
|
//
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
||||||
comboBoxStrategy.Location = new Point(749, 24);
|
comboBoxStrategy.Location = new Point(655, 18);
|
||||||
|
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
comboBoxStrategy.Size = new Size(151, 28);
|
comboBoxStrategy.Size = new Size(133, 23);
|
||||||
comboBoxStrategy.TabIndex = 19;
|
comboBoxStrategy.TabIndex = 19;
|
||||||
//
|
//
|
||||||
|
// ChooseCar
|
||||||
|
//
|
||||||
|
ChooseCar.Location = new Point(706, 90);
|
||||||
|
ChooseCar.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ChooseCar.Name = "ChooseCar";
|
||||||
|
ChooseCar.Size = new Size(82, 39);
|
||||||
|
ChooseCar.TabIndex = 20;
|
||||||
|
ChooseCar.Text = "Выбрать технику";
|
||||||
|
ChooseCar.UseVisualStyleBackColor = true;
|
||||||
|
ChooseCar.Click += ButtonSelectTank_Click;
|
||||||
|
//
|
||||||
// FormTank
|
// FormTank
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
BackColor = SystemColors.ButtonHighlight;
|
BackColor = SystemColors.ButtonHighlight;
|
||||||
ClientSize = new Size(914, 568);
|
ClientSize = new Size(800, 426);
|
||||||
|
Controls.Add(ChooseCar);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(buttonArmVechicle);
|
Controls.Add(buttonArmVechicle);
|
||||||
@ -158,9 +164,9 @@
|
|||||||
Controls.Add(keyDown);
|
Controls.Add(keyDown);
|
||||||
Controls.Add(ButtonCreate);
|
Controls.Add(ButtonCreate);
|
||||||
Controls.Add(pictureBoxTank);
|
Controls.Add(pictureBoxTank);
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
|
||||||
Name = "FormTank";
|
Name = "FormTank";
|
||||||
Text = "FormTank";
|
Text = "FormTank";
|
||||||
|
Load += FormTank_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -176,5 +182,6 @@
|
|||||||
private Button buttonArmVechicle;
|
private Button buttonArmVechicle;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button ChooseCar;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,10 +7,13 @@ namespace Tank
|
|||||||
{
|
{
|
||||||
private DrawArmoVehicle? _Tank;
|
private DrawArmoVehicle? _Tank;
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawArmoVehicle? SelectedCar { get; private set; }
|
||||||
|
|
||||||
public FormTank()
|
public FormTank()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedCar = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
@ -18,19 +21,30 @@ namespace Tank
|
|||||||
if (_Tank == null)
|
if (_Tank == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxTank.Width, pictureBoxTank.Height);
|
Bitmap bitmap = new(pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bitmap);
|
||||||
_Tank?.DrawTransport(gr);
|
_Tank?.DrawTransport(gr);
|
||||||
pictureBoxTank.Image = bmp;
|
pictureBoxTank.Image = bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonCreateTank_Click(object sender, EventArgs e)
|
private void ButtonCreateTank_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
Color mainColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
mainColor = dialog.Color;
|
||||||
|
}
|
||||||
|
Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
addColor = dialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
_Tank = new DrawTank(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
_Tank = new DrawTank(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
mainColor, addColor,
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)),
|
Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)),
|
||||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
_Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
_Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||||
@ -66,9 +80,15 @@ namespace Tank
|
|||||||
private void CreateButtonArmoVehicle_Click(object sender, EventArgs e)
|
private void CreateButtonArmoVehicle_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
_Tank = new DrawArmoVehicle(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
_Tank = new DrawArmoVehicle(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
color, pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
|
||||||
|
|
||||||
_Tank.SetPosition(rnd.Next(10, 50), rnd.Next(30, 70));
|
_Tank.SetPosition(rnd.Next(10, 50), rnd.Next(30, 70));
|
||||||
Draw();
|
Draw();
|
||||||
@ -102,5 +122,16 @@ namespace Tank
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectTank_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedCar = _Tank;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormTank_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@
|
|||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -11,7 +11,7 @@ namespace Tank
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormTank());
|
Application.Run(new CollectionsFrame());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
84
Tank/Tank/SetGeneric.cs
Normal file
84
Tank/Tank/SetGeneric.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T> where T : class
|
||||||
|
{
|
||||||
|
private readonly T?[] _places;
|
||||||
|
|
||||||
|
public int Count => _places.Length;
|
||||||
|
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T car)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
for(int i = 0; i < _places.Length; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
index = i; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for(int i = index; i > 0; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
_places[0] = car;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T car, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return -1;
|
||||||
|
if (_places[position] == null)
|
||||||
|
{
|
||||||
|
_places[position] = car;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
int index = -1;
|
||||||
|
for(int i = position; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
index = i; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < 0)
|
||||||
|
return -1;
|
||||||
|
for(int i = index; index > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
_places[position] = car;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return false;
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
96
Tank/Tank/TanksGenericCollection.cs
Normal file
96
Tank/Tank/TanksGenericCollection.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms.VisualStyles;
|
||||||
|
using Tank.DrawningObjects;
|
||||||
|
using Tank.MovementStrategy;
|
||||||
|
|
||||||
|
namespace Tank.Generics
|
||||||
|
{
|
||||||
|
internal class TanksGenericCollection<T, U>
|
||||||
|
where T : DrawArmoVehicle
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private readonly int _placeSizeWidth = 180;
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
public TanksGenericCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
int width = pictureWidth / _placeSizeWidth;
|
||||||
|
int height = pictureHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int? operator +(TanksGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator -(TanksGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowCars()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
//Линия разметки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
DrawArmoVehicle? tank = _collection.Get(i);
|
||||||
|
if (tank == null)
|
||||||
|
continue;
|
||||||
|
tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||||
|
tank.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user