Абстрактный класс.
This commit is contained in:
parent
bfced67c39
commit
c8d2e3c46d
@ -31,9 +31,76 @@ namespace Stormtrooper
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
//TODO
|
||||
if (true)
|
||||
{
|
||||
int LefTopX = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x);
|
||||
int LefTopY = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y);
|
||||
int objwidth = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x);
|
||||
int objheigh = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y);
|
||||
|
||||
bool CanStep = true;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
for (int i = LefTopX; i >= Math.Abs(LefTopX - Convert.ToInt32(_drawningObject.Step / _size_x)); i--)
|
||||
{
|
||||
for (int j = LefTopY; j <= objheigh && j<_map.GetLength(1); j++)
|
||||
{
|
||||
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Right:
|
||||
for (int i = objwidth; i <= objwidth + Convert.ToInt32(_drawningObject.Step / _size_x) && i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = LefTopY; j <= objheigh && j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Direction.Down:
|
||||
for (int i = LefTopX; i <= objwidth && i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = objheigh; j <= objheigh + Convert.ToInt32(_drawningObject.Step / _size_y) && j < _map.GetLength(1); j++)
|
||||
{
|
||||
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case Direction.Up:
|
||||
for (int i = LefTopX; i <= objwidth && i<_map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = LefTopY; j >= Math.Abs(LefTopY - Convert.ToInt32(_drawningObject.Step / _size_y)) ; j--)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (CanStep)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
@ -45,10 +112,24 @@ namespace Stormtrooper
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
int x = _random.Next(0, 150);
|
||||
int y = _random.Next(100, 300);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (i * _size_x >= x && j * _size_y <= y &&
|
||||
i * _size_x <= x + _drawningObject.GetCurrentPosition().Right &&
|
||||
j * _size_y >= j - _drawningObject.GetCurrentPosition().Bottom && _map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
|
||||
return true;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
@ -60,19 +141,13 @@ namespace Stormtrooper
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawRoadPart(gr, i, j);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
if (_map[i, j] == 1) DrawBarrierPart(gr, i, j);
|
||||
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ namespace Stormtrooper
|
||||
g.FillPolygon(brBl, N);
|
||||
|
||||
//фюзеляж
|
||||
Brush brGr = new SolidBrush(Color.Gray);
|
||||
Brush brGr = new SolidBrush(Color.White);
|
||||
g.FillRectangle(brGr, _startPosX + 20, _startPosY - 60, 100, 20);
|
||||
|
||||
//крыло и стаб
|
||||
@ -184,6 +184,7 @@ namespace Stormtrooper
|
||||
g.FillPolygon(br, S);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
/// </summary>
|
||||
@ -214,7 +215,7 @@ namespace Stormtrooper
|
||||
/// <returns></returns>
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _StormWidth, _startPosY + _StormHeight);
|
||||
return (_startPosX, _startPosX + _StormWidth, _startPosY - _StormHeight, _startPosY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace Stormtrooper
|
||||
{
|
||||
Storm = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bodyKit, rocket, sportLine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Storm is not EntityMilitaryStormtrooper militaryTrop)
|
||||
|
@ -28,6 +28,8 @@ namespace Stormtrooper
|
||||
}
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
if (_storm is DrawningMilitary)
|
||||
((DrawningMilitary)_storm).DrawTransport(g);
|
||||
_storm.DrawTransport(g);
|
||||
}
|
||||
|
||||
|
27
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
27
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
@ -46,11 +46,10 @@
|
||||
//
|
||||
// pictureBoxStormtrooper
|
||||
//
|
||||
this.pictureBoxStormtrooper.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxStormtrooper.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxStormtrooper.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
|
||||
this.pictureBoxStormtrooper.Size = new System.Drawing.Size(914, 446);
|
||||
this.pictureBoxStormtrooper.Size = new System.Drawing.Size(1000, 500);
|
||||
this.pictureBoxStormtrooper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxStormtrooper.TabIndex = 0;
|
||||
this.pictureBoxStormtrooper.TabStop = false;
|
||||
@ -62,10 +61,10 @@
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 446);
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 501);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
|
||||
this.statusStrip.Size = new System.Drawing.Size(914, 26);
|
||||
this.statusStrip.Size = new System.Drawing.Size(1000, 26);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
@ -89,7 +88,7 @@
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(14, 392);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(14, 447);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(86, 31);
|
||||
@ -103,7 +102,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(815, 334);
|
||||
this.buttonUp.Location = new System.Drawing.Point(901, 389);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
@ -117,7 +116,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(770, 382);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(856, 437);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
@ -131,7 +130,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(858, 382);
|
||||
this.buttonRight.Location = new System.Drawing.Point(944, 437);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
@ -145,7 +144,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(815, 382);
|
||||
this.buttonDown.Location = new System.Drawing.Point(901, 437);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
@ -157,7 +156,7 @@
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(116, 392);
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(116, 447);
|
||||
this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(126, 31);
|
||||
@ -171,8 +170,10 @@
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 16);
|
||||
"Простая карта",
|
||||
"Ясное небо",
|
||||
"Пасмурное небо"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 13);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28);
|
||||
@ -183,7 +184,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(914, 472);
|
||||
this.ClientSize = new System.Drawing.Size(1000, 527);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
|
@ -79,7 +79,7 @@ namespace Stormtrooper
|
||||
var storm = new DrawningMilitary(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(storm);
|
||||
}
|
||||
|
||||
@ -90,6 +90,12 @@ namespace Stormtrooper
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Ясное небо":
|
||||
_abstractMap = new SecondMap();
|
||||
break;
|
||||
case "Пасмурное небо":
|
||||
_abstractMap = new ThirdMap();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,6 +61,6 @@
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>51</value>
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
52
Stormtrooper/Stormtrooper/SecondMap.cs
Normal file
52
Stormtrooper/Stormtrooper/SecondMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class SecondMap:AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x+3, _size_y+3);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 30)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,13 +18,11 @@ namespace Stormtrooper
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||
1), j * (_size_y + 1));
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||
1), j * (_size_y + 1));
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
|
69
Stormtrooper/Stormtrooper/ThirdMap.cs
Normal file
69
Stormtrooper/Stormtrooper/ThirdMap.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class ThirdMap:AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightGray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x + 3, _size_y + 3);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 30)
|
||||
{
|
||||
int x = _random.Next(0, 30);
|
||||
int y = _random.Next(0, 30);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
|
||||
x = _random.Next(70, 100);
|
||||
y = _random.Next(0, 30);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
|
||||
x = _random.Next(40, 60);
|
||||
y = _random.Next(50, 90);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user