Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laba5 Sokolova #6

Open
wants to merge 3 commits into
base: laba4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Boat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public void SetPosition(int x, int y, int width, int height)
_pictureWidth = width;
_pictureHeight = height;
}
public void SetMainColor(Color color)
{
MainColor = color;
}
public abstract void DrawShip(Graphics g);
public abstract void MoveTransport(Direction direction);
}
Expand Down
36 changes: 16 additions & 20 deletions FormDock.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 39 additions & 52 deletions FormDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ public partial class FormDock : Form
/// </summary>
MultiLevelDock dock;

/// <summary>
/// Форма для добавления
/// </summary>
FormShipConfig form;

/// <summary>
/// Количество уровней-парковок
/// </summary>
private const int countLevel = 5;

public cancelDelegate c;
public FormDock()
{
InitializeComponent();


dock = new MultiLevelDock(countLevel, pictureBoxDock.Width,
pictureBoxDock.Height);
//заполнение listBox
Expand All @@ -51,57 +59,6 @@ private void Draw()
}
}
/// <summary>
/// Обработка нажатия кнопки "Швартовать корабль"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSetShip_Click(object sender, EventArgs e)
{
if (listBoxLevels.SelectedIndex > -1)
{
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
var ship = new Ship(100, 1000, dialog.Color);
int place = dock[listBoxLevels.SelectedIndex] + ship;
if (place == -1)
{
MessageBox.Show("Нет свободных мест", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Draw();
}
}
}
/// <summary>
/// Обработка нажатия кнопки "Швартовать лайнер"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSetLiner_Click(object sender, EventArgs e)
{
if (listBoxLevels.SelectedIndex > -1)
{
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
ColorDialog dialogDop = new ColorDialog();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
var car = new Ship_Liner(100, 1000, dialog.Color, dialogDop.Color,
true, true, true);
int place = dock[listBoxLevels.SelectedIndex] + car;
if (place == -1)
{
MessageBox.Show("Нет свободных мест", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Draw();
}
}
}
}
/// <summary>
/// Обработка нажатия кнопки "Забрать"
/// </summary>
/// <param name="sender"></param>
Expand Down Expand Up @@ -142,6 +99,36 @@ private void buttonTakeShip_Click(object sender, EventArgs e)
private void listBoxLevels_SelectedIndexChanged(object sender, EventArgs e)
{
Draw();
}
}
/// <summary>
/// Обработка нажатия кнопки "Заказать корабль"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSetShip_Click(object sender, EventArgs e)
{
form = new FormShipConfig();
form.AddEvent(AddShip);
form.Show();
}
/// <summary>
/// Метод добавления корабля
/// </summary>
/// <param name="ship"></param>
private void AddShip(IShip ship)
{
if (ship != null && listBoxLevels.SelectedIndex > -1)
{
int place = dock[listBoxLevels.SelectedIndex] + ship;
if (place > -1)
{
Draw();
}
else
{
MessageBox.Show("Корабль не удалось пришвартовать");
}
}
}
}
}
Loading