Merge pull request 'PIbd-12_Rotov_I.P._Simple' (#1) from lab1 into main

Reviewed-on: #1
This commit is contained in:
irotov 2025-02-20 11:44:17 +04:00
commit 76f81c1ea6
16 changed files with 775 additions and 62 deletions

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper;
public class EntityStormTrooper
{
//speed
public int Speed { get; private set; }
//weight
public double Weight { get; private set; }
//maincolor
public Color BodyColor { get; private set; }
//additionalcolor
public Color AdditionalColor { get; private set; }
public bool BodyRockets { get; private set; }
public bool Bombs { get; private set; }
//movement
public double Step => Speed * 500 / Weight;
public bool Wing { get; private set; }
public void Init(bool wing, int speed, double weight, Color bodyColor, Color additionalColor, bool bodyRockets, bool bombs)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Wing = wing;
BodyRockets = bodyRockets;
Bombs = bombs;
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper;
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4,
}

View File

@ -0,0 +1,224 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper;
public class DrawingStormTrooper
{
public EntityStormTrooper? EntityStormTrooper { get; private set; }
//windowswidth
private int? _pictureWidth;
private int? _pictureHeight;
private int? _startPosX;
private int? _startPosY;
private readonly int _drawingTrooperWidth = 140;
private readonly int _drawingTrooperHeight = 120;
public void Init(bool wing, int speed, double weight, Color bodyColor, Color additionalColor, bool bodyRockets, bool bombs)
{
EntityStormTrooper = new EntityStormTrooper();
EntityStormTrooper.Init(wing, speed, weight, bodyColor, additionalColor, bodyRockets, bombs);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
public bool SetPictureSize(int width, int height)
{
if (_drawingTrooperHeight > height || _drawingTrooperWidth > width) { return false; }
_pictureWidth = width;
_pictureHeight = height;
return true;
}
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x < 0 || y < 0 || x + _drawingTrooperWidth > _pictureWidth || y + _drawingTrooperHeight > _pictureHeight)
{
return;
}
_startPosX = x;
_startPosY = y;
}
public bool MoveStormTrooper(DirectionType direction)
{
if (EntityStormTrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityStormTrooper.Step > 0)
{
_startPosX -= (int)EntityStormTrooper.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityStormTrooper.Step > 0)
{
_startPosY -= (int)EntityStormTrooper.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityStormTrooper.Step + _drawingTrooperWidth < _pictureWidth)
{
_startPosX += (int)EntityStormTrooper.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityStormTrooper.Step + _drawingTrooperHeight< _pictureHeight)
{
_startPosY += (int)EntityStormTrooper.Step;
}
return true;
default:
return false;
}
}
public void DrawTransport(Graphics g)
{
if (EntityStormTrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return;
Pen pen = new(EntityStormTrooper.BodyColor)
{
Width = 2
};
Pen additionalPen = new(EntityStormTrooper.AdditionalColor)
{
Width = 2
};
Brush brushBlack = new SolidBrush(EntityStormTrooper.BodyColor);
Brush additionalBrush = new SolidBrush(EntityStormTrooper.AdditionalColor);
if (EntityStormTrooper.BodyRockets)
{
// Толщина толстой палочки ракеты
int rocketWidth = 6;
// Длина толстой палочки ракеты
int rocketLength = 15;
PointF[] rocketsTop =
{
new(_startPosX.Value + 90, _startPosY.Value + 13),
new(_startPosX.Value + 90, _startPosY.Value + 33)
};
PointF[] rocketsBottom =
{
new(_startPosX.Value + 90, _startPosY.Value + 103),
new(_startPosX.Value + 90, _startPosY.Value + 123)
};
// Прорисовка ракет на верхнем крыле
foreach (PointF rocketPos in rocketsTop)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - (rocketWidth / 2), rocketLength, rocketWidth);
}
// Прорисовка ракет на нижнем крыле
foreach (PointF rocketPos in rocketsBottom)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - (rocketWidth / 2), rocketLength, rocketWidth);
}
}
// Прорисовка бомб под крыльями
if (EntityStormTrooper.Bombs)
{
int bombWidth = 10;
int bombHeight = 15;
// Позиции бомб под верхним и нижним крылом
PointF[] bombs =
{
new(_startPosX.Value + 75, _startPosY.Value + 15), // Под верхним крылом
new(_startPosX.Value + 75, _startPosY.Value + 105) // Под нижним крылом
};
// Рисуем бомбы
foreach (PointF bombPos in bombs)
{
g.FillEllipse(additionalBrush, bombPos.X, bombPos.Y, bombWidth, bombHeight);
g.DrawEllipse(pen, bombPos.X, bombPos.Y, bombWidth, bombHeight);
}
}
// Определение точек основных элементов объекта
PointF[] front =
{
new(_startPosX.Value + 130, _startPosY.Value + 53),
new(_startPosX.Value + 155, _startPosY.Value + 66),
new(_startPosX.Value + 130, _startPosY.Value + 79)
};
PointF[] tailTop =
{
new(_startPosX.Value, _startPosY.Value + 23),
new(_startPosX.Value, _startPosY.Value + 53),
new(_startPosX.Value + 20, _startPosY.Value + 53),
new(_startPosX.Value + 20, _startPosY.Value + 38)
};
PointF[] tailBottom =
{
new(_startPosX.Value, _startPosY.Value + 79),
new(_startPosX.Value, _startPosY.Value + 109),
new(_startPosX.Value + 20, _startPosY.Value + 94),
new(_startPosX.Value + 20, _startPosY.Value + 79)
};
PointF[] wingTop =
{
new(_startPosX.Value + 90, _startPosY.Value),
new(_startPosX.Value + 90, _startPosY.Value + 53),
new(_startPosX.Value + 60, _startPosY.Value + 53),
new(_startPosX.Value + 75, _startPosY.Value),
};
PointF[] wingBottom =
{
new(_startPosX.Value + 90, _startPosY.Value + 79),
new(_startPosX.Value + 90, _startPosY.Value + 133),
new(_startPosX.Value + 75, _startPosY.Value + 133),
new(_startPosX.Value + 60, _startPosY.Value + 79),
};
// Прорисовка основных элементов объекта
g.FillPolygon(brushBlack, front);
g.DrawPolygon(pen, tailTop);
g.DrawPolygon(pen, tailBottom);
g.DrawPolygon(pen, wingTop);
g.DrawPolygon(pen, wingBottom);
g.DrawRectangle(pen, (int)_startPosX, (int)_startPosY + 53, 130, 26);
}
}

View File

@ -1,46 +0,0 @@
namespace ProjectStormTrooper
{
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()
{
SuspendLayout();
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1138, 450);
Name = "Form1";
Text = "Form1";
Load += Form1_Load;
ResumeLayout(false);
}
#endregion
}
}

View File

@ -1,15 +0,0 @@
namespace ProjectStormTrooper
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -11,7 +11,7 @@ namespace ProjectStormTrooper
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new StormTrooperForm());
}
}
}

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</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>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectStormTrooper.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[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>
/// Returns the cached ResourceManager instance used by this class.
/// </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("ProjectStormTrooper.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrow_down {
get {
object obj = ResourceManager.GetObject("arrow_down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrow_left {
get {
object obj = ResourceManager.GetObject("arrow_left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrow_right {
get {
object obj = ResourceManager.GetObject("arrow_right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrow_up {
get {
object obj = ResourceManager.GetObject("arrow_up", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="arrow_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\arrows\arrow_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrow_left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\arrows\arrow_left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrow_right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\arrows\arrow_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrow_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\arrows\arrow_up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,139 @@
namespace ProjectStormTrooper
{
partial class StormTrooperForm
{
/// <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()
{
buttonCreate = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonDown = new Button();
pictureBox2 = new PictureBox();
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
SuspendLayout();
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 409);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(759, 377);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrow_right;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(831, 377);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrow_up;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(795, 350);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrow_down;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(795, 409);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// pictureBox2
//
pictureBox2.Dock = DockStyle.Fill;
pictureBox2.Location = new Point(0, 0);
pictureBox2.Name = "pictureBox2";
pictureBox2.Size = new Size(882, 453);
pictureBox2.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox2.TabIndex = 6;
pictureBox2.TabStop = false;
pictureBox2.Click += ButtonMove_Click;
//
// StormTrooperForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBox2);
Name = "StormTrooperForm";
StartPosition = FormStartPosition.CenterScreen;
Text = "StormTrooperForm";
Load += StormTrooperForm_Load;
Click += ButtonMove_Click;
((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
private PictureBox pictureBox2;
}
}

View File

@ -0,0 +1,97 @@
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 ProjectStormTrooper
{
public partial class StormTrooperForm : Form
{
private DrawingStormTrooper? _drawingStormTrooper;
public StormTrooperForm()
{
InitializeComponent();
}
public void Draw()
{
if (_drawingStormTrooper == null)
{
return;
}
Bitmap bmp = new(pictureBox2.Width, pictureBox2.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingStormTrooper.DrawTransport(gr);
pictureBox2.Image = bmp;
}
private void PictureBox2_Click(object sender, EventArgs e)
{
}
private void StormTrooperForm_Load(object sender, EventArgs e)
{
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingStormTrooper = new DrawingStormTrooper();
_drawingStormTrooper.Init(Convert.ToBoolean(random.Next(0, 2)), 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)));
_drawingStormTrooper.SetPictureSize(pictureBox2.Width,
pictureBox2.Height);
_drawingStormTrooper.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingStormTrooper == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Up);
break;
case "buttonDown":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Left);
break;
case "buttonRight":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB