Лабораторная работа №1 (изменение корабля)
This commit is contained in:
parent
4166c6d002
commit
901523325e
@ -41,39 +41,40 @@ public class DrawningBattleship
|
||||
/// Ширина прорисовки корабля
|
||||
/// </summary>
|
||||
|
||||
private readonly int _drawningBattleshipWidth = 110;
|
||||
private readonly int _drawningBattleshipWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки корабля
|
||||
/// </summary>
|
||||
|
||||
private readonly int _drawningBattleshipHeight = 65;
|
||||
private readonly int _drawningBattleshipHeight = 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="weapon">Признак наличия оружия</param>
|
||||
/// <param name="rockets">Признак наличия отсека ракет</param>
|
||||
/// <param name="turret">Признак наличия орудийной башни</param>
|
||||
/// <param name="rocketCompartment">Признак наличия отсека под ракеты</param>
|
||||
///<param name="weapon">Признак наличия отсека под ракеты</param>
|
||||
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.Init(speed, weight, bodyColor, additionalColor, bodyKit, weapon, rockets);
|
||||
EntityBattleship.Init(speed, weight, bodyColor, additionalColor,
|
||||
turret, rocketCompartment, weapon);
|
||||
_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)
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
@ -158,18 +159,28 @@ public class DrawningBattleship
|
||||
int y = _startPosY.Value;
|
||||
|
||||
// Корпус корабля
|
||||
g.FillRectangle(bodyBrush, x + 15, y + 40, 80, 30);
|
||||
g.DrawRectangle(pen, x + 15, y + 40, 80, 30);
|
||||
|
||||
// Нос корабля (треугольник)
|
||||
Point[] nose = {
|
||||
new Point(x + 95, y + 40),
|
||||
new Point(x + 95, y + 70),
|
||||
new Point(x + 110, y + 55)
|
||||
Point[] body = new Point[] {
|
||||
new Point(x + 5, y),
|
||||
new Point(x + 100, y),
|
||||
new Point(x + 150, y + 25),
|
||||
new Point(x + 100, y + 50),
|
||||
new Point(x + 5, y + 50)
|
||||
};
|
||||
g.FillPolygon(bodyBrush, nose);
|
||||
g.DrawPolygon(pen, nose);
|
||||
// Пушки (реалистичные)
|
||||
g.FillPolygon(bodyBrush, body);
|
||||
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)
|
||||
{
|
||||
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.DrawLine(pen, x + 86, y + 30, x + 86, y + 35);
|
||||
}
|
||||
|
||||
// Ракеты (улучшены)
|
||||
if (EntityBattleship.Rockets)
|
||||
// Отсек под ракеты
|
||||
if (EntityBattleship.RocketCompartment)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, x + 25, y + 50, 6, 15);
|
||||
g.DrawRectangle(pen, x + 25, y + 50, 6, 15);
|
||||
g.FillEllipse(additionalBrush, x + 27, y + 45, 4, 4);
|
||||
|
||||
g.FillRectangle(additionalBrush, x + 79, y + 50, 6, 15);
|
||||
g.DrawRectangle(pen, x + 79, y + 50, 6, 15);
|
||||
g.FillEllipse(additionalBrush, x + 81, y + 45, 4, 4);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
int offsetX = 14 + (i * 12);
|
||||
int offsetY = 14 + (j * 12);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,46 +15,45 @@
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// Признак наличия орудийной башни
|
||||
/// </summary>
|
||||
public bool Turret { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия отсека под ракеты
|
||||
/// </summary>
|
||||
public bool RocketCompartment { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения корабля
|
||||
/// </summary>
|
||||
|
||||
public bool Weapon { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
|
||||
public bool Tower { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool Rockets { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// Признак наличия оружия
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / 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="weapon">Признак наличия оружия</param>
|
||||
/// <param name="rockets">Признак наличия отсека ракет</param>
|
||||
/// <param name="turret">Признак наличия орудийной башни</param>
|
||||
/// <param name="rocketCompartment">Признак наличия отсека под ракеты</param>
|
||||
///<param name="weapon">Признак наличия отсека под ракеты</param>
|
||||
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;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Turret = turret;
|
||||
RocketCompartment = rocketCompartment;
|
||||
Weapon = weapon;
|
||||
Rockets = rockets;
|
||||
}
|
||||
|
||||
|
||||
|
39
Battleship/Battleship/Form1.Designer.cs
generated
Normal file
39
Battleship/Battleship/Form1.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
10
Battleship/Battleship/Form1.cs
Normal file
10
Battleship/Battleship/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Battleship
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
120
Battleship/Battleship/Form1.resx
Normal file
120
Battleship/Battleship/Form1.resx
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user