доабвил форму

This commit is contained in:
spacyboy 2023-11-22 03:27:45 +04:00
parent 36e2fba235
commit d00147fea5
3 changed files with 279 additions and 36 deletions

View File

@ -28,12 +28,158 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "RoadTrain";
buttonDown = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
pictureBoxRoadTrain = new PictureBox();
buttonStep = new Button();
comboBoxStrategy = new ComboBox();
button1 = new Button();
buttonCreateRoadTrain = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit();
SuspendLayout();
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.ForeColor = SystemColors.ControlText;
buttonDown.Location = new Point(718, 418);
buttonDown.Margin = new Padding(3, 2, 3, 2);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(26, 22);
buttonDown.TabIndex = 12;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.ForeColor = SystemColors.ControlText;
buttonLeft.Location = new Point(686, 418);
buttonLeft.Margin = new Padding(3, 2, 3, 2);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(26, 22);
buttonLeft.TabIndex = 11;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.ForeColor = SystemColors.ControlText;
buttonUp.Location = new Point(718, 391);
buttonUp.Margin = new Padding(3, 2, 3, 2);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(26, 22);
buttonUp.TabIndex = 10;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.ForeColor = SystemColors.ControlText;
buttonRight.Location = new Point(749, 417);
buttonRight.Margin = new Padding(3, 2, 3, 2);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(26, 22);
buttonRight.TabIndex = 9;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// pictureBoxRoadTrain
//
pictureBoxRoadTrain.Dock = DockStyle.Fill;
pictureBoxRoadTrain.Location = new Point(0, 0);
pictureBoxRoadTrain.Margin = new Padding(3, 2, 3, 2);
pictureBoxRoadTrain.Name = "pictureBoxRoadTrain";
pictureBoxRoadTrain.Size = new Size(800, 450);
pictureBoxRoadTrain.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxRoadTrain.TabIndex = 7;
pictureBoxRoadTrain.TabStop = false;
//
// buttonStep
//
buttonStep.Location = new Point(650, 41);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.TabIndex = 16;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(624, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 23);
comboBoxStrategy.TabIndex = 15;
//
// button1
//
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
button1.Location = new Point(228, 388);
button1.Name = "button1";
button1.Size = new Size(122, 50);
button1.TabIndex = 14;
button1.Text = "Создать машину";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonCreate_Click;
//
// buttonCreateRoadTrain
//
buttonCreateRoadTrain.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateRoadTrain.Location = new Point(24, 388);
buttonCreateRoadTrain.Name = "buttonCreateRoadTrain";
buttonCreateRoadTrain.Size = new Size(198, 50);
buttonCreateRoadTrain.TabIndex = 13;
buttonCreateRoadTrain.Text = "Создать машину с баком под воду или щеткой";
buttonCreateRoadTrain.UseVisualStyleBackColor = true;
buttonCreateRoadTrain.Click += buttonCreateRoadTrain_Click;
//
// RoadTrain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(button1);
Controls.Add(buttonCreateRoadTrain);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(pictureBoxRoadTrain);
Name = "RoadTrain";
Text = "RoadTrain";
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
public PictureBox pictureBoxRoadTrain;
private Button buttonStep;
private ComboBox comboBoxStrategy;
private Button button1;
private Button buttonCreateRoadTrain;
}
}

View File

@ -1,20 +1,117 @@
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 RoadTrain.DrawingObjects;
using RoadTrain.MovementStrategy;
namespace RoadTrain
{
public partial class RoadTrain : Form
{
private DrawingRoadTrain? _drawingRoadTrain;
private AbstractStrategy? _abstractStrategy;
public RoadTrain()
{
InitializeComponent();
}
private void Draw()
{
if (_drawingRoadTrain == null)
{
return;
}
Bitmap bmp = new(pictureBoxRoadTrain.Width,
pictureBoxRoadTrain.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingRoadTrain.DrawTransport(gr);
pictureBoxRoadTrain.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingRoadTrain = new DrawingRoadTrain(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
_drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonCreateRoadTrain_Click(object sender, EventArgs e)
{
Random random = new();
_drawingRoadTrain = new DrawingRoadTrainWithTank(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
_drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingRoadTrain == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingRoadTrain.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingRoadTrain.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingRoadTrain.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingRoadTrain.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingRoadTrain == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawingObjectTrain(_drawingRoadTrain), pictureBoxRoadTrain.Width,
pictureBoxRoadTrain.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->