Готовая 1 лаба
This commit is contained in:
parent
ca3ac93b3e
commit
bb608311d0
32
Tank/Tank/Direction.cs
Normal file
32
Tank/Tank/Direction.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
223
Tank/Tank/DrawingTank.cs
Normal file
223
Tank/Tank/DrawingTank.cs
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningTank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityTank? EntityTank { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
private int _pictureWidth = 900;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
private int _pictureHeight = 500;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private int _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя кооридната прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private int _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _tankWidth = 110;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _tankHeight = 60;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="trunk">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
/// <returns>true - объект создан, false - проверка не пройдена,
|
||||||
|
/// нельзя создать объект в этих размерах</returns>
|
||||||
|
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bodyKit, bool trunk, bool sportLine, int width, int height)
|
||||||
|
{
|
||||||
|
// TODO: проверки
|
||||||
|
if (width > _tankWidth && height > _tankHeight && speed > 0 && weight > 0)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityTank = new EntityTank();
|
||||||
|
EntityTank.Init(speed, weight, bodyColor, additionalColor,
|
||||||
|
bodyKit, trunk, sportLine);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
// проверки
|
||||||
|
if (x >= 0 && x + _tankWidth <= _pictureWidth &&
|
||||||
|
y >= 0 && y + _tankHeight <= _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (EntityTank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case Direction.Left:
|
||||||
|
if (_startPosX - EntityTank.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityTank.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case Direction.Up:
|
||||||
|
if (_startPosY - EntityTank.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityTank.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case Direction.Right:
|
||||||
|
if (_startPosX + EntityTank.Step + _tankWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityTank.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case Direction.Down:
|
||||||
|
if (_startPosY + EntityTank.Step + _tankHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityTank.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityTank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new
|
||||||
|
SolidBrush(EntityTank.AdditionalColor);
|
||||||
|
// гусеница
|
||||||
|
Rectangle Caterpillar = new Rectangle(_startPosX + 2, _startPosY + 35, 16, 22);
|
||||||
|
float startAngle_Caterpillar = 90;
|
||||||
|
float sweepAngle_Caterpillar = 180;
|
||||||
|
g.DrawArc(pen, Caterpillar, startAngle_Caterpillar, sweepAngle_Caterpillar);
|
||||||
|
Rectangle Caterpillar2 = new Rectangle(_startPosX + 102, _startPosY + 35, 16, 22);
|
||||||
|
float startAngle_Caterpillar2 = 270;
|
||||||
|
float sweepAngle_Caterpillar2 = 180;
|
||||||
|
g.DrawArc(pen, Caterpillar2, startAngle_Caterpillar2, sweepAngle_Caterpillar2);
|
||||||
|
Point startPoint = new Point(_startPosX + 10, _startPosY + 58);
|
||||||
|
Point endPoint = new Point(_startPosX + 110, _startPosY + 58);
|
||||||
|
g.DrawLine(pen, startPoint, endPoint);
|
||||||
|
// колеса
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
|
||||||
|
// колеса снизу поменьше
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 47, 10, 10);
|
||||||
|
// колеса сверху
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 32, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 32, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 75, _startPosY + 32, 10, 10);
|
||||||
|
|
||||||
|
//кузов
|
||||||
|
Brush br = new SolidBrush(EntityTank.BodyColor);
|
||||||
|
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
|
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
|
||||||
|
// пулемет
|
||||||
|
g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
|
|
||||||
|
// зенитный пулемет на башне
|
||||||
|
g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
|
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
|
||||||
|
|
||||||
|
//выделяем рамкой весь танк
|
||||||
|
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
|
|
||||||
|
// обвесы
|
||||||
|
if (EntityTank.BodyKit)
|
||||||
|
{
|
||||||
|
Brush brAdd = new SolidBrush(EntityTank.AdditionalColor);
|
||||||
|
|
||||||
|
g.FillRectangle(brAdd, _startPosX + 5, _startPosY + 17, 20, 18);
|
||||||
|
g.FillRectangle(brAdd, _startPosX + 95, _startPosY + 17, 20, 18);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 20, 18);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 95, _startPosY + 17, 20, 18);
|
||||||
|
|
||||||
|
g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//// спортивная линия
|
||||||
|
//if (EntityTank.SportLine)
|
||||||
|
//{
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 75,
|
||||||
|
// _startPosY + 23, 25, 15);
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||||
|
// _startPosY + 23, 35, 15);
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 10,
|
||||||
|
// _startPosY + 23, 20, 15);
|
||||||
|
//}
|
||||||
|
// багажник
|
||||||
|
if (EntityTank.Trunk)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4 , 8, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
Tank/Tank/EntityTank.cs
Normal file
66
Tank/Tank/EntityTank.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
public class EntityTank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
/// </summary>
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия обвеса
|
||||||
|
/// </summary>
|
||||||
|
public bool BodyKit { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия Багажника
|
||||||
|
/// </summary>
|
||||||
|
public bool Trunk { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия гоночной полосы
|
||||||
|
/// </summary>
|
||||||
|
public bool SportLine { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения танка
|
||||||
|
/// </summary>
|
||||||
|
public double Step => (double)Speed * 200 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес Танка</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="trunk">Признак наличия багажника</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bodyKit, bool trunk, bool sportLine)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
BodyKit = bodyKit;
|
||||||
|
Trunk = trunk;
|
||||||
|
SportLine = sportLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
Tank/Tank/Form1.Designer.cs
generated
39
Tank/Tank/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace Tank
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace Tank
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
135
Tank/Tank/FormTank.Designer.cs
generated
Normal file
135
Tank/Tank/FormTank.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
partial class FormTank
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
this.pictureBoxTank = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxTank
|
||||||
|
//
|
||||||
|
this.pictureBoxTank.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBoxTank.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBoxTank.Name = "pictureBoxTank";
|
||||||
|
this.pictureBoxTank.Size = new System.Drawing.Size(884, 461);
|
||||||
|
this.pictureBoxTank.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
|
this.pictureBoxTank.TabIndex = 0;
|
||||||
|
this.pictureBoxTank.TabStop = false;
|
||||||
|
this.pictureBoxTank.Click += new System.EventHandler(this.pictureBox1_Click);
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
this.buttonCreate.Location = new System.Drawing.Point(26, 417);
|
||||||
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
|
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCreate.TabIndex = 1;
|
||||||
|
this.buttonCreate.Text = "Создать";
|
||||||
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonUp.BackgroundImage = global::Tank.Properties.Resources.upper_arrow;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(806, 381);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonUp.TabIndex = 2;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonLeft.BackgroundImage = global::Tank.Properties.Resources.left_arrow;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(770, 417);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonLeft.TabIndex = 3;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonDown.BackgroundImage = global::Tank.Properties.Resources.down_arrow;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(806, 417);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonDown.TabIndex = 4;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::Tank.Properties.Resources.right_arrow;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(842, 417);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonRight.TabIndex = 5;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// FormTank
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||||
|
this.Controls.Add(this.buttonRight);
|
||||||
|
this.Controls.Add(this.buttonDown);
|
||||||
|
this.Controls.Add(this.buttonLeft);
|
||||||
|
this.Controls.Add(this.buttonUp);
|
||||||
|
this.Controls.Add(this.buttonCreate);
|
||||||
|
this.Controls.Add(this.pictureBoxTank);
|
||||||
|
this.Name = "FormTank";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Tank";
|
||||||
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxTank;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
}
|
||||||
|
}
|
99
Tank/Tank/FormTank.cs
Normal file
99
Tank/Tank/FormTank.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
namespace Tank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñïîðòèâíûé àâòîìîáèëü"
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormTank : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||||
|
/// </summary>
|
||||||
|
private DrawningTank? _drawningTank;
|
||||||
|
/// <summary>
|
||||||
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||||
|
/// </summary>
|
||||||
|
public FormTank()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||||
|
/// </summary>
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningTank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxTank.Width,
|
||||||
|
pictureBoxTank.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningTank.DrawTransport(gr);
|
||||||
|
pictureBoxTank.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pictureBox1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
// Ñîçäàíèå Tank
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningTank = new DrawningTank();
|
||||||
|
_drawningTank.Init(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)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
|
||||||
|
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
|
_drawningTank.SetPosition(random.Next(10, 100),
|
||||||
|
random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningTank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawningTank.MoveTransport(Direction.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawningTank.MoveTransport(Direction.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawningTank.MoveTransport(Direction.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawningTank.MoveTransport(Direction.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Tank/Tank/FormTank.resx
Normal file
60
Tank/Tank/FormTank.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<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>
|
@ -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 Form1());
|
Application.Run(new FormTank());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
103
Tank/Tank/Properties/Resources.Designer.cs
generated
Normal file
103
Tank/Tank/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace Tank.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tank.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap down_arrow {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("down-arrow", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap left_arrow {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("left-arrow", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap right_arrow {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("right-arrow", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap upper_arrow {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("upper-arrow", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -117,4 +117,17 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="down-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="left-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="right-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="upper-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
BIN
Tank/Tank/Resources/down-arrow.png
Normal file
BIN
Tank/Tank/Resources/down-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
BIN
Tank/Tank/Resources/left-arrow.png
Normal file
BIN
Tank/Tank/Resources/left-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 B |
BIN
Tank/Tank/Resources/right-arrow.png
Normal file
BIN
Tank/Tank/Resources/right-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 224 B |
BIN
Tank/Tank/Resources/upper-arrow.png
Normal file
BIN
Tank/Tank/Resources/upper-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
@ -8,4 +8,19 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<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>
|
</Project>
|
Loading…
Reference in New Issue
Block a user