Дописал проверки, пересоздал ВинФорму, не работает панель элементов, переустановлю ВС.
This commit is contained in:
parent
c8589815a0
commit
cfb33cac96
@ -71,7 +71,11 @@ namespace WinFormsLabRad1
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// Паша - написать проверку
|
||||
// Паша - написаЛ проверку:
|
||||
if (width <= _drawningTankWidth || height <= _drawningTankHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
@ -85,15 +89,72 @@ namespace WinFormsLabRad1
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
int endx = x + _drawningTankWidth;
|
||||
|
||||
int endy = y + _drawningTankHeight;
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// Паша - написать проверку
|
||||
// Паша - написаЛ проверку
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (endx > _pictureWidth || x < 0 || endy > _pictureHeight || y<0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityTankZU == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityTankZU.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityTankZU.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosX.Value + EntityTankZU.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosY.Value + EntityTankZU.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs
generated
10
WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs
generated
@ -3,12 +3,12 @@
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
@ -23,8 +23,8 @@
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
@ -36,4 +36,4 @@
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,13 @@
|
||||
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 WinFormsLabRad1
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
Loading…
x
Reference in New Issue
Block a user