Storage(two_Forms)

This commit is contained in:
Inna Pruidze 2024-04-28 12:36:36 +04:00
parent 3e17af2218
commit d01d7cf012
34 changed files with 789 additions and 136 deletions

Binary file not shown.

View File

@ -1,34 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<ForceDesignerDPIUnaware>true</ForceDesignerDPIUnaware>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Simplify.Windows.Forms" Version="1.1.3" />
<PackageReference Include="System.Windows.Extensions" Version="8.0.0" />
<PackageReference Include="System.Windows.Forms.Pictograms" Version="1.3.22" />
<PackageReference Include="System.Windows.Forms.Ribbon35" Version="3.5.8" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CruiserMech", "CruiserMech\CruiserMech.csproj", "{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinF_Lab2_Cruiser", "WinF_Lab2_Cruiser\WinF_Lab2_Cruiser.csproj", "{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Release|Any CPU.Build.0 = Release|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7A9FCCBC-7DB9-4CE7-AA8B-6C609F3E0FB0}
SolutionGuid = {23A421F3-C54C-4554-B468-133A363BD9CD}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,174 @@
namespace WinF_Lab2_Cruiser
{
partial class CollectionForm
{
/// <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()
{
ToolBox = new GroupBox();
Check = new Button();
RandomGenerator = new Button();
RemoveButton = new Button();
maskedTextBox1 = new MaskedTextBox();
Add2Button = new Button();
AddButton = new Button();
comboBox1 = new ComboBox();
pictureBox1 = new PictureBox();
ToolBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
SuspendLayout();
//
// ToolBox
//
ToolBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ToolBox.Controls.Add(Check);
ToolBox.Controls.Add(RandomGenerator);
ToolBox.Controls.Add(RemoveButton);
ToolBox.Controls.Add(maskedTextBox1);
ToolBox.Controls.Add(Add2Button);
ToolBox.Controls.Add(AddButton);
ToolBox.Controls.Add(comboBox1);
ToolBox.Location = new Point(1042, 12);
ToolBox.Name = "ToolBox";
ToolBox.Size = new Size(207, 701);
ToolBox.TabIndex = 0;
ToolBox.TabStop = false;
ToolBox.Text = "Tools";
//
// Check
//
Check.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
Check.Location = new Point(34, 629);
Check.Name = "Check";
Check.Size = new Size(150, 46);
Check.TabIndex = 6;
Check.Text = "Check";
Check.UseVisualStyleBackColor = true;
Check.Click += Check_Click;
//
// RandomGenerator
//
RandomGenerator.Anchor = AnchorStyles.Right;
RandomGenerator.Location = new Point(34, 391);
RandomGenerator.Name = "RandomGenerator";
RandomGenerator.Size = new Size(150, 140);
RandomGenerator.TabIndex = 5;
RandomGenerator.Text = "Generator Random";
RandomGenerator.UseVisualStyleBackColor = true;
RandomGenerator.Click += RandomGenerator_Click;
//
// RemoveButton
//
RemoveButton.Location = new Point(34, 275);
RemoveButton.Name = "RemoveButton";
RemoveButton.Size = new Size(150, 46);
RemoveButton.TabIndex = 4;
RemoveButton.Text = "Delete";
RemoveButton.UseVisualStyleBackColor = true;
RemoveButton.Click += RemoveButton_Click;
//
// maskedTextBox1
//
maskedTextBox1.Anchor = AnchorStyles.Right;
maskedTextBox1.Location = new Point(6, 214);
maskedTextBox1.Mask = "00";
maskedTextBox1.Name = "maskedTextBox1";
maskedTextBox1.Size = new Size(198, 39);
maskedTextBox1.TabIndex = 3;
maskedTextBox1.ValidatingType = typeof(int);
//
// Add2Button
//
Add2Button.Anchor = AnchorStyles.Right;
Add2Button.Location = new Point(6, 146);
Add2Button.Name = "Add2Button";
Add2Button.Size = new Size(198, 46);
Add2Button.TabIndex = 2;
Add2Button.Text = "Advanced";
Add2Button.UseVisualStyleBackColor = true;
Add2Button.Click += Add2Button_Click;
//
// AddButton
//
AddButton.Anchor = AnchorStyles.Right;
AddButton.Location = new Point(6, 94);
AddButton.Name = "AddButton";
AddButton.Size = new Size(198, 46);
AddButton.TabIndex = 1;
AddButton.Text = "Base";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += AddButton_Click;
//
// comboBox1
//
comboBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "Storage" });
comboBox1.Location = new Point(6, 38);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(198, 40);
comboBox1.TabIndex = 0;
comboBox1.SelectedIndexChanged += comboBox_SelectedIndexChanged;
//
// pictureBox1
//
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
pictureBox1.Dock = DockStyle.Left;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(1036, 723);
pictureBox1.TabIndex = 3;
pictureBox1.TabStop = false;
//
// CollectionForm
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1259, 723);
Controls.Add(pictureBox1);
Controls.Add(ToolBox);
Name = "CollectionForm";
Text = "CollectionForm";
ToolBox.ResumeLayout(false);
ToolBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox ToolBox;
private ComboBox comboBox1;
private Button AddButton;
private Button Add2Button;
private MaskedTextBox maskedTextBox1;
private PictureBox pictureBox1;
private Button RemoveButton;
private Button RandomGenerator;
private Button Check;
}
}

View File

@ -0,0 +1,151 @@
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;
using WinF_Lab2_Cruiser.CollectionGenericObjects;
using WinF_Lab2_Cruiser.Drawing_tools;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace WinF_Lab2_Cruiser
{
public partial class CollectionForm : Form
{
private AbstractCompany _Company;
public CollectionForm()
{
InitializeComponent();
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "Storage":
_Company = new NewClassCollection(pictureBox1.Width, pictureBox1.Height, new ArrayAlg<DrawingBase>());
break;
}
}
private static Color GetColor(Random r)
{
Color cl = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{ cl = dialog.Color; }
return cl;
}
private void CreateObject(string type)
{
if (_Company == null)
{
return;
}
Random rn = new Random();
DrawingBase Transport;
switch (type)
{
case nameof(DrawingBase):
Transport = new DrawingBase(rn.Next(100, 300), rn.Next(1000, 3000), GetColor(rn));
break;
case nameof(DrawingCruiser):
Class_CruiserEntity Obj = new Class_CruiserEntity(rn.Next(100, 300), rn.Next(1000, 3000),
GetColor(rn), GetColor(rn), Convert.ToBoolean(rn.Next(0, 2)),
Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
Transport = new DrawingCruiser(Obj);
break;
default:
return;
}
if (_Company + Transport > 0)
{
MessageBox.Show("> Object was added");
pictureBox1.Image = _Company.Show();
}
else { MessageBox.Show("[!] Failed to add object"); }
}
private void AddButton_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBase));
private void Add2Button_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingCruiser));
private void RemoveButton_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBox1?.Text) || _Company == null) { return; }
if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
if (_Company - Convert.ToInt32(maskedTextBox1.Text) != null)
{
MessageBox.Show("> Object was removed");
pictureBox1.Image = _Company.Show();
}
else { MessageBox.Show("[!] No object to be removed"); }
}
private void RandomGenerator_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
int counter = 100;
DrawingBase? drBase = null;
while (drBase == null)
{
drBase = _Company.GetRandomObj();
counter--;
if (counter <= 0)
{
break;
}
}
if (drBase == null)
{
return;
}
DrawingCanvas Form = new DrawingCanvas();
/*
DrawingCanvas Form = new() { SetTransport = drBase };
*/
Form.SetTransport = drBase;
Form.ShowDialog();
// ----------------------------------------------------------
}
private void Check_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
pictureBox1.Image = _Company.Show();
}
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public abstract class AbstractCompany
{
protected readonly int _placeSizeWidth = 302;
protected readonly int _placeSizeHeight = 46;
protected readonly int _picW, _picH;
protected ICGO<DrawingBase>? _Array = null;
// max num of vehicles
private int GetMaxCount => _picW * _picH / (_placeSizeWidth * _placeSizeHeight);
public AbstractCompany(int SizeWidth, int SizeHeight, ICGO<DrawingBase>? array)
{
_picW = SizeWidth;
_picH = SizeHeight;
_Array = array;
_Array.SetMaxCount = GetMaxCount;
}
// insted of bool:
public static int operator +(AbstractCompany cmp,
DrawingBase trasport) => (cmp._Array.Insert(trasport));
public static DrawingBase operator -(AbstractCompany cmp,
int pos) => (cmp._Array.Remove(pos));
public DrawingBase? GetRandomObj()
{
Random r = new();
return _Array?.GetItem(r.Next(GetMaxCount));
}
public Bitmap? Show()
{
Bitmap bitmap = new(_picW, _picH);
Graphics Gr = Graphics.FromImage(bitmap);
DrawBackgound(Gr);
SetObjectsPosition();
for (int i = 0; i < (_Array?.Count ?? 0); ++i)
{
DrawingBase? obj = _Array?.GetItem(i);
obj?.DrawTransport(Gr);
}
return bitmap;
}
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();
}
}

View File

@ -0,0 +1,101 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public class ArrayAlg<K> : ICGO<K>
where K : class
{
private K?[] _Array;
public ArrayAlg()
{
_Array = Array.Empty<K?>();
}
public int Count => _Array.Length;
public int SetMaxCount { set { if (value > 0) { _Array = new K?[value]; } } }
public K? GetItem(int index)
{
if (index > Count || index < 0)
{
return null;
}
return _Array[index];
}
public int Insert(K item)
{
// any empty place
for (int i = 0; i < Count; i++)
{
if (_Array[i] == null)
{
_Array[i] = item;
return i;
}
}
return -1;
}
public int Insert(int index, K item)
{
if (_Array[index] == null)
{
_Array[index] = item;
return index;
}
else
{
int min_diff = 100, min_index = 100;
for (int i = 0; i < Count; i++)
{
if (_Array[i] == null && min_diff > Math.Abs(index - i))
{
min_diff = Math.Abs(index - i);
min_index = i;
}
}
_Array[min_index] = item;
return min_index;
}
return -1;
}
public K Remove(int index)
{
K item;
if (index < Count && index >= 0)
{
item = _Array[index];
_Array[index] = null;
return item;
}
return null;
}
/*
public bool Remove(int index)
{
K item;
if (index < Count)
{
item = _Array[index];
_Array[index] = null;
return true;
}
return false;
}
*/
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public interface ICGO<K> // U>
where K : class // ссылочный тип
// where U : struct // 2nd dop task
{
int Count { get; }
int SetMaxCount { set; }
int Insert(K item);
int Insert(int index, K item);
K? Remove(int index);
//bool Remove(int index);
K? GetItem(int index);
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
internal class NewClassCollection : AbstractCompany // service
{
private int startCoordX = 10, startCoordY = 10, between = 30;
public int maxWkolvo { get; private set; }
public int maxHkolvo { get; private set; }
public NewClassCollection(int SizeWidth, int SizeHeight, ICGO<DrawingBase>? array) : base(SizeWidth, SizeHeight, array)
{
maxWkolvo = _picW / (_placeSizeWidth + between);
maxHkolvo = _picH / _placeSizeHeight;
}
protected override void DrawBackgound(Graphics g)
{
Pen pen = new(Color.Black, 2);
int currentH = 10, currentW = 10;
for (int i = 0; i < maxWkolvo; i++)
{
currentH = 10;
for (int j = 0; j < maxHkolvo; j++)
{
g.DrawLine(pen, currentW + 302, currentH - 1, currentW - 1, currentH - 1);
g.DrawLine(pen, currentW - 1, currentH - 1, currentW - 1, currentH + 50);
currentH += _placeSizeHeight + 1; // + between;
}
currentW += _placeSizeWidth + between;
}
}
protected override void SetObjectsPosition()
{
int index_collection = 0;
int newX = startCoordX, newY = startCoordY;
if (_Array != null)
{
for(int i = 0; i < maxHkolvo; ++i)
{
newX = startCoordX;
for (int j = 0; j < maxWkolvo; ++j)
{
if (_Array.GetItem(index_collection) != null)
{
_Array.GetItem(index_collection).SetPicSize(_picW, _picH);
_Array.GetItem(index_collection).SetPos(newX, newY);
newX += _placeSizeWidth + between;
index_collection++;
}
}
newY += _placeSizeHeight + 2;
}
}
}
}
}

View File

@ -1,9 +1,5 @@
using System.Drawing.Printing;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
using System.Xml.Linq;
namespace CruiserMech

namespace WinF_Lab2_Cruiser
{
partial class DrawingCanvas
{
@ -34,8 +30,6 @@ namespace CruiserMech
private void InitializeComponent()
{
pictureBox1 = new PictureBox();
CreateButton = new Button();
CreateButton2 = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonDown = new Button();
@ -56,29 +50,6 @@ namespace CruiserMech
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
//
// CreateButton
//
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateButton.Location = new Point(22, 465);
CreateButton.Margin = new Padding(6);
CreateButton.Name = "CreateButton";
CreateButton.Size = new Size(139, 113);
CreateButton.TabIndex = 1;
CreateButton.Text = "Create object";
CreateButton.UseVisualStyleBackColor = true;
CreateButton.Click += buttonCr_Click;
//
// CreateButton2
//
CreateButton2.Location = new Point(22, 26);
CreateButton2.Margin = new Padding(6);
CreateButton2.Name = "CreateButton2";
CreateButton2.Size = new Size(139, 113);
CreateButton2.TabIndex = 2;
CreateButton2.Text = "Cr Updated Object";
CreateButton2.UseVisualStyleBackColor = true;
CreateButton2.Click += buttonCr2_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -131,9 +102,6 @@ namespace CruiserMech
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// ListComboBox
//
//
// ButtonActivate
//
ButtonActivate.Anchor = AnchorStyles.Right;
@ -145,18 +113,18 @@ namespace CruiserMech
ButtonActivate.UseVisualStyleBackColor = true;
ButtonActivate.Click += comboBox_Activate;
//
// comboBox1
// comboBox
//
comboBox.FormattingEnabled = true;
comboBox.Items.AddRange(new object[] { "Center", "Boarder" });
comboBox.Location = new Point(188, 26);
comboBox.Name = "Directions";
comboBox.Location = new Point(22, 27);
comboBox.Name = "comboBox";
comboBox.Size = new Size(203, 40);
comboBox.TabIndex = 9;
//
// Activate
//
Activate.Location = new Point(188, 93);
Activate.Location = new Point(22, 84);
Activate.Name = "Activate";
Activate.Size = new Size(203, 46);
Activate.TabIndex = 10;
@ -177,8 +145,6 @@ namespace CruiserMech
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(CreateButton);
Controls.Add(CreateButton2);
Controls.Add(pictureBox1);
Controls.Add(ButtonActivate);
Margin = new Padding(4, 2, 4, 2);
@ -190,8 +156,8 @@ namespace CruiserMech
}
#endregion
private PictureBox pictureBox1;
private Button CreateButton;
private Button CreateButton2;
//private Button CreateButton;
//private Button CreateButton2;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
@ -200,4 +166,4 @@ namespace CruiserMech
private ComboBox comboBox;
private Button Activate;
}
}
}

View File

@ -1,23 +1,32 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
using WinF_Lab2_Cruiser.Entity_Folder;
using WinF_Lab2_Cruiser.Move_Strategy;
using System.Windows.Forms;
using CruiserMech.Drawing_tools;
using CruiserMech.Entity_Folder;
using CruiserMech.Move_Strategy;
namespace CruiserMech
namespace WinF_Lab2_Cruiser
{
public partial class DrawingCanvas : Form
{
private DrawingBase? _DrCruiser;
private AbstractStrategy _strategy;
private AbstractStrategy? _strategy;
public DrawingBase SetTransport
{
set
{
_DrCruiser = value;
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
comboBox.Enabled = true;
_strategy = null;
Draw();
}
}
public DrawingCanvas()
{
InitializeComponent();
_strategy = null;
// DrawBackgound(Gr);
}
//private DrawingCanvas_Load(object sender, EventArgs e);
private void Draw()
@ -29,8 +38,10 @@ namespace CruiserMech
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp); _DrCruiser.DrawTransport(gr);
pictureBox1.Image = bmp;
// DrawBackgound(gr);
}
/*
private void CreateObj(string type)
{
Random rn = new Random();
@ -54,6 +65,12 @@ namespace CruiserMech
Draw();
}
private void buttonCr2_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingCruiser));
private void buttonCr_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingBase));
*/
private void comboBox_Activate(object sender, EventArgs e)
{
if (_DrCruiser == null) return;
@ -83,8 +100,6 @@ namespace CruiserMech
}
}
private void buttonCr2_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingCruiser));
private void buttonCr_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingBase));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_DrCruiser == null)
@ -92,8 +107,7 @@ namespace CruiserMech
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
bool result = false; switch (name)
{
case "buttonUp":
result = _DrCruiser.MoveTransport(DirectionType.Up);

View 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>

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Drawing_tools
namespace WinF_Lab2_Cruiser.Drawing_tools
{
public enum DirectionType
{

View File

@ -4,9 +4,9 @@ using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Entity_Folder;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace CruiserMech.Drawing_tools
namespace WinF_Lab2_Cruiser.Drawing_tools
{
public class DrawingBase
{

View File

@ -4,9 +4,9 @@ using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Entity_Folder;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace CruiserMech.Drawing_tools
namespace WinF_Lab2_Cruiser.Drawing_tools
{
internal class DrawingCruiser : DrawingBase
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Entity_Folder
namespace WinF_Lab2_Cruiser.Entity_Folder
{
public class Base_Class_Cruiser
{

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Entity_Folder
namespace WinF_Lab2_Cruiser.Entity_Folder
{
internal class Class_CruiserEntity : Base_Class_Cruiser
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public abstract class AbstractStrategy
{
@ -64,6 +64,8 @@ namespace CruiserMech.Move_Strategy
return _movableObj?.GetStep;
}
// protected virtual void AdditionalMethod() { }
protected virtual void MoveToTarget()
{
ObjectParam? objParams = GetObjParam;
@ -93,7 +95,7 @@ namespace CruiserMech.Move_Strategy
if (objParams == null) { return false; }
return objParams.MiddleHorizontal - GetStep() <= FieldWidth / 2 &&
objParams.MiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.MiddleHorizontal + GetStep() + 1 >= FieldWidth / 2 &&
objParams.MiddleVertical - GetStep() <= FieldHeight / 2 &&
objParams.MiddleVertical + GetStep() >= FieldHeight / 2;
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy;
namespace WinF_Lab2_Cruiser.Move_Strategy;
public class Boarder : AbstractStrategy
{
@ -16,8 +16,8 @@ public class Boarder : AbstractStrategy
return false;
}
return FieldWidth - GetStep() < objP.SecondCoordX
&& FieldHeight - GetStep() < objP.SecondCoordY;
return FieldWidth < objP.SecondCoordX
&& FieldHeight < objP.SecondCoordY;
}
protected override void MoveToTarget()
@ -31,7 +31,7 @@ public class Boarder : AbstractStrategy
int s = (int)GetStep();
int diffx = objP.SecondCoordX - (FieldWidth - s);
if (Math.Abs(diffx) > GetStep())
if (Math.Abs(diffx) >= GetStep())
{
if (diffx > 0)
{
@ -43,7 +43,7 @@ public class Boarder : AbstractStrategy
}
int diffy = objP.SecondCoordY - (FieldHeight - s);
if (Math.Abs(diffy) > GetStep())
if (Math.Abs(diffy) >= GetStep())
{
if (diffy > 0)
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy;
namespace WinF_Lab2_Cruiser.Move_Strategy;
public class Center : AbstractStrategy
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public interface IMO
{
@ -14,6 +14,8 @@ namespace CruiserMech.Move_Strategy
int GetStep { get; }
int AdditionalMethod { set; }
bool TryMoveObj(Moves direction);
}
}

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Drawing_tools;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public class MovableCruiser : IMO
{
@ -31,6 +31,8 @@ namespace CruiserMech.Move_Strategy
public int GetStep => (int)(_DrBase?.BaseEntity?.Step ?? 0);
public int AdditionalMethod { set => throw new NotImplementedException(); }
public bool TryMoveObj(Moves direction)
{
if (_DrBase == null || _DrBase.BaseEntity == null)

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public enum Moves
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public class ObjectParam
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public enum Status
{

View File

@ -1,4 +1,4 @@
namespace CruiserMech
namespace WinF_Lab2_Cruiser
{
internal static class Program
{
@ -11,7 +11,8 @@ namespace CruiserMech
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new DrawingCanvas());
// Application.Run(new DrawingCanvas());
Application.Run(new CollectionForm());
}
}
}

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace CruiserMech.Properties {
namespace WinF_Lab2_Cruiser.Properties {
using System;
@ -39,7 +39,7 @@ namespace CruiserMech.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CruiserMech.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinF_Lab2_Cruiser.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
@ -90,16 +90,6 @@ namespace CruiserMech.Properties {
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap up_arrow {
get {
object obj = ResourceManager.GetObject("up_arrow", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>

View File

@ -121,9 +121,6 @@
<data name="right_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up_arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up_arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View File

Before

Width:  |  Height:  |  Size: 940 B

After

Width:  |  Height:  |  Size: 940 B

View File

Before

Width:  |  Height:  |  Size: 905 B

After

Width:  |  Height:  |  Size: 905 B

View File

Before

Width:  |  Height:  |  Size: 877 B

After

Width:  |  Height:  |  Size: 877 B

View File

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>