изменил stream

This commit is contained in:
marusya 2023-11-15 19:45:11 +04:00
parent 733f7f5a51
commit fa5fcdf346
3 changed files with 93 additions and 124 deletions

View File

@ -71,11 +71,9 @@
groupBox1.Controls.Add(numericUpDownSpeed); groupBox1.Controls.Add(numericUpDownSpeed);
groupBox1.Controls.Add(label2); groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1); groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(14, 16); groupBox1.Location = new Point(12, 12);
groupBox1.Margin = new Padding(3, 4, 3, 4);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
groupBox1.Padding = new Padding(3, 4, 3, 4); groupBox1.Size = new Size(454, 228);
groupBox1.Size = new Size(519, 304);
groupBox1.TabIndex = 0; groupBox1.TabIndex = 0;
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Параметры"; groupBox1.Text = "Параметры";
@ -83,9 +81,9 @@
// labelModifiedObject // labelModifiedObject
// //
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(358, 195); labelModifiedObject.Location = new Point(313, 146);
labelModifiedObject.Name = "labelModifiedObject"; labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(99, 35); labelModifiedObject.Size = new Size(87, 27);
labelModifiedObject.TabIndex = 8; labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый"; labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
@ -94,9 +92,9 @@
// labelSimpleObject // labelSimpleObject
// //
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(246, 195); labelSimpleObject.Location = new Point(215, 146);
labelSimpleObject.Name = "labelSimpleObject"; labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(99, 35); labelSimpleObject.Size = new Size(87, 27);
labelSimpleObject.TabIndex = 7; labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой"; labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
@ -112,102 +110,91 @@
groupBox2.Controls.Add(panelGreen); groupBox2.Controls.Add(panelGreen);
groupBox2.Controls.Add(panelWhite); groupBox2.Controls.Add(panelWhite);
groupBox2.Controls.Add(panelRed); groupBox2.Controls.Add(panelRed);
groupBox2.Location = new Point(246, 43); groupBox2.Location = new Point(215, 32);
groupBox2.Margin = new Padding(3, 4, 3, 4);
groupBox2.Name = "groupBox2"; groupBox2.Name = "groupBox2";
groupBox2.Padding = new Padding(3, 4, 3, 4); groupBox2.Size = new Size(185, 106);
groupBox2.Size = new Size(211, 141);
groupBox2.TabIndex = 6; groupBox2.TabIndex = 6;
groupBox2.TabStop = false; groupBox2.TabStop = false;
groupBox2.Text = "Цвета"; groupBox2.Text = "Цвета";
// //
// panelPurple // panelPurple
// //
panelPurple.BackColor = Color.FromArgb(192, 0, 192); panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(159, 84); panelPurple.Location = new Point(139, 63);
panelPurple.Margin = new Padding(3, 4, 3, 4);
panelPurple.Name = "panelPurple"; panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(40, 40); panelPurple.Size = new Size(35, 30);
panelPurple.TabIndex = 7; panelPurple.TabIndex = 7;
panelPurple.MouseDown += panelColor_MouseDown; panelPurple.MouseDown += panelColor_MouseDown;
// //
// panelYellow // panelYellow
// //
panelYellow.BackColor = Color.Yellow; panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(159, 29); panelYellow.Location = new Point(139, 22);
panelYellow.Margin = new Padding(3, 4, 3, 4);
panelYellow.Name = "panelYellow"; panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(40, 40); panelYellow.Size = new Size(35, 30);
panelYellow.TabIndex = 3; panelYellow.TabIndex = 3;
panelYellow.MouseDown += panelColor_MouseDown; panelYellow.MouseDown += panelColor_MouseDown;
// //
// panelBlack // panelBlack
// //
panelBlack.BackColor = Color.Black; panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(112, 84); panelBlack.Location = new Point(98, 63);
panelBlack.Margin = new Padding(3, 4, 3, 4);
panelBlack.Name = "panelBlack"; panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(40, 40); panelBlack.Size = new Size(35, 30);
panelBlack.TabIndex = 6; panelBlack.TabIndex = 6;
panelBlack.MouseDown += panelColor_MouseDown; panelBlack.MouseDown += panelColor_MouseDown;
// //
// panelBlue // panelBlue
// //
panelBlue.BackColor = Color.Blue; panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(112, 29); panelBlue.Location = new Point(98, 22);
panelBlue.Margin = new Padding(3, 4, 3, 4);
panelBlue.Name = "panelBlue"; panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(40, 40); panelBlue.Size = new Size(35, 30);
panelBlue.TabIndex = 2; panelBlue.TabIndex = 2;
panelBlue.MouseDown += panelColor_MouseDown; panelBlue.MouseDown += panelColor_MouseDown;
// //
// panelGray // panelGray
// //
panelGray.BackColor = Color.Gray; panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(65, 84); panelGray.Location = new Point(57, 63);
panelGray.Margin = new Padding(3, 4, 3, 4);
panelGray.Name = "panelGray"; panelGray.Name = "panelGray";
panelGray.Size = new Size(40, 40); panelGray.Size = new Size(35, 30);
panelGray.TabIndex = 5; panelGray.TabIndex = 5;
panelGray.MouseDown += panelColor_MouseDown; panelGray.MouseDown += panelColor_MouseDown;
// //
// panelGreen // panelGreen
// //
panelGreen.BackColor = Color.FromArgb(0, 192, 0); panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(65, 29); panelGreen.Location = new Point(57, 22);
panelGreen.Margin = new Padding(3, 4, 3, 4);
panelGreen.Name = "panelGreen"; panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(40, 40); panelGreen.Size = new Size(35, 30);
panelGreen.TabIndex = 1; panelGreen.TabIndex = 1;
panelGreen.MouseDown += panelColor_MouseDown; panelGreen.MouseDown += panelColor_MouseDown;
// //
// panelWhite // panelWhite
// //
panelWhite.BackColor = Color.White; panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(18, 84); panelWhite.Location = new Point(16, 63);
panelWhite.Margin = new Padding(3, 4, 3, 4);
panelWhite.Name = "panelWhite"; panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(40, 40); panelWhite.Size = new Size(35, 30);
panelWhite.TabIndex = 4; panelWhite.TabIndex = 4;
panelWhite.MouseDown += panelColor_MouseDown; panelWhite.MouseDown += panelColor_MouseDown;
// //
// panelRed // panelRed
// //
panelRed.BackColor = Color.Red; panelRed.BackColor = Color.Red;
panelRed.Location = new Point(18, 29); panelRed.Location = new Point(16, 22);
panelRed.Margin = new Padding(3, 4, 3, 4);
panelRed.Name = "panelRed"; panelRed.Name = "panelRed";
panelRed.Size = new Size(40, 40); panelRed.Size = new Size(35, 30);
panelRed.TabIndex = 0; panelRed.TabIndex = 0;
panelRed.MouseDown += panelColor_MouseDown; panelRed.MouseDown += panelColor_MouseDown;
// //
// checkBoxBodyKit // checkBoxBodyKit
// //
checkBoxBodyKit.AutoSize = true; checkBoxBodyKit.AutoSize = true;
checkBoxBodyKit.Location = new Point(11, 205); checkBoxBodyKit.Location = new Point(10, 154);
checkBoxBodyKit.Margin = new Padding(3, 4, 3, 4);
checkBoxBodyKit.Name = "checkBoxBodyKit"; checkBoxBodyKit.Name = "checkBoxBodyKit";
checkBoxBodyKit.Size = new Size(215, 24); checkBoxBodyKit.Size = new Size(170, 19);
checkBoxBodyKit.TabIndex = 5; checkBoxBodyKit.TabIndex = 5;
checkBoxBodyKit.Text = "Признак наличия батареи"; checkBoxBodyKit.Text = "Признак наличия батареи";
checkBoxBodyKit.UseVisualStyleBackColor = true; checkBoxBodyKit.UseVisualStyleBackColor = true;
@ -215,47 +202,44 @@
// checkBoxPushka // checkBoxPushka
// //
checkBoxPushka.AutoSize = true; checkBoxPushka.AutoSize = true;
checkBoxPushka.Location = new Point(11, 159); checkBoxPushka.Location = new Point(10, 119);
checkBoxPushka.Margin = new Padding(3, 4, 3, 4);
checkBoxPushka.Name = "checkBoxPushka"; checkBoxPushka.Name = "checkBoxPushka";
checkBoxPushka.Size = new Size(202, 24); checkBoxPushka.Size = new Size(163, 19);
checkBoxPushka.TabIndex = 4; checkBoxPushka.TabIndex = 4;
checkBoxPushka.Text = "Признак наличия пушки"; checkBoxPushka.Text = "Признак наличия пушки";
checkBoxPushka.UseVisualStyleBackColor = true; checkBoxPushka.UseVisualStyleBackColor = true;
// //
// numericUpDownWeight // numericUpDownWeight
// //
numericUpDownWeight.Location = new Point(87, 80); numericUpDownWeight.Location = new Point(76, 60);
numericUpDownWeight.Margin = new Padding(3, 4, 3, 4);
numericUpDownWeight.Name = "numericUpDownWeight"; numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(83, 27); numericUpDownWeight.Size = new Size(73, 23);
numericUpDownWeight.TabIndex = 3; numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
// //
// numericUpDownSpeed // numericUpDownSpeed
// //
numericUpDownSpeed.Location = new Point(87, 41); numericUpDownSpeed.Location = new Point(76, 31);
numericUpDownSpeed.Margin = new Padding(3, 4, 3, 4);
numericUpDownSpeed.Name = "numericUpDownSpeed"; numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(83, 27); numericUpDownSpeed.Size = new Size(73, 23);
numericUpDownSpeed.TabIndex = 2; numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
// //
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(11, 83); label2.Location = new Point(10, 62);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(36, 20); label2.Size = new Size(29, 15);
label2.TabIndex = 1; label2.TabIndex = 1;
label2.Text = "Вес:"; label2.Text = "Вес:";
// //
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(11, 44); label1.Location = new Point(10, 33);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(76, 20); label1.Size = new Size(62, 15);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "Скорость:"; label1.Text = "Скорость:";
// //
@ -265,10 +249,9 @@
panelColor.Controls.Add(labelDopColor); panelColor.Controls.Add(labelDopColor);
panelColor.Controls.Add(labelBaseColor); panelColor.Controls.Add(labelBaseColor);
panelColor.Controls.Add(pictureBoxObject); panelColor.Controls.Add(pictureBoxObject);
panelColor.Location = new Point(539, 16); panelColor.Location = new Point(472, 12);
panelColor.Margin = new Padding(3, 4, 3, 4);
panelColor.Name = "panelColor"; panelColor.Name = "panelColor";
panelColor.Size = new Size(315, 245); panelColor.Size = new Size(276, 184);
panelColor.TabIndex = 1; panelColor.TabIndex = 1;
panelColor.DragDrop += PanelObject_DragDrop; panelColor.DragDrop += PanelObject_DragDrop;
panelColor.DragEnter += PanelObject_DragEnter; panelColor.DragEnter += PanelObject_DragEnter;
@ -277,9 +260,9 @@
// //
labelDopColor.AllowDrop = true; labelDopColor.AllowDrop = true;
labelDopColor.BorderStyle = BorderStyle.FixedSingle; labelDopColor.BorderStyle = BorderStyle.FixedSingle;
labelDopColor.Location = new Point(187, 13); labelDopColor.Location = new Point(164, 10);
labelDopColor.Name = "labelDopColor"; labelDopColor.Name = "labelDopColor";
labelDopColor.Size = new Size(114, 38); labelDopColor.Size = new Size(100, 29);
labelDopColor.TabIndex = 2; labelDopColor.TabIndex = 2;
labelDopColor.Text = "Доп. цвет"; labelDopColor.Text = "Доп. цвет";
labelDopColor.TextAlign = ContentAlignment.MiddleCenter; labelDopColor.TextAlign = ContentAlignment.MiddleCenter;
@ -291,9 +274,9 @@
// //
labelBaseColor.AllowDrop = true; labelBaseColor.AllowDrop = true;
labelBaseColor.BorderStyle = BorderStyle.FixedSingle; labelBaseColor.BorderStyle = BorderStyle.FixedSingle;
labelBaseColor.Location = new Point(14, 13); labelBaseColor.Location = new Point(12, 10);
labelBaseColor.Name = "labelBaseColor"; labelBaseColor.Name = "labelBaseColor";
labelBaseColor.Size = new Size(114, 38); labelBaseColor.Size = new Size(100, 29);
labelBaseColor.TabIndex = 2; labelBaseColor.TabIndex = 2;
labelBaseColor.Text = "Цвет"; labelBaseColor.Text = "Цвет";
labelBaseColor.TextAlign = ContentAlignment.MiddleCenter; labelBaseColor.TextAlign = ContentAlignment.MiddleCenter;
@ -303,19 +286,17 @@
// //
// pictureBoxObject // pictureBoxObject
// //
pictureBoxObject.Location = new Point(14, 61); pictureBoxObject.Location = new Point(12, 46);
pictureBoxObject.Margin = new Padding(3, 4, 3, 4);
pictureBoxObject.Name = "pictureBoxObject"; pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(288, 169); pictureBoxObject.Size = new Size(252, 127);
pictureBoxObject.TabIndex = 0; pictureBoxObject.TabIndex = 0;
pictureBoxObject.TabStop = false; pictureBoxObject.TabStop = false;
// //
// ButtonOk // ButtonOk
// //
ButtonOk.Location = new Point(553, 277); ButtonOk.Location = new Point(484, 208);
ButtonOk.Margin = new Padding(3, 4, 3, 4);
ButtonOk.Name = "ButtonOk"; ButtonOk.Name = "ButtonOk";
ButtonOk.Size = new Size(114, 43); ButtonOk.Size = new Size(100, 32);
ButtonOk.TabIndex = 2; ButtonOk.TabIndex = 2;
ButtonOk.Text = "Добавить"; ButtonOk.Text = "Добавить";
ButtonOk.UseVisualStyleBackColor = true; ButtonOk.UseVisualStyleBackColor = true;
@ -323,24 +304,22 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(727, 277); buttonCancel.Location = new Point(636, 208);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(114, 43); buttonCancel.Size = new Size(100, 32);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
// //
// FormSelfPropelledArtilleryUnitConfig // FormSelfPropelledArtilleryUnitConfig
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 336); ClientSize = new Size(800, 252);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(ButtonOk); Controls.Add(ButtonOk);
Controls.Add(panelColor); Controls.Add(panelColor);
Controls.Add(groupBox1); Controls.Add(groupBox1);
Margin = new Padding(3, 4, 3, 4);
Name = "FormSelfPropelledArtilleryUnitConfig"; Name = "FormSelfPropelledArtilleryUnitConfig";
Text = "FormSelfPropelledArtilleryUnitConfig"; Text = "FormSelfPropelledArtilleryUnitConfig";
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);

View File

@ -24,9 +24,6 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
objParams.DownBorder + GetStep() >= FieldHeight; objParams.DownBorder + GetStep() >= FieldHeight;
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
var objParams = GetObjectParameters; var objParams = GetObjectParameters;
@ -45,9 +42,6 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
MoveDown(); MoveDown();
} }
} }
} }
} }

View File

@ -107,8 +107,7 @@ namespace SelfPropelledArtilleryUnit.Generics
File.Delete(filename); File.Delete(filename);
} }
StringBuilder data = new(); StringBuilder data = new();
foreach (KeyValuePair<string, foreach (KeyValuePair<string, UstaGenericCollection<DrawningUsta, DrawningObjectUsta>> record in _ustaStorages)
UstaGenericCollection<DrawningUsta, DrawningObjectUsta>> record in _ustaStorages)
{ {
StringBuilder records = new(); StringBuilder records = new();
foreach (DrawningUsta? elem in record.Value.GetUsta) foreach (DrawningUsta? elem in record.Value.GetUsta)
@ -121,10 +120,12 @@ namespace SelfPropelledArtilleryUnit.Generics
{ {
return false; return false;
} }
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new using (StreamWriter writer = new StreamWriter(filename))
UTF8Encoding(true).GetBytes($"UstaStorage{Environment.NewLine}{data}"); {
fs.Write(info, 0, info.Length); writer.Write($"UstaStorage{Environment.NewLine}{data}");
}
return true; return true;
} }
@ -139,44 +140,38 @@ namespace SelfPropelledArtilleryUnit.Generics
{ {
return false; return false;
} }
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open)) using (StreamReader reader = new StreamReader(filename))
{ {
byte[] b = new byte[fs.Length]; string cheker = reader.ReadLine();
UTF8Encoding temp = new(true); if (cheker == null)
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{ {
return false; return false;
} }
if (!strs[0].StartsWith("UstaStorage")) if (!cheker.StartsWith("UstaStorage"))
{ {
//если нет такой записи, то это не те данные
return false; return false;
} }
_ustaStorages.Clear(); _ustaStorages.Clear();
foreach (string data in strs) string strs;
bool firstinit = true;
while ((strs = reader.ReadLine()) != null)
{ {
string[] record = data.Split(_separatorForKeyValue, if (strs == null && firstinit)
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{ {
continue; return false;
} }
UstaGenericCollection<DrawningUsta, DrawningObjectUsta> if (strs == null)
collection = new(_pictureWidth, _pictureHeight); {
string[] set = record[1].Split(_separatorRecords, return false;
StringSplitOptions.RemoveEmptyEntries); }
foreach (string elem in set) firstinit = false;
string name = strs.Split(_separatorForKeyValue)[0];
UstaGenericCollection<DrawningUsta, DrawningObjectUsta> collection = new(_pictureWidth, _pictureHeight);
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
{ {
DrawningUsta? usta = DrawningUsta? usta =
elem?.CreateDrawningUsta(_separatorForObject, _pictureWidth, _pictureHeight); data?.CreateDrawningUsta(_separatorForObject, _pictureWidth, _pictureHeight);
if (usta != null) if (usta != null)
{ {
int? result = collection + usta; int? result = collection + usta;
@ -186,10 +181,11 @@ namespace SelfPropelledArtilleryUnit.Generics
} }
} }
} }
_ustaStorages.Add(record[0], collection); _ustaStorages.Add(name, collection);
} }
return true; return true;
} }
} }
}
} }