доабвил форму
This commit is contained in:
parent
36e2fba235
commit
d00147fea5
154
RoadTrain/RoadTrain/RoadTrain.Designer.cs
generated
154
RoadTrain/RoadTrain/RoadTrain.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user