Лабораторная работа №1 (изменение корабля)

This commit is contained in:
v.ignatkin 2025-02-13 15:10:48 +04:00
parent 4166c6d002
commit 901523325e
5 changed files with 252 additions and 57 deletions

View File

@ -41,39 +41,40 @@ public class DrawningBattleship
/// Ширина прорисовки корабля /// Ширина прорисовки корабля
/// </summary> /// </summary>
private readonly int _drawningBattleshipWidth = 110; private readonly int _drawningBattleshipWidth = 150;
/// <summary> /// <summary>
/// Высота прорисовки корабля /// Высота прорисовки корабля
/// </summary> /// </summary>
private readonly int _drawningBattleshipHeight = 65; private readonly int _drawningBattleshipHeight = 60;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса спортивного корабля /// Инициализация корабля
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param> /// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="turret">Признак наличия орудийной башни</param>
/// <param name="weapon">Признак наличия оружия</param> /// <param name="rocketCompartment">Признак наличия отсека под ракеты</param>
/// <param name="rockets">Признак наличия отсека ракет</param> ///<param name="weapon">Признак наличия отсека под ракеты</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool weapon, bool rockets) additionalColor, bool turret, bool rocketCompartment, bool weapon)
{ {
EntityBattleship = new EntityBattleship(); EntityBattleship = new EntityBattleship();
EntityBattleship.Init(speed, weight, bodyColor, additionalColor, bodyKit, weapon, rockets); EntityBattleship.Init(speed, weight, bodyColor, additionalColor,
turret, rocketCompartment, weapon);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
_startPosY = null; _startPosY = null;
} }
/// <summary> /// <summary>
/// Установка границ поля /// Установка границ поля
/// </summary> /// </summary>
/// <param name="width">Ширина поля</param> /// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param> /// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
@ -158,18 +159,28 @@ public class DrawningBattleship
int y = _startPosY.Value; int y = _startPosY.Value;
// Корпус корабля // Корпус корабля
g.FillRectangle(bodyBrush, x + 15, y + 40, 80, 30); Point[] body = new Point[] {
g.DrawRectangle(pen, x + 15, y + 40, 80, 30); new Point(x + 5, y),
new Point(x + 100, y),
// Нос корабля (треугольник) new Point(x + 150, y + 25),
Point[] nose = { new Point(x + 100, y + 50),
new Point(x + 95, y + 40), new Point(x + 5, y + 50)
new Point(x + 95, y + 70),
new Point(x + 110, y + 55)
}; };
g.FillPolygon(bodyBrush, nose); g.FillPolygon(bodyBrush, body);
g.DrawPolygon(pen, nose); g.DrawPolygon(pen, body);
// Пушки (реалистичные)
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, x, y + 6, 5, 13);
g.FillRectangle(brBlack, x, y + 31, 5, 13);
Brush brDark = new SolidBrush(Color.DarkGray);
g.FillRectangle(brDark, x + 39, y + 20, 40, 10);
g.DrawRectangle(pen, x + 39, y + 20, 40, 10);
g.FillRectangle(brDark, x + 70, y + 12, 18, 26);
g.DrawRectangle(pen, x + 70, y + 12, 18, 26);
g.FillEllipse(brBlack, x + 94, y + 19, 12, 12);
// Пушки
if (EntityBattleship.Weapon) if (EntityBattleship.Weapon)
{ {
g.FillRectangle(additionalBrush, x + 20, y + 35, 8, 20); g.FillRectangle(additionalBrush, x + 20, y + 35, 8, 20);
@ -180,19 +191,35 @@ public class DrawningBattleship
g.DrawRectangle(pen, x + 82, y + 35, 8, 20); g.DrawRectangle(pen, x + 82, y + 35, 8, 20);
g.DrawLine(pen, x + 86, y + 30, x + 86, y + 35); g.DrawLine(pen, x + 86, y + 30, x + 86, y + 35);
} }
// Отсек под ракеты
// Ракеты (улучшены) if (EntityBattleship.RocketCompartment)
if (EntityBattleship.Rockets)
{ {
g.FillRectangle(additionalBrush, x + 25, y + 50, 6, 15); for (int i = 0; i < 2; i++)
g.DrawRectangle(pen, x + 25, y + 50, 6, 15); {
g.FillEllipse(additionalBrush, x + 27, y + 45, 4, 4); for (int j = 0; j < 2; j++)
{
g.FillRectangle(additionalBrush, x + 79, y + 50, 6, 15); int offsetX = 14 + (i * 12);
g.DrawRectangle(pen, x + 79, y + 50, 6, 15); int offsetY = 14 + (j * 12);
g.FillEllipse(additionalBrush, x + 81, y + 45, 4, 4); g.FillRectangle(additionalBrush, x + offsetX, y + offsetY, 10, 10);
g.DrawRectangle(pen, x + offsetX, y + offsetY, 10, 10);
}
}
} }
// Орудийная башня
if (EntityBattleship.Turret)
{
Point[] turret = new Point[] {
new Point(x + 112, y + 19),
new Point(x + 112, y + 31),
new Point(x + 119, y + 28),
new Point(x + 119, y + 22)
};
g.FillPolygon(additionalBrush, turret);
g.FillRectangle(additionalBrush, x + 119, y + 24, 12, 2);
g.DrawPolygon(pen, turret);
g.DrawRectangle(pen, x + 119, y + 24, 12, 2);
}
} }
} }

View File

@ -15,46 +15,45 @@
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия обвеса /// Признак наличия орудийной башни
/// </summary>
public bool Turret { get; private set; }
/// <summary>
/// Признак наличия отсека под ракеты
/// </summary>
public bool RocketCompartment { get; private set; }
/// <summary>
/// Шаг перемещения корабля
/// </summary> /// </summary>
public bool Weapon { get; private set; } public bool Weapon { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия гоночной полосы /// Признак наличия оружия
/// </summary>
public bool Tower { get; private set; }
/// <summary>
/// Признак (опция) наличия гоночной полосы
/// </summary>
public bool Rockets { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary> /// </summary>
public double Step => Speed * 100 / Weight; public double Step => Speed * 100 / Weight;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля /// Инициализация полей объекта-класса корабля
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param> /// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="turret">Признак наличия орудийной башни</param>
/// <param name="weapon">Признак наличия оружия</param> /// <param name="rocketCompartment">Признак наличия отсека под ракеты</param>
/// <param name="rockets">Признак наличия отсека ракет</param> ///<param name="weapon">Признак наличия отсека под ракеты</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool weapon, bool rockets) additionalColor, bool turret, bool rocketCompartment, bool weapon)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
Turret = turret;
RocketCompartment = rocketCompartment;
Weapon = weapon; Weapon = weapon;
Rockets = rockets;
} }

39
Battleship/Battleship/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,39 @@
namespace Battleship
{
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
}
}

View File

@ -0,0 +1,10 @@
namespace Battleship
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?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>
</root>