public bool TryAddToItems(Item item) { if (!IsInItems) { if (CapacityIn == 2) // factory { var first = InItems.FirstOrDefault(); if ((item.ModelImages != ModelImages.Package && (int)item.ModelImages < 100) && ((first is null) || (ExtensionMethods.IsFromTwoKind(first.ModelImages, item.ModelImages)))) { InItems.Add(item); Work(); GameLogger.Log <Objects.ConsoleLog>($"{nameof(TryAddToItems)} Type: {"factory"} , Add {item.ModelImages} and Work"); return(true); } } else { if ((int)item.ModelImages >= 100) { InItems.Add(item); Work(); GameLogger.Log <Objects.ConsoleLog>($"{nameof(TryAddToItems)} Type: {"pagcking"} , Add {item.ModelImages} and Work"); return(true); } } } return(false); }
// kind Factory , Packaging public Factory(string kind) { Key = $"{nameof(Factory)}{GameLogger.Factory}"; timer = new Timer(); random = new Random(); // timer.AutoReset = false; switch (kind) { case "Factory": CapacityIn = 2; InItems = new List <Item>(CapacityIn); timer.Interval = random.NextSecound(1, 5); timer.Elapsed += (o, e) => { Item = new Item() { ModelImages = InItems.GetModelImages() }; timer.Stop(); timer.Interval = random.NextSecound(1, 5); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item))); InItems.Clear(); GameLogger.Log <Objects.ConsoleLog>($"{nameof(Factory)} Type: {kind} , Interval: {timer.Interval} , ModelImages: {Item.ModelImages}"); }; break; case "Packaging": CapacityIn = 1; InItems = new List <Item>(CapacityIn); timer.Interval = random.NextSecound(1, 3); timer.Elapsed += (o, e) => { Item = new Item() { ModelImages = ModelImages.Package, EqualPackage = (int)InItems.GetModelImages() }; timer.Stop(); timer.Interval = random.NextSecound(1, 3); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item))); InItems.Clear(); GameLogger.Log <Objects.ConsoleLog>($"{nameof(Factory)} Type: {kind} , Interval: {timer.Interval} , ModelImages: {Item.ModelImages}"); }; break; default: break; } }
public Police() { random = new Random(); timer = new Timer((e) => { var ranSpot = random.RandomSpot(); OnPolice?.Invoke(ranSpot); GameLogger.Log <Objects.ConsoleLog>($"{nameof(Police)} , Atack {ranSpot} "); }, null, 3 * 1000, 15 * 1000); }
public static T[,] InitializeArray <T>(this T[,] array) where T : new() { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = new T(); } } GameLogger.Log <Objects.ConsoleLog>($"Done {nameof(InitializeArray)}"); return(array); }
public bool TryAddToItems(Item item) { if (Item is not null && item.ModelImages == ModelImages.Package && Item.EqualPackage == item.EqualPackage) { Items.Dequeue(); GameLogger.Log <Objects.ConsoleLog>($"{nameof(TryAddToItems)} Dequeue"); return(true); } return(false); }
//kind: CrystalMine Model , kind: CrystalMine Color public CrystalMine(string kind) { Key = $"{nameof(CrystalMine)}{GameLogger.CrystalMine}"; timer = new Timer(); random = new Random(); //timer.AutoReset = false; switch (kind) { case "Model": timer.Interval = random.NextSecound(1, 5); timer.Elapsed += (o, e) => { Item = new Item() { ModelImages = random.RandomModel() }; timer.Stop(); timer.Interval = random.NextSecound(1, 5); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item))); GameLogger.Log <Objects.ConsoleLog>($"{nameof(CrystalMine)} Type: {kind} , Interval: {timer.Interval} , ModelImages: {Item.ModelImages}"); }; break; case "Color": timer.Interval = random.NextSecound(1, 3); timer.Elapsed += (o, e) => { Item = new Item() { ModelImages = random.RandomColor() }; timer.Stop(); timer.Interval = random.NextSecound(1, 3); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item))); GameLogger.Log <Objects.ConsoleLog>($"{nameof(CrystalMine)} Type: {kind} , Interval: {timer.Interval} , ModelImages: {Item.ModelImages}"); }; break; default: break; } timer.Start(); //Timer s =new Timer((o)=> { Console.WriteLine($"Im{DateTime.Now.Second}"); }, null,100,1); }
public Customer() { Key = $"{nameof(Customer)}"; random = new Random(); Items = new Queue <Item>(); timer = new Timer((o) => { var diamond = random.RandomDiamond(); Items.Enqueue(new Item() { ModelImages = diamond, EqualPackage = (int)diamond }); timer.Change((int)random.NextSecound(5, 20), Timeout.Infinite); GameLogger.Log <Objects.ConsoleLog>($"{nameof(Customer)} , ModelImages: {Item.ModelImages} , EqualPackage: {Item.EqualPackage}"); }, null, (int)random.NextSecound(1, 3), Timeout.Infinite); }
public static void Initialize(Spot[,] Board, Action action) { #region - Dealer - var initDealer = Board[Board.GetLength(0) - 1, Board.GetLength(1) / 2]; initDealer.SpotTypes = SpotTypes.Dealer; initDealer.Content = new Dealer() { Image = DealerImages.Top.GetUrlImage(), IsCurrentPostion = true, }; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Dealer} at row-1 col/2"); #endregion #region - CrystalMine - var spot = Board[2, 0]; spot.SpotTypes = SpotTypes.CrystalMine; var _CrystalMine = new CrystalMine("Model") { Image = "/image/crystalminemodel.png", }; _CrystalMine.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = _CrystalMine; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.CrystalMine} model at [2,0]"); //color spot = Board[3, 0]; spot.SpotTypes = SpotTypes.CrystalMine; _CrystalMine = new CrystalMine("Color") { Image = "/image/crystalminecolor.png", }; _CrystalMine.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = _CrystalMine; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.CrystalMine} color at [3,0]"); spot = Board[4, 0]; spot.SpotTypes = SpotTypes.CrystalMine; _CrystalMine = new CrystalMine("Model") { Image = "/image/crystalminemodel.png", }; _CrystalMine.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = _CrystalMine; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.CrystalMine} model at [4,0]"); #endregion #region - Factory - spot = Board[1, 4]; spot.SpotTypes = SpotTypes.Factory; var factory = new Factory("Factory") { Image = "/image/factory.png", }; factory.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = factory; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Factory} Factory at [1,4]"); spot = Board[2, 4]; spot.SpotTypes = SpotTypes.Factory; factory = new Factory("Factory") { Image = "/image/factory.png", }; factory.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = factory; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Factory} Factory at [2,4]"); spot = Board[3, 4]; spot.SpotTypes = SpotTypes.Factory; factory = new Factory("Factory") { Image = "/image/factory.png", }; factory.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = factory; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Factory} Factory at [3,4]"); spot = Board[4, 4]; spot.SpotTypes = SpotTypes.Factory; factory = new Factory("Packaging") { Image = "/image/packaging.png", }; factory.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = factory; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Factory} Packaging at [4,4]"); spot = Board[5, 4]; spot.SpotTypes = SpotTypes.Factory; factory = new Factory("Packaging") { Image = "/image/packaging.png", }; factory.PropertyChanged += (o, e) => { action.Invoke(); }; spot.Content = factory; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Factory} Packaging at [5,4]"); #endregion spot = Board[6, 0]; spot.SpotTypes = SpotTypes.Storage; spot.Content = new Storage() { Image = "/image/storage.png", }; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Storage} at [6,0]"); spot = Board[0, 2]; spot.SpotTypes = SpotTypes.Customer; spot.Content = new Customer() { Image = "/image/customer.png", }; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Customer} at [0,2]"); spot = Board[1, 0]; spot.SpotTypes = SpotTypes.Police; var _police = new Police() { Image = "/image/police.png", }; _police.OnPolice += (type) => { Console.WriteLine(type); Board.PoliceAction(type); action.Invoke(); }; spot.Content = _police; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Police} at [1,0]"); spot = Board[6, 4]; spot.SpotTypes = SpotTypes.Calculator; spot.Content = new Calculator() { Image = "/image/calculator.png", }; GameLogger.Log <Objects.ConsoleLog>($"Init {SpotTypes.Calculator} at [6,4]"); GameLogger.Log <Objects.ConsoleLog>($"Done {nameof(Initialize)}"); }