|
|
@ -1,5 +1,6 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
namespace ShopWin.Model |
|
|
namespace ShopWin.Model |
|
|
{ |
|
|
{ |
|
|
@ -9,20 +10,43 @@ namespace ShopWin.Model |
|
|
public class CShop |
|
|
public class CShop |
|
|
{ |
|
|
{ |
|
|
private Random _random = new Random(); |
|
|
private Random _random = new Random(); |
|
|
|
|
|
private System.Threading.Timer _timer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Title = ""; |
|
|
public string Title = ""; |
|
|
public List<CShelf> ShelfList = new List<CShelf>(); |
|
|
public List<CShelf> ShelfList = new List<CShelf>(); |
|
|
|
|
|
|
|
|
public CShop(string title) |
|
|
public CShop(string title) |
|
|
{ |
|
|
{ |
|
|
Title = title; |
|
|
Title = title; |
|
|
|
|
|
_timer = new Timer(h_tick, null, |
|
|
|
|
|
new TimeSpan(0, 0, 0, 0, 1000), |
|
|
|
|
|
new TimeSpan(0, 0, 0, 0, 1000) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void h_tick(object state) |
|
|
|
|
|
{ |
|
|
|
|
|
this.Tick(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Tick() |
|
|
public void Tick() |
|
|
|
|
|
{ |
|
|
|
|
|
h_ShelfBroke(); |
|
|
|
|
|
h_GoodsSold(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void h_ShelfBroke() |
|
|
|
|
|
{ |
|
|
|
|
|
for (int ii = 0; ii < ShelfList.Count; ii++) { |
|
|
|
|
|
ShelfList[ii].CheckBrokenState(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void h_GoodsSold() |
|
|
{ |
|
|
{ |
|
|
if (_random.Next(0, 10) == 1) { |
|
|
if (_random.Next(0, 10) == 1) { |
|
|
if (ShelfList[0].ProductList.Count > 0) { |
|
|
ShelfList[0].RemoveProduct(); |
|
|
ShelfList[0].ProductList.RemoveAt(0); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|