-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormShip.cs
69 lines (67 loc) · 2.14 KB
/
FormShip.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 WindowsFormsCars
{
public partial class FormShip : Form
{
private Ship ship;
public FormShip()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxShip.Width, pictureBoxShip.Height);
Graphics gr = Graphics.FromImage(bmp);
ship.DrawShip(gr);
pictureBoxShip.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
ship = new Ship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.Blue,
Color.Gray, true, true, true);
ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width,
pictureBoxShip.Height);
Draw();
}
/// <summary>
/// Обработка нажатия кнопок управления
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = (sender as Button).Name;
switch (name)
{
case "buttonUp":
ship.MoveTransport(Direction.Up);
break;
case "buttonDown":
ship.MoveTransport(Direction.Down);
break;
case "buttonLeft":
ship.MoveTransport(Direction.Left);
break;
case "buttonRight":
ship.MoveTransport(Direction.Right);
break;
}
Draw();
}
}
}