From e998513d7b461660472aa86937a6d23fd4f4dc80 Mon Sep 17 00:00:00 2001 From: vsa Date: Sat, 12 Nov 2022 17:04:33 +0700 Subject: [PATCH] 2022.11.12 --- Shop/Shop/Form1.Designer.cs | 217 +++++++++--------- Shop/Shop/Form1.cs | 92 +++++--- Shop/Shop/ShelfControl.Designer.cs | 134 +++++++++++ Shop/Shop/ShelfControl.cs | 51 ++++ Shop/Shop/ShelfControl.resx | 120 ++++++++++ Shop/Shop/ShopWin.csproj | 9 + WorkField/WorkField/FieldControl.Designer.cs | 59 +++++ WorkField/WorkField/FieldControl.cs | 27 +++ WorkField/WorkField/FieldControl.resx | 120 ++++++++++ WorkField/WorkField/FieldControlUnit.cs | 99 ++++++++ WorkField/WorkField/Form1.Designer.cs | 85 +++++-- WorkField/WorkField/Form1.cs | 55 +++-- WorkField/WorkField/Model/Block.cs | 11 + WorkField/WorkField/Model/BlockList.cs | 100 ++++++++ WorkField/WorkField/Model/CStadium.cs | 76 ------ WorkField/WorkField/Model/Description.txt | 18 +- WorkField/WorkField/Model/FieldBlock.cs | 10 + .../Model/{CPlayer.cs => PlayerBlock.cs} | 13 +- WorkField/WorkField/Model/Stadium.cs | 86 +++++++ WorkField/WorkField/Model/WallBlock.cs | 10 + WorkField/WorkField/Program.cs | 3 - .../WorkField/Properties/AssemblyInfo.cs | 1 - WorkField/WorkField/WorkField.csproj | 18 +- 23 files changed, 1145 insertions(+), 269 deletions(-) create mode 100644 Shop/Shop/ShelfControl.Designer.cs create mode 100644 Shop/Shop/ShelfControl.cs create mode 100644 Shop/Shop/ShelfControl.resx create mode 100644 WorkField/WorkField/FieldControl.Designer.cs create mode 100644 WorkField/WorkField/FieldControl.cs create mode 100644 WorkField/WorkField/FieldControl.resx create mode 100644 WorkField/WorkField/FieldControlUnit.cs create mode 100644 WorkField/WorkField/Model/Block.cs create mode 100644 WorkField/WorkField/Model/BlockList.cs delete mode 100644 WorkField/WorkField/Model/CStadium.cs create mode 100644 WorkField/WorkField/Model/FieldBlock.cs rename WorkField/WorkField/Model/{CPlayer.cs => PlayerBlock.cs} (77%) create mode 100644 WorkField/WorkField/Model/Stadium.cs create mode 100644 WorkField/WorkField/Model/WallBlock.cs diff --git a/Shop/Shop/Form1.Designer.cs b/Shop/Shop/Form1.Designer.cs index 786c05b..7d37421 100644 --- a/Shop/Shop/Form1.Designer.cs +++ b/Shop/Shop/Form1.Designer.cs @@ -30,29 +30,29 @@ this.components = new System.ComponentModel.Container(); this.textBox1 = new System.Windows.Forms.TextBox(); this.panel1 = new System.Windows.Forms.Panel(); - this.panel2 = new System.Windows.Forms.Panel(); - this.panel3 = new System.Windows.Forms.Panel(); - this.panel4 = new System.Windows.Forms.Panel(); - this.panel5 = new System.Windows.Forms.Panel(); - this.panel7 = new System.Windows.Forms.Panel(); - this.panel8 = new System.Windows.Forms.Panel(); this.panel9 = new System.Windows.Forms.Panel(); + this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.panel8 = new System.Windows.Forms.Panel(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.panel7 = new System.Windows.Forms.Panel(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.panel2 = new System.Windows.Forms.Panel(); this.textBox2 = new System.Windows.Forms.TextBox(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.panel5 = new System.Windows.Forms.Panel(); this.groupBox3 = new System.Windows.Forms.GroupBox(); - this.groupBox4 = new System.Windows.Forms.GroupBox(); - this.groupBox5 = new System.Windows.Forms.GroupBox(); - this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.panel4 = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.panel3 = new System.Windows.Forms.Panel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.panel1.SuspendLayout(); + this.panel9.SuspendLayout(); + this.panel8.SuspendLayout(); + this.panel7.SuspendLayout(); this.panel2.SuspendLayout(); - this.panel3.SuspendLayout(); - this.panel4.SuspendLayout(); this.panel5.SuspendLayout(); - this.panel7.SuspendLayout(); - this.panel8.SuspendLayout(); - this.panel9.SuspendLayout(); + this.panel4.SuspendLayout(); + this.panel3.SuspendLayout(); this.SuspendLayout(); // // textBox1 @@ -73,44 +73,43 @@ this.panel1.Size = new System.Drawing.Size(800, 100); this.panel1.TabIndex = 1; // - // panel2 + // panel9 // - this.panel2.Controls.Add(this.textBox2); - this.panel2.Controls.Add(this.panel5); - this.panel2.Controls.Add(this.panel4); - this.panel2.Controls.Add(this.panel3); - this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel2.Location = new System.Drawing.Point(0, 250); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(800, 100); - this.panel2.TabIndex = 3; + this.panel9.Controls.Add(this.groupBox6); + this.panel9.Dock = System.Windows.Forms.DockStyle.Left; + this.panel9.Location = new System.Drawing.Point(222, 0); + this.panel9.Name = "panel9"; + this.panel9.Size = new System.Drawing.Size(111, 100); + this.panel9.TabIndex = 7; // - // panel3 + // groupBox6 // - this.panel3.Controls.Add(this.groupBox1); - this.panel3.Dock = System.Windows.Forms.DockStyle.Left; - this.panel3.Location = new System.Drawing.Point(0, 0); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(111, 100); - this.panel3.TabIndex = 4; + this.groupBox6.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox6.Location = new System.Drawing.Point(0, 0); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(111, 100); + this.groupBox6.TabIndex = 2; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "groupBox6"; // - // panel4 + // panel8 // - this.panel4.Controls.Add(this.groupBox2); - this.panel4.Dock = System.Windows.Forms.DockStyle.Left; - this.panel4.Location = new System.Drawing.Point(111, 0); - this.panel4.Name = "panel4"; - this.panel4.Size = new System.Drawing.Size(111, 100); - this.panel4.TabIndex = 5; + this.panel8.Controls.Add(this.groupBox5); + this.panel8.Dock = System.Windows.Forms.DockStyle.Left; + this.panel8.Location = new System.Drawing.Point(111, 0); + this.panel8.Name = "panel8"; + this.panel8.Size = new System.Drawing.Size(111, 100); + this.panel8.TabIndex = 6; // - // panel5 + // groupBox5 // - this.panel5.Controls.Add(this.groupBox3); - this.panel5.Dock = System.Windows.Forms.DockStyle.Left; - this.panel5.Location = new System.Drawing.Point(222, 0); - this.panel5.Name = "panel5"; - this.panel5.Size = new System.Drawing.Size(111, 100); - this.panel5.TabIndex = 6; + this.groupBox5.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox5.Location = new System.Drawing.Point(0, 0); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(111, 100); + this.groupBox5.TabIndex = 2; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "groupBox5"; // // panel7 // @@ -121,23 +120,28 @@ this.panel7.Size = new System.Drawing.Size(111, 100); this.panel7.TabIndex = 5; // - // panel8 + // groupBox4 // - this.panel8.Controls.Add(this.groupBox5); - this.panel8.Dock = System.Windows.Forms.DockStyle.Left; - this.panel8.Location = new System.Drawing.Point(111, 0); - this.panel8.Name = "panel8"; - this.panel8.Size = new System.Drawing.Size(111, 100); - this.panel8.TabIndex = 6; + this.groupBox4.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox4.Location = new System.Drawing.Point(0, 0); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(111, 100); + this.groupBox4.TabIndex = 2; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "groupBox4"; // - // panel9 + // panel2 // - this.panel9.Controls.Add(this.groupBox6); - this.panel9.Dock = System.Windows.Forms.DockStyle.Left; - this.panel9.Location = new System.Drawing.Point(222, 0); - this.panel9.Name = "panel9"; - this.panel9.Size = new System.Drawing.Size(111, 100); - this.panel9.TabIndex = 7; + this.panel2.Controls.Add(this.textBox2); + this.panel2.Controls.Add(this.panel5); + this.panel2.Controls.Add(this.panel4); + this.panel2.Controls.Add(this.panel3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel2.Location = new System.Drawing.Point(0, 250); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(800, 100); + this.panel2.TabIndex = 3; + this.panel2.Visible = false; // // textBox2 // @@ -146,25 +150,14 @@ this.textBox2.Size = new System.Drawing.Size(100, 20); this.textBox2.TabIndex = 7; // - // groupBox1 - // - this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox1.Location = new System.Drawing.Point(0, 0); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(111, 100); - this.groupBox1.TabIndex = 1; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "groupBox1"; - // - // groupBox2 + // panel5 // - this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox2.Location = new System.Drawing.Point(0, 0); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(111, 100); - this.groupBox2.TabIndex = 2; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "groupBox2"; + this.panel5.Controls.Add(this.groupBox3); + this.panel5.Dock = System.Windows.Forms.DockStyle.Left; + this.panel5.Location = new System.Drawing.Point(222, 0); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(111, 100); + this.panel5.TabIndex = 6; // // groupBox3 // @@ -176,35 +169,43 @@ this.groupBox3.TabStop = false; this.groupBox3.Text = "groupBox3"; // - // groupBox4 + // panel4 // - this.groupBox4.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox4.Location = new System.Drawing.Point(0, 0); - this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(111, 100); - this.groupBox4.TabIndex = 2; - this.groupBox4.TabStop = false; - this.groupBox4.Text = "groupBox4"; + this.panel4.Controls.Add(this.groupBox2); + this.panel4.Dock = System.Windows.Forms.DockStyle.Left; + this.panel4.Location = new System.Drawing.Point(111, 0); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(111, 100); + this.panel4.TabIndex = 5; // - // groupBox5 + // groupBox2 // - this.groupBox5.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox5.Location = new System.Drawing.Point(0, 0); - this.groupBox5.Name = "groupBox5"; - this.groupBox5.Size = new System.Drawing.Size(111, 100); - this.groupBox5.TabIndex = 2; - this.groupBox5.TabStop = false; - this.groupBox5.Text = "groupBox5"; + this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox2.Location = new System.Drawing.Point(0, 0); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(111, 100); + this.groupBox2.TabIndex = 2; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "groupBox2"; // - // groupBox6 + // panel3 // - this.groupBox6.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox6.Location = new System.Drawing.Point(0, 0); - this.groupBox6.Name = "groupBox6"; - this.groupBox6.Size = new System.Drawing.Size(111, 100); - this.groupBox6.TabIndex = 2; - this.groupBox6.TabStop = false; - this.groupBox6.Text = "groupBox6"; + this.panel3.Controls.Add(this.groupBox1); + this.panel3.Dock = System.Windows.Forms.DockStyle.Left; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(111, 100); + this.panel3.TabIndex = 4; + // + // groupBox1 + // + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox1.Location = new System.Drawing.Point(0, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(111, 100); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "groupBox1"; // // timer1 // @@ -223,14 +224,14 @@ this.Name = "Form1"; this.Text = "Shop"; this.panel1.ResumeLayout(false); + this.panel9.ResumeLayout(false); + this.panel8.ResumeLayout(false); + this.panel7.ResumeLayout(false); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); - this.panel3.ResumeLayout(false); - this.panel4.ResumeLayout(false); this.panel5.ResumeLayout(false); - this.panel7.ResumeLayout(false); - this.panel8.ResumeLayout(false); - this.panel9.ResumeLayout(false); + this.panel4.ResumeLayout(false); + this.panel3.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Shop/Shop/Form1.cs b/Shop/Shop/Form1.cs index a0199ba..89ffbcd 100644 --- a/Shop/Shop/Form1.cs +++ b/Shop/Shop/Form1.cs @@ -13,11 +13,47 @@ namespace ShopWin { InitializeComponent(); h_initShop(); + h_initControls(); + h_RefreshShop(); } + private void h_initControls() + { + foreach (CShelf pShelf in _shop.ShelfList) { + var panel = new System.Windows.Forms.Panel(); + panel.Dock = System.Windows.Forms.DockStyle.Bottom; + panel.Location = new System.Drawing.Point(0, 150); + panel.Name = "panel6"; + panel.Size = new System.Drawing.Size(800, 100); + panel.TabIndex = 8; + + var shelfControl = new ShelfControl(); + shelfControl.Dock = System.Windows.Forms.DockStyle.Fill; + panel.Controls.Add(shelfControl); + + shelfControl.Init(pShelf); + + Controls.Add(panel); + + } + } + + private void h_refreshShelfControls(Control parentControl) + { + foreach (Control control in parentControl.Controls) { + if (control is ShelfControl) { + (control as ShelfControl).Refresh(); + } else { + h_refreshShelfControls(control); + } + } + } + private void h_RefreshShop() { + h_refreshShelfControls(this); + panel1.BackColor = _shop.ShelfList[1].CheckBrokenState() ? Color.DarkRed : Color.Green; @@ -27,36 +63,38 @@ namespace ShopWin groupBox1.Text = h_GetGroupboxTitle(_shop.ShelfList[0], 0); - groupBox2.Text = h_GetGroupboxTitle(_shop.ShelfList[0], 1); - groupBox3.Text = h_GetGroupboxTitle(_shop.ShelfList[0], 2); - groupBox4.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 0); - groupBox5.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 1); - groupBox6.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 2); - } + groupBox2.Text = h_GetGroupboxTitle(_shop.ShelfList[0], 1); + groupBox3.Text = h_GetGroupboxTitle(_shop.ShelfList[0], 2); + groupBox4.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 0); + groupBox5.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 1); + groupBox6.Text = h_GetGroupboxTitle(_shop.ShelfList[1], 2); + } - private string h_GetGroupboxTitle(CShelf cShelf, int v) - { - if (cShelf.ProductList.Count <= v) return "-"; - return cShelf.ProductList[v].Article; - } + private string h_GetGroupboxTitle(CShelf cShelf, int v) + { + if (cShelf.ProductList.Count <= v) return "-"; + return cShelf.ProductList[v].Article; + } - private void h_initShop() - { - _shop = new CShop("Shop1"); - _shop.ShelfList.Add(new CShelf("1", h_OnBreak)); - _shop.ShelfList.Add(new CShelf("2", h_OnBreak)); - _shop.FillTest(3); - } + private void h_initShop() + { + _shop = new CShop("Shop1"); + _shop.ShelfList.Add(new CShelf("1", h_OnBreak)); + _shop.ShelfList.Add(new CShelf("2", h_OnBreak)); + _shop.ShelfList.Add(new CShelf("3", h_OnBreak)); + _shop.ShelfList.Add(new CShelf("4", h_OnBreak)); + _shop.FillTest(3); + } - private void h_OnBreak(CShelf pShelf) - { - // - } + private void h_OnBreak(CShelf pShelf) + { + // + } - private void timer1_Tick(object sender, EventArgs e) - { - // _shop.Tick(); - h_RefreshShop(); - } + private void timer1_Tick(object sender, EventArgs e) + { + // _shop.Tick(); + h_RefreshShop(); } } +} diff --git a/Shop/Shop/ShelfControl.Designer.cs b/Shop/Shop/ShelfControl.Designer.cs new file mode 100644 index 0000000..54cc315 --- /dev/null +++ b/Shop/Shop/ShelfControl.Designer.cs @@ -0,0 +1,134 @@ +namespace ShopWin +{ + partial class ShelfControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.panel3 = new System.Windows.Forms.Panel(); + this.panel4 = new System.Windows.Forms.Panel(); + this.listView1 = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.panel2.SuspendLayout(); + this.panel4.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.RosyBrown; + this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel1.Location = new System.Drawing.Point(0, 157); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(710, 10); + this.panel1.TabIndex = 0; + // + // panel2 + // + this.panel2.Controls.Add(this.panel3); + this.panel2.Controls.Add(this.panel4); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 0); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(710, 157); + this.panel2.TabIndex = 1; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.RosyBrown; + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(213, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(497, 157); + this.panel3.TabIndex = 2; + // + // panel4 + // + this.panel4.Controls.Add(this.listView1); + this.panel4.Dock = System.Windows.Forms.DockStyle.Left; + this.panel4.Location = new System.Drawing.Point(0, 0); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(213, 157); + this.panel4.TabIndex = 2; + // + // listView1 + // + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1, + this.columnHeader2, + this.columnHeader3}); + this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.listView1.FullRowSelect = true; + this.listView1.GridLines = true; + this.listView1.HideSelection = false; + this.listView1.Location = new System.Drawing.Point(0, 0); + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(213, 157); + this.listView1.TabIndex = 0; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); + // + // columnHeader1 + // + this.columnHeader1.Text = "#"; + // + // columnHeader2 + // + this.columnHeader2.Text = "Title"; + // + // columnHeader3 + // + this.columnHeader3.Text = "Weight"; + // + // ShelfControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.Name = "ShelfControl"; + this.Size = new System.Drawing.Size(710, 167); + this.panel2.ResumeLayout(false); + this.panel4.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.ColumnHeader columnHeader2; + private System.Windows.Forms.ColumnHeader columnHeader3; + } +} diff --git a/Shop/Shop/ShelfControl.cs b/Shop/Shop/ShelfControl.cs new file mode 100644 index 0000000..ed5766c --- /dev/null +++ b/Shop/Shop/ShelfControl.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShopWin.Model; + +namespace ShopWin +{ + public partial class ShelfControl : UserControl + { + private CShelf _shelf; + public ShelfControl() + { + InitializeComponent(); + } + + public void Init(CShelf shelf) + { + _shelf = shelf; + listView1.Tag = _shelf; + } + + public void Refresh() + { + if (_shelf == null) return; + listView1.Items.Clear(); + for (int index = 0; index < _shelf.ProductList.Count; index++) { + CProduct pGood = _shelf.ProductList[index]; + ListViewItem lvi = listView1.Items.Add((index + 1).ToString(), (index + 1).ToString()); + lvi.SubItems.Add(pGood.Title); + lvi.SubItems.Add(pGood.Weight.ToString()); + lvi.Tag = pGood; + } + } + + private void listView1_SelectedIndexChanged(object sender, EventArgs e) + { + if (listView1.SelectedItems == null) return; + if (listView1.SelectedItems.Count == 0) return; + CProduct p = (listView1.SelectedItems[0].Tag as CProduct); + if (p == null) return; + Debug.WriteLine(p.Title); + } + } +} diff --git a/Shop/Shop/ShelfControl.resx b/Shop/Shop/ShelfControl.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/Shop/Shop/ShelfControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Shop/Shop/ShopWin.csproj b/Shop/Shop/ShopWin.csproj index 42c2cb5..576fed9 100644 --- a/Shop/Shop/ShopWin.csproj +++ b/Shop/Shop/ShopWin.csproj @@ -57,6 +57,12 @@ + + UserControl + + + ShelfControl.cs + Form1.cs @@ -70,6 +76,9 @@ Resources.resx True + + ShelfControl.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/WorkField/WorkField/FieldControl.Designer.cs b/WorkField/WorkField/FieldControl.Designer.cs new file mode 100644 index 0000000..56f1bc1 --- /dev/null +++ b/WorkField/WorkField/FieldControl.Designer.cs @@ -0,0 +1,59 @@ +namespace WorkFieldWin +{ + partial class FieldControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(523, 243); + this.pictureBox1.TabIndex = 1; + this.pictureBox1.TabStop = false; + // + // FieldControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.pictureBox1); + this.Name = "FieldControl"; + this.Size = new System.Drawing.Size(523, 243); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox1; + } +} diff --git a/WorkField/WorkField/FieldControl.cs b/WorkField/WorkField/FieldControl.cs new file mode 100644 index 0000000..6432cdb --- /dev/null +++ b/WorkField/WorkField/FieldControl.cs @@ -0,0 +1,27 @@ +using System.Windows.Forms; +using WorkField.Model; + +namespace WorkFieldWin +{ + public partial class FieldControl : UserControl + { + private FieldControlUnit _control; + + public FieldControl() + { + InitializeComponent(); + } + + public void Init(CStadium st) + { + _control = new FieldControlUnit( + pictureBox1.CreateGraphics(), + st); + } + + public void RefreshContent() + { + _control.Refresh(); + } + } +} diff --git a/WorkField/WorkField/FieldControl.resx b/WorkField/WorkField/FieldControl.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/WorkField/WorkField/FieldControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WorkField/WorkField/FieldControlUnit.cs b/WorkField/WorkField/FieldControlUnit.cs new file mode 100644 index 0000000..a467b7f --- /dev/null +++ b/WorkField/WorkField/FieldControlUnit.cs @@ -0,0 +1,99 @@ +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using WorkField.Model; + +namespace WorkFieldWin +{ + internal class FieldControlUnit + { + private Graphics _gr; + private CStadium _st; + private int PlayerWidth = 4; + private double Scale = 1; + private int PlayerHeight = 4; + + + public FieldControlUnit(Graphics gr, CStadium st) + { + _gr = gr; + _st = st; + } + + private int h_GetX(int X) + { + return (int)(X * Scale); + } + + private int h_GetY(int Y) + { + return (int)(Y * Scale); + } + + public void Refresh() + { + // h_LoadImage(); + h_DrawImage(); + h_refreshPicture(); + } + + private void h_LoadImage() + { + Bitmap im = new Bitmap("1.bmp"); + Bitmap resizedImage = h_ResizeImage(im, h_GetX(im.Width), h_GetY(im.Height)); + _gr.DrawImage(resizedImage, new Point(h_GetX(0), h_GetY(0))); + } + + private void h_DrawImage() + { + Bitmap im = new Bitmap( + h_GetX(_st.BlockList.GetWidth()), + h_GetY(_st.BlockList.GetHeight())); + Graphics gr = Graphics.FromImage(im); + + foreach (var pl in _st.BlockList.List) { + if (pl is CFieldBlock) { + gr.DrawEllipse(Pens.GreenYellow, h_GetX(pl.X), h_GetY(pl.Y), h_GetX(PlayerWidth), h_GetY(PlayerHeight)); + } + + if (pl is CWallBlock) { + gr.DrawEllipse(Pens.BlueViolet, h_GetX(pl.X), h_GetY(pl.Y), h_GetX(PlayerWidth), h_GetY(PlayerHeight)); + } + } + + _gr.DrawImage(im, 0, 0); + } + + + private static Bitmap h_ResizeImage(Image image, int width, int height) + { + var destRect = new Rectangle(0, 0, width, height); + var destImage = new Bitmap(width, height); + + destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); + + using (var graphics = Graphics.FromImage(destImage)) { + graphics.CompositingMode = CompositingMode.SourceCopy; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.SmoothingMode = SmoothingMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + + using (var wrapMode = new ImageAttributes()) { + wrapMode.SetWrapMode(WrapMode.TileFlipXY); + graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); + } + } + + return destImage; + } + + private void h_refreshPicture() + { + foreach (CPlayerBlock pl in _st.PlayerList) { + _gr.DrawEllipse(Pens.Brown, h_GetX(pl.X), h_GetY(pl.Y), h_GetX(PlayerWidth), h_GetY(PlayerHeight)); + } + } + + } +} diff --git a/WorkField/WorkField/Form1.Designer.cs b/WorkField/WorkField/Form1.Designer.cs index 4a3acb4..7d410f6 100644 --- a/WorkField/WorkField/Form1.Designer.cs +++ b/WorkField/WorkField/Form1.Designer.cs @@ -38,13 +38,20 @@ this.lab1X = new System.Windows.Forms.Label(); this.btnMove = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); + this.panel4 = new System.Windows.Forms.Panel(); + this.panel5 = new System.Windows.Forms.Panel(); + this.fieldControl2 = new WorkFieldWin.FieldControl(); + this.fieldControl1 = new WorkFieldWin.FieldControl(); + this.panel1.SuspendLayout(); this.panel2.SuspendLayout(); this.panel3.SuspendLayout(); + this.panel4.SuspendLayout(); + this.panel5.SuspendLayout(); this.SuspendLayout(); // // button1 // - this.button1.Location = new System.Drawing.Point(308, 10); + this.button1.Location = new System.Drawing.Point(210, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; @@ -54,10 +61,12 @@ // // panel1 // - this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel1.Location = new System.Drawing.Point(0, 52); + this.panel1.BackColor = System.Drawing.Color.WhiteSmoke; + this.panel1.Controls.Add(this.fieldControl1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 53); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(800, 398); + this.panel1.Size = new System.Drawing.Size(784, 190); this.panel1.TabIndex = 1; // // panel2 @@ -65,9 +74,9 @@ this.panel2.Controls.Add(this.lab2Y); this.panel2.Controls.Add(this.lab2X); this.panel2.Dock = System.Windows.Forms.DockStyle.Right; - this.panel2.Location = new System.Drawing.Point(690, 0); + this.panel2.Location = new System.Drawing.Point(674, 0); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(110, 52); + this.panel2.Size = new System.Drawing.Size(110, 53); this.panel2.TabIndex = 4; // // lab2Y @@ -93,9 +102,9 @@ this.panel3.Controls.Add(this.lab1Y); this.panel3.Controls.Add(this.lab1X); this.panel3.Dock = System.Windows.Forms.DockStyle.Right; - this.panel3.Location = new System.Drawing.Point(580, 0); + this.panel3.Location = new System.Drawing.Point(564, 0); this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(110, 52); + this.panel3.Size = new System.Drawing.Size(110, 53); this.panel3.TabIndex = 7; // // lab1Y @@ -118,7 +127,7 @@ // // btnMove // - this.btnMove.Location = new System.Drawing.Point(389, 10); + this.btnMove.Location = new System.Drawing.Point(291, 12); this.btnMove.Name = "btnMove"; this.btnMove.Size = new System.Drawing.Size(75, 23); this.btnMove.TabIndex = 8; @@ -131,22 +140,64 @@ this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // + // panel4 + // + this.panel4.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.panel4.Controls.Add(this.btnMove); + this.panel4.Controls.Add(this.button1); + this.panel4.Controls.Add(this.panel3); + this.panel4.Controls.Add(this.panel2); + this.panel4.Dock = System.Windows.Forms.DockStyle.Top; + this.panel4.Location = new System.Drawing.Point(0, 0); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(784, 53); + this.panel4.TabIndex = 2; + // + // panel5 + // + this.panel5.BackColor = System.Drawing.Color.DarkGray; + this.panel5.Controls.Add(this.fieldControl2); + this.panel5.Dock = System.Windows.Forms.DockStyle.Top; + this.panel5.Location = new System.Drawing.Point(0, 243); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(784, 362); + this.panel5.TabIndex = 2; + // + // fieldControl2 + // + this.fieldControl2.Dock = System.Windows.Forms.DockStyle.Fill; + this.fieldControl2.Location = new System.Drawing.Point(0, 0); + this.fieldControl2.Name = "fieldControl2"; + this.fieldControl2.Size = new System.Drawing.Size(784, 362); + this.fieldControl2.TabIndex = 1; + // + // fieldControl1 + // + this.fieldControl1.BackColor = System.Drawing.Color.WhiteSmoke; + this.fieldControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.fieldControl1.Location = new System.Drawing.Point(0, 0); + this.fieldControl1.Name = "fieldControl1"; + this.fieldControl1.Size = new System.Drawing.Size(784, 190); + this.fieldControl1.TabIndex = 0; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.btnMove); - this.Controls.Add(this.panel3); - this.Controls.Add(this.panel2); + this.ClientSize = new System.Drawing.Size(784, 419); + this.Controls.Add(this.panel5); this.Controls.Add(this.panel1); - this.Controls.Add(this.button1); + this.Controls.Add(this.panel4); + this.DoubleBuffered = true; this.Name = "Form1"; this.Text = "Стадион"; + this.panel1.ResumeLayout(false); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); + this.panel4.ResumeLayout(false); + this.panel5.ResumeLayout(false); this.ResumeLayout(false); } @@ -163,6 +214,10 @@ private System.Windows.Forms.Label lab1X; private System.Windows.Forms.Button btnMove; private System.Windows.Forms.Timer timer1; - } + private System.Windows.Forms.Panel panel4; + private WorkFieldWin.FieldControl fieldControl1; + private WorkFieldWin.FieldControl fieldControl2; + private System.Windows.Forms.Panel panel5; + } } diff --git a/WorkField/WorkField/Form1.cs b/WorkField/WorkField/Form1.cs index 3a3c8b0..413b8d2 100644 --- a/WorkField/WorkField/Form1.cs +++ b/WorkField/WorkField/Form1.cs @@ -1,11 +1,5 @@ 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; using WorkField.Model; @@ -24,30 +18,34 @@ namespace WorkField private void h_PrepareStadium() { - _stadium = new CStadium(30, 30); - _stadium.PlayerList.Add( - new CPlayer("player1", 10, 10, _stadium.IsPosition)); - _stadium.PlayerList.Add( - new CPlayer("player2", 25, 10, h_CanMove)); + _stadium = new CStadium("1.bmp"); + _stadium.AddNewStandardPlayer(); + _stadium.AddNewStandardPlayer(); + //_stadium.PlayerList.Add( + // new CPlayer("player1", 10, 10, _stadium.IsPosition)); + //_stadium.PlayerList.Add( + // new CPlayer("player2", 25, 10, h_CanMove)); } - private bool h_CanMove(int arg1, int arg2) - { - if (DateTime.Now.Second < 30) { - return false; - } + //private bool h_CanMove(int arg1, int arg2) + //{ + // if (DateTime.Now.Second < 30) { + // return false; + // } - return true; - } + // return true; + //} private void button1_Click(object sender, EventArgs e) { - int iNum = _stadium.PlayerList.Count + 1; - _stadium.PlayerList.Add( - new CPlayer($"player{iNum}", - 10, 10 + iNum * 2, h_CanMove)); + _stadium.AddNewStandardPlayer(); + //int iNum = _stadium.PlayerList.Count + 1; + //_stadium.PlayerList.Add( + // new CPlayer($"player{iNum}", + // 10, 10 + iNum * 2, h_CanMove)); } + private void btnMove_Click(object sender, EventArgs e) { timer1.Enabled = !timer1.Enabled; @@ -57,12 +55,21 @@ namespace WorkField { lab1X.Text = _stadium.PlayerList[0].X.ToString(); lab1Y.Text = _stadium.PlayerList[0].Y.ToString(); - lab1X.BackColor = _stadium.PlayerList[0].IsFreezed - ? Color.Brown + lab1X.BackColor = _stadium.PlayerList[0].IsFreezed + ? Color.Brown : Color.Gray; lab2X.Text = _stadium.PlayerList[1].X.ToString(); lab2Y.Text = _stadium.PlayerList[1].Y.ToString(); + + h_RefreshPicture(); + + } + + private void h_RefreshPicture() + { + fieldControl1.RefreshContent(); + fieldControl2.RefreshContent(); } private void timer1_Tick(object sender, EventArgs e) diff --git a/WorkField/WorkField/Model/Block.cs b/WorkField/WorkField/Model/Block.cs new file mode 100644 index 0000000..ce02023 --- /dev/null +++ b/WorkField/WorkField/Model/Block.cs @@ -0,0 +1,11 @@ +namespace WorkField.Model +{ + /// + /// Блок + /// + public class CBlock + { + public int X; + public int Y; + } +} \ No newline at end of file diff --git a/WorkField/WorkField/Model/BlockList.cs b/WorkField/WorkField/Model/BlockList.cs new file mode 100644 index 0000000..ac75798 --- /dev/null +++ b/WorkField/WorkField/Model/BlockList.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace WorkField.Model +{ + /// + /// Тип блока + /// + public enum EBlockType + { + Unknown = 0, + Wall = 1, + Field = 2, + } + + /// + /// БлокСписок + /// + public class CBlockList + { + public List List; + + /// Initializes a new instance of the class. + public CBlockList() + { + List = new List(); + } + + public int GetWidth() + { + int iMaxX = 0; + foreach (var pB in List) { + if (pB.X > iMaxX) { + iMaxX = pB.X; + } + } + + return iMaxX; + } + + public int GetHeight() + { + int iMaxY = 0; + foreach (var pB in List) { + if (pB.Y > iMaxY) { + iMaxY = pB.Y; + } + } + + return iMaxY; + } + + + /// + /// Ищет элемент в позиции + /// + /// + /// + /// + public CBlock Find(int iX, int iY) + { + CBlock el = List + .FirstOrDefault(block => + block.X == iX && block.Y == iY); + //CBlock el = null; + //foreach (CBlock block in List) { + // if (block.X == iX && block.Y == iY) { + // el = block; + // break; + // } + //} + + + return el; + } + + public bool Add(int iX, int iY, EBlockType enType) + { + CBlock pp = Find(iX, iY); + if (pp != null) { + return false; + } + + switch (enType) { + case EBlockType.Field: + List.Add(new CFieldBlock() { X = iX, Y = iY }); + break; + case EBlockType.Wall: + List.Add(new CWallBlock() { X = iX, Y = iY }); + break; + case EBlockType.Unknown: + throw new ArgumentOutOfRangeException(nameof(enType), enType, null); + } + + return true; + + } + } +} \ No newline at end of file diff --git a/WorkField/WorkField/Model/CStadium.cs b/WorkField/WorkField/Model/CStadium.cs deleted file mode 100644 index 1050377..0000000 --- a/WorkField/WorkField/Model/CStadium.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Runtime.Remoting; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace WorkField.Model -{ - /// - /// Стадион - /// - public class CStadium - { - private System.Threading.Timer _timer; - - /// - /// Ширина - /// - public int Width; - /// - /// Длина - /// - public int Height; - /// - /// Список работников - /// - public List PlayerList; - - public CStadium (int width, int height) - { - Width = width; - Height = height; - PlayerList = new List(); - - _timer = new Timer(h_tick, null, - new TimeSpan(0, 0, 0, 0, 300), - new TimeSpan(0, 0, 0, 0, 1000) - ); - } - - private void h_tick(object x) - { - this.Move(); - } - - internal void Move() - { - foreach (CPlayer pPlayer in PlayerList) { - pPlayer.Move(); - } - } - - public bool IsPosition(int newX, int newY) - { - string sFilename = "1.bmp"; - Bitmap pB = new Bitmap(sFilename); - if (newX < 0) return false; - if (newY < 0) return false; - if (newX > pB.Width) return false; - if (newY > pB.Height) return false; - //for (int xx = 0; xx < pB.Width; xx++) { - // for (int yy = 0; yy < pB.Height; yy++) { - Color pColor = pB.GetPixel(newX, newY); - return !(pColor.R == Color.Black.R - && pColor.G == Color.Black.G - && pColor.B == Color.Black.B - ); - // } - //} - return true; - } - } -} diff --git a/WorkField/WorkField/Model/Description.txt b/WorkField/WorkField/Model/Description.txt index 25dfb9c..10a7932 100644 --- a/WorkField/WorkField/Model/Description.txt +++ b/WorkField/WorkField/Model/Description.txt @@ -1,14 +1,22 @@ Поле с работниками Поле - Ширина - Длина - Работник[] + БлокСписок + РаботникБлок[] -Работник - Фамилия +БлокСписок (контроль уникальности, поиск блока по координатам) + Блок[] + +Блок X Y +СтенаБлок: Блок + +ПолеБлок: Блок + +РаботникБлок: Блок + Фамилия + diff --git a/WorkField/WorkField/Model/FieldBlock.cs b/WorkField/WorkField/Model/FieldBlock.cs new file mode 100644 index 0000000..0fd01b5 --- /dev/null +++ b/WorkField/WorkField/Model/FieldBlock.cs @@ -0,0 +1,10 @@ +namespace WorkField.Model +{ + /// + /// ПолеБлок + /// + public class CFieldBlock : CBlock + { + + } +} \ No newline at end of file diff --git a/WorkField/WorkField/Model/CPlayer.cs b/WorkField/WorkField/Model/PlayerBlock.cs similarity index 77% rename from WorkField/WorkField/Model/CPlayer.cs rename to WorkField/WorkField/Model/PlayerBlock.cs index d095094..d5fed46 100644 --- a/WorkField/WorkField/Model/CPlayer.cs +++ b/WorkField/WorkField/Model/PlayerBlock.cs @@ -1,18 +1,15 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace WorkField.Model { - public class CPlayer + /// + /// РаботникБлок + /// + public class CPlayerBlock: CBlock { private Random _rnd = new Random(); public string Surname; - public int X; - public int Y; private readonly Func _fnCanMove; public bool IsFreezed @@ -31,7 +28,7 @@ namespace WorkField.Model private DateTime UnfreezeTime; - public CPlayer(string surname, int x, int y, + public CPlayerBlock(string surname, int x, int y, Func fnCanMove) { Surname = surname; diff --git a/WorkField/WorkField/Model/Stadium.cs b/WorkField/WorkField/Model/Stadium.cs new file mode 100644 index 0000000..a51fd25 --- /dev/null +++ b/WorkField/WorkField/Model/Stadium.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; + +namespace WorkField.Model +{ + /// + /// Стадион + /// + public class CStadium + { + private System.Threading.Timer _timer; + private string _mapFilename; + + public CBlockList BlockList; + /// + /// Список работников + /// + public List PlayerList; + + + public CStadium(string sFn) + { + _mapFilename = sFn; + PlayerList = new List(); + BlockList = new CBlockList(); + + h_FillField(); + + _timer = new Timer(h_tick, null, + new TimeSpan(0, 0, 0, 0, 300), + new TimeSpan(0, 0, 0, 0, 1000) + ); + } + + private void h_FillField() + { + Bitmap pB = new Bitmap(_mapFilename); + for (int xx = 0; xx < pB.Width; xx++) { + for (int yy = 0; yy < pB.Height; yy++) { + Color pColor = pB.GetPixel(xx, yy); + bool isWall = h_IsColor(pColor, Color.Black); + bool isField = !isWall; // h_IsColor(pColor, Color.White); + if (isWall) BlockList.Add(xx, yy, EBlockType.Wall); + if (isField) BlockList.Add(xx, yy, EBlockType.Field); + } + } + } + + private static bool h_IsColor(Color pC1, Color pC2) + { + return pC2.R == pC1.R + && pC2.G == pC1.G + && pC2.B == pC1.B; + } + + private void h_tick(object x) + { + this.Move(); + } + + internal void Move() + { + foreach (CPlayerBlock pPlayer in PlayerList) { + pPlayer.Move(); + } + } + + public bool IsPosition(int newX, int newY) + { + CBlock pBlock = BlockList.Find(newX, newY); + if (pBlock == null) return false; + if (pBlock is CWallBlock) return false; + return true; + } + + public void AddNewStandardPlayer() + { + int iNum = PlayerList.Count + 1; + PlayerList.Add( + new CPlayerBlock($"player{iNum}", + 10, 10 + iNum * 2, IsPosition)); + } + } +} diff --git a/WorkField/WorkField/Model/WallBlock.cs b/WorkField/WorkField/Model/WallBlock.cs new file mode 100644 index 0000000..b8897af --- /dev/null +++ b/WorkField/WorkField/Model/WallBlock.cs @@ -0,0 +1,10 @@ +namespace WorkField.Model +{ + /// + /// СтенаБлок + /// + public class CWallBlock : CBlock + { + + } +} \ No newline at end of file diff --git a/WorkField/WorkField/Program.cs b/WorkField/WorkField/Program.cs index e2d40df..3a73fa5 100644 --- a/WorkField/WorkField/Program.cs +++ b/WorkField/WorkField/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace WorkField diff --git a/WorkField/WorkField/Properties/AssemblyInfo.cs b/WorkField/WorkField/Properties/AssemblyInfo.cs index 42b6ac3..74c46c9 100644 --- a/WorkField/WorkField/Properties/AssemblyInfo.cs +++ b/WorkField/WorkField/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/WorkField/WorkField/WorkField.csproj b/WorkField/WorkField/WorkField.csproj index 1a11bfc..f80e518 100644 --- a/WorkField/WorkField/WorkField.csproj +++ b/WorkField/WorkField/WorkField.csproj @@ -46,16 +46,30 @@ + + UserControl + + + FieldControl.cs + + Form Form1.cs - - + + + + + + + + FieldControl.cs + Form1.cs