lab1 release
This commit is contained in:
parent
635b9a84bd
commit
d35129e2c1
@ -23,12 +23,19 @@ public class DrawingAircraftCarrier
|
||||
|
||||
public void SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawingCarHeight > height || _drawingCarWidth > width) return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return;
|
||||
|
||||
if (x < 0 || y < 0 ||
|
||||
x+_drawingCarWidth > _pictureWidth ||
|
||||
y+_drawingCarHeight > _pictureHeight) return;
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
@ -97,12 +104,12 @@ public class DrawingAircraftCarrier
|
||||
|
||||
if (EntityAircraftCarrier.HasDeck)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 40, 55, 20);
|
||||
g.FillRectangle(brushPC, _startPosX.Value + 50, _startPosY.Value + 40, 55, 20);
|
||||
}
|
||||
|
||||
if (EntityAircraftCarrier.HasСabin)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 105, _startPosY.Value + 25, 30, 50);
|
||||
g.FillRectangle(brushSC, _startPosX.Value + 105, _startPosY.Value + 25, 30, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +121,10 @@
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAircraftCarrier);
|
||||
KeyPreview = true;
|
||||
Name = "FormAircraftCarrier";
|
||||
Text = "FormAircraftCarrier";
|
||||
KeyDown += FormAircraftCarrier_KeyDown;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public partial class FormAircraftCarrier : Form
|
||||
_drawingAircraftCarrier.Init(random.Next(100, 200), random.Next(1000, 2000),
|
||||
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)));
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawingAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
|
||||
_drawingAircraftCarrier.SetPosition(10, 10);
|
||||
|
||||
@ -55,7 +55,35 @@ public partial class FormAircraftCarrier : Form
|
||||
break;
|
||||
}
|
||||
|
||||
if (directionType.HasValue) {
|
||||
if (directionType.HasValue)
|
||||
{
|
||||
_drawingAircraftCarrier.MoveAircraftCarrier(directionType.Value);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void FormAircraftCarrier_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (_drawingAircraftCarrier == null) return;
|
||||
DirectionType? directionType = null;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.W:
|
||||
directionType = DirectionType.Up;
|
||||
break;
|
||||
case Keys.S:
|
||||
directionType = DirectionType.Down;
|
||||
break;
|
||||
case Keys.A:
|
||||
directionType = DirectionType.Left;
|
||||
break;
|
||||
case Keys.D:
|
||||
directionType = DirectionType.Right;
|
||||
break;
|
||||
}
|
||||
|
||||
if (directionType.HasValue)
|
||||
{
|
||||
_drawingAircraftCarrier.MoveAircraftCarrier(directionType.Value);
|
||||
Draw();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user