PI-14 Lopatin_D.A. LabWork01 Simple1 #1
15
WarmlyLocomotive/DirectionType.cs
Normal file
15
WarmlyLocomotive/DirectionType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive;
|
||||
|
||||
public enum DirectionType
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
182
WarmlyLocomotive/DrawningWarmlyLocomotive.cs
Normal file
182
WarmlyLocomotive/DrawningWarmlyLocomotive.cs
Normal file
@ -0,0 +1,182 @@
|
||||
namespace WarmlyLocomotive;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningWarmlyLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveHeight = 100;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool tube, bool fuelTank)
|
||||
{
|
||||
EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
|
||||
EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor,
|
||||
tube, fuelTank);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityWarmlyLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityWarmlyLocomotive.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityWarmlyLocomotive.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityWarmlyLocomotive.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityWarmlyLocomotive.AdditionalColor);
|
||||
|
||||
//труба
|
||||
if (EntityWarmlyLocomotive.Tube)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 20, 30);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value, 20, 40);
|
||||
}
|
||||
|
||||
//локомотив
|
||||
Brush br = new SolidBrush(EntityWarmlyLocomotive.BodyColor);
|
||||
Brush blBr = new SolidBrush(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 140, 20);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 140, 20);
|
||||
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 60);
|
||||
Point point2 = new Point(_startPosX.Value + 20, _startPosY.Value + 30);
|
||||
Point point3 = new Point(_startPosX.Value + 140, _startPosY.Value + 30);
|
||||
Point point4 = new Point(_startPosX.Value + 140, _startPosY.Value + 60);
|
||||
Point[] body ={point1, point2, point3, point4};
|
||||
g.DrawPolygon(pen, body);
|
||||
g.FillPolygon(br, body);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 140, _startPosY.Value + 40, 10, 40);
|
||||
g.FillRectangle(br, _startPosX.Value + 140, _startPosY.Value + 40, 10, 40);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 80, 20, 20);
|
||||
g.FillEllipse(blBr, _startPosX.Value, _startPosY.Value + 80, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 80, 20, 20);
|
||||
g.FillEllipse(blBr, _startPosX.Value + 30, _startPosY.Value + 80, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 80, 20, 20);
|
||||
g.FillEllipse(blBr, _startPosX.Value + 90, _startPosY.Value + 80, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 120, _startPosY.Value + 80, 20, 20);
|
||||
g.FillEllipse(blBr, _startPosX.Value + 120, _startPosY.Value + 80, 20, 20);
|
||||
|
||||
// отсек для топлива
|
||||
if (EntityWarmlyLocomotive.FuelTank)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
38
WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
38
WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive;
|
||||
|
||||
public class EntityWarmlyLocomotive
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public bool Tube { get; private set; }
|
||||
|
||||
public bool FuelTank { get; private set; }
|
||||
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool tube, bool fuelTank)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Tube = tube;
|
||||
FuelTank = fuelTank;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
partial class Form1
|
||||
partial class Тепловоз
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// 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)
|
||||
@ -23,15 +23,21 @@
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </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 = "Form1";
|
||||
SuspendLayout();
|
||||
//
|
||||
// Тепловоз
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Name = "Тепловоз";
|
||||
Text = "FormWarmlyLocomotive";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
20
WarmlyLocomotive/FormWarmlyLocomotive.cs
Normal file
20
WarmlyLocomotive/FormWarmlyLocomotive.cs
Normal file
@ -0,0 +1,20 @@
|
||||
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 WarmlyLocomotive
|
||||
{
|
||||
public partial class Тепловоз : Form
|
||||
{
|
||||
public Тепловоз()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
-->
|
Loading…
Reference in New Issue
Block a user