Доделал

This commit is contained in:
Алексей Тихоненков 2023-10-12 20:51:18 +04:00
parent cb138fd554
commit a0db4e8315
5 changed files with 73 additions and 104 deletions

View File

@ -35,11 +35,11 @@ namespace AntiAircraftGun
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _carWidth = 110;
private readonly int _zenitWidth = 110;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _carHeight = 60;
private readonly int _zenitHeight = 60;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -54,7 +54,8 @@ namespace AntiAircraftGun
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, Color dopColor, bool rocket, bool radar, int width, int height)
{
// TODO: Продумать проверки
if (width <= _zenitWidth || height <= _zenitHeight) return false;
_pictureWidth = width;
_pictureHeight = height;
AntiAircraftGun = new EntityAntiAircraftGun();
@ -68,9 +69,14 @@ namespace AntiAircraftGun
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y
if (AntiAircraftGun == null) return;
_startPosX = x;
_startPosY = y;
if (x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
}
/// <summary>
/// Изменение направления перемещения
@ -82,14 +88,6 @@ namespace AntiAircraftGun
{
return;
}
FormAntiAirCraftGun form1 = new FormAntiAirCraftGun();
Size windowSize = form1.Size;
int windowWidth = windowSize.Width;
int windowHeight = windowSize.Height;
// Теперь вы можете получить ширину и высоту отдельно, если это необходимо
switch (direction)
{
//влево
@ -108,14 +106,14 @@ namespace AntiAircraftGun
break;
// вправо
case DirectionType.Right:
if (_startPosX + AntiAircraftGun.Step < windowWidth-150)
if (_startPosX + AntiAircraftGun.Step < _pictureWidth-110)
{
_startPosX += (int)AntiAircraftGun.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + AntiAircraftGun.Step < windowHeight-100)
if (_startPosY + AntiAircraftGun.Step < _pictureHeight-60)
{
_startPosY += (int)AntiAircraftGun.Step;
}
@ -149,8 +147,6 @@ namespace AntiAircraftGun
g.DrawEllipse(pen, trackRect);
g.FillEllipse(Brushes.Black, trackRect);
}
Brush dopBrush = new SolidBrush(AntiAircraftGun.DopColor);
Pen dopPen = new Pen(AntiAircraftGun.DopColor);
if (AntiAircraftGun.Rocket)
@ -169,12 +165,6 @@ namespace AntiAircraftGun
g.DrawLine(dopPen, _startPosX + 98, _startPosY, _startPosX + 93, _startPosY + 10);
g.FillEllipse(dopBrush, _startPosX + 88, _startPosY -10, 10, 10);
}
}
}
}

View File

@ -28,11 +28,17 @@ namespace AntiAircraftGun
/// Шаг перемещения автомобиля
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Цвет для доп. деталей
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Ракета
/// </summary>
public bool Rocket { get; private set; }
/// <summary>
/// Радар
/// </summary>
public bool Radar { get; private set; }
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля

View File

@ -2,34 +2,34 @@
{
partial class FormAntiAirCraftGun
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 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)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// 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)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
this.Create = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
@ -47,16 +47,16 @@
this.pictureBoxAntiAircraftGun.TabIndex = 0;
this.pictureBoxAntiAircraftGun.TabStop = false;
//
// Create
// buttonCreate
//
this.Create.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.Create.Location = new System.Drawing.Point(32, 577);
this.Create.Name = "Create";
this.Create.Size = new System.Drawing.Size(75, 23);
this.Create.TabIndex = 1;
this.Create.Text = "Создать";
this.Create.UseVisualStyleBackColor = true;
this.Create.Click += new System.EventHandler(this.Create_Click_1);
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(32, 577);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonLeft
//
@ -106,7 +106,7 @@
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// Form1
// FormAntiAirCraftGun
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -115,23 +115,24 @@
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.Create);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxAntiAircraftGun);
this.Name = "Form1";
this.Name = "FormAntiAirCraftGun";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
}
#endregion
#endregion
private PictureBox pictureBoxAntiAircraftGun;
private Button Create;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
}
private PictureBox pictureBoxAntiAircraftGun;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
}
}

View File

@ -37,11 +37,7 @@ namespace AntiAircraftGun
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBoxZenit_Click(object sender, EventArgs e)
{
@ -62,11 +58,7 @@ namespace AntiAircraftGun
pictureBoxAntiAircraftGun.Image = bmp;
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawing == null)
@ -91,8 +83,7 @@ namespace AntiAircraftGun
}
Draw();
}
private void Create_Click_1(object sender, EventArgs e)
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawing = new DrawingAntiAirCraftGun();
@ -102,7 +93,7 @@ namespace AntiAircraftGun
random.Next(0, 256)),
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)), // Äîï. öâåò2
Convert.ToBoolean(random.Next(2)), // Rocket
Convert.ToBoolean(random.Next(2)), // Radar
@ -111,8 +102,9 @@ namespace AntiAircraftGun
_drawing.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
public class Vopros
{
private int _id;
public int change_id { set { _id = value; } }
public void Change(int id)
{
change_id = id;
}
}
}