Lisov N.A. Lab_work2 #2

Merged
eegov merged 11 commits from LabWork02 into LabWork01 2022-09-30 09:43:17 +04:00
6 changed files with 172 additions and 6 deletions
Showing only changes of commit 80197437fa - Show all commits

View File

@ -34,8 +34,108 @@ namespace AirFighter
public Bitmap MoveObject(Direction direction)
{
//ПРОВЕРКА НА СТОЛКНОВЕНИЕ
if (true)
int CollisionFlag = 0;
Size objSize1 = new Size(100,100);
//COLLISION CHECK
if (direction == Direction.Up)
{
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
Point LeftTop = new Point((int)_drawingObject.GetCurrentPosition().Left, (int)(_drawingObject.GetCurrentPosition().Top - _drawingObject.Step));
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)(_size_y));
if (objectRect.Contains(rectBarrier))
{
CollisionFlag = 1;
}
}
}
}
}
else if (direction == Direction.Down)
{
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
Point LeftTop = new Point((int)_drawingObject.GetCurrentPosition().Left, (int)(_drawingObject.GetCurrentPosition().Top + _drawingObject.Step));
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
if (objectRect.Contains(rectBarrier))
{
CollisionFlag = 1;
}
}
}
}
}
else if (direction == Direction.Left)
{
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left - _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
if (objectRect.Contains(rectBarrier))
{
CollisionFlag = 1;
}
}
}
}
}
else if (direction == Direction.Right)
{
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left + _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
if (objectRect.Contains(rectBarrier))
{
CollisionFlag = 1;
}
}
}
}
}
if (CollisionFlag != 1)
{
_drawingObject.MoveObject(direction);
}
@ -53,7 +153,7 @@ namespace AirFighter
int x = _random.Next(0, 10);
int y = _random.Next(0,10);
_drawingObject.SetObject(x, y, _width, _height);
//ПРОВЕРКА ЕСТЬ ЛИ УЖЕ НА ЭТОМ МЕСТЕ ОБЪЕКТ
//CHECK IF BARRIER IS ALREADY SPAWANED ON OBJECT SPAWN
return true;
}

View File

@ -242,7 +242,7 @@ namespace AirFighter
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _aircraftWidth, _startPosY + _aircraftHeight);
}

View File

@ -157,7 +157,8 @@
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxMapSelection.FormattingEnabled = true;
this.comboBoxMapSelection.Items.AddRange(new object[] {
"1. Simple map"});
"1. Simple map",
"2. NightSky map"});
this.comboBoxMapSelection.Location = new System.Drawing.Point(12, 12);
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
this.comboBoxMapSelection.Size = new System.Drawing.Size(121, 23);

View File

@ -91,6 +91,11 @@ namespace AirFighter
_abstractMap = new SimpleMap();
}
break;
case "2. NightSky map":
{
_abstractMap = new NightSkyMap();
}
break;
}
}
}

60
AirFighter/NightSkyMap.cs Normal file
View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class NightSkyMap : AbstractMap
{
Brush ThundercloudColor = new SolidBrush(Color.FromArgb(0, 0, 139));
Brush NightSkyColor = new SolidBrush(Color.Black);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(ThundercloudColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(NightSkyColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
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 < 20)
{
int x = _random.Next(10,90);
int y = _random.Next(10,90);
_map[x, y] = _barrier;
_map[x-1,y] = _barrier;
_map[x + 1, y] = _barrier;
_map[x,y - 1] = _barrier;
counter++;
}
}
}
}

View File

@ -34,7 +34,7 @@ namespace AirFighter
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_random.Next(0, 50) == 5)
if (_random.Next(0, 90) == 5)
{
_map[i, j] = _barrier;
}