private void UpdateToyProperties(IToy Toy) { DataTable DT = new DataTable(); DT.Columns.Add("Property", typeof(string)); DT.Columns.Add("Value", typeof(string)); if (Toy != null) { DT.Rows.Add("Name", Toy.Name); DT.Rows.Add("Type", Toy.GetType().Name); Type T = Toy.GetType(); foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (PI.Name != "Name") { DT.Rows.Add(PI.Name, PI.GetValue(Toy, new object[] { }).ToString()); } } } CabinetToyProperties.ClearSelection(); CabinetToyProperties.Columns.Clear(); CabinetToyProperties.AutoGenerateColumns = true; CabinetToyProperties.DataSource = DT; CabinetToyProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); CabinetToyProperties.Refresh(); }
private void RemoveToyFromSquare(IToy toy) { lock (toysSquare.Toys) { toysSquare.RemoveToyFromSquare(toy); } }
/// <summary> /// Move 1 step in face direction /// </summary> /// <param name="toy">The toy</param> /// <returns>The new position</returns> public override IPosition Execute(IToy toy) { int x = toy.X; int y = toy.Y; if (toy.Facing == Direction.NORTH) { y = y + 1; } else if (toy.Facing == Direction.SOUTH) { y = y - 1; } else if (toy.Facing == Direction.EAST) { x = x + 1; } else if (toy.Facing == Direction.WEST) { x = x - 1; } return(new PositionImpl() { X = x, Y = y, Facing = toy.Facing }); }
/// <summary> /// Return invalid x and y position /// </summary> /// <param name="toy">The toy</param> /// <returns>The new position</returns> public override IPosition Execute(IToy toy) { return(new PositionImpl() { X = -1, Y = -1, Facing = Direction.NORTH }); }
/// <summary> /// Rotate direction 90 degrees to right /// </summary> /// <param name="toy">The toy</param> /// <returns>The new position</returns> public override IPosition Execute(IToy toy) { return(new PositionImpl() { X = toy.X, Y = toy.Y, Facing = TurnRight(toy.Facing) }); }
/// <summary> /// Get current toy position without modification /// </summary> /// <param name="toy">The toy</param> /// <returns>The position</returns> public override IPosition Execute(IToy toy) { IPosition pos = new PositionImpl() { X = toy.X, Y = toy.Y, Facing = toy.Facing }; Console.WriteLine(toy.CurrentPositionInfo()); return(pos); }
private void UpdateToyFromControls(IToy selectedToy, NumericUpDown speedUpDown, NumericUpDown volumeUpDown, CheckBox openableCheckbox) { if (selectedToy is IAccelerable) { (selectedToy as IAccelerable).ChangeSpeed((int)speedUpDown.Value); } if (selectedToy is IFillable) { (selectedToy as IFillable).ChangeFillLevel((int)volumeUpDown.Value); } if (selectedToy is IOpenable) { (selectedToy as IOpenable).Open(openableCheckbox.Checked); } }
public void AddToyToSquare(IToy toy) { lock (toysSquare.Toys) { toy.ValueChanged += this.ToyValueChanged; try { toysSquare.AddToy(toy); } catch (ValueExceedException ex) { Console.WriteLine(ex.Message); } catch (ToysAmountExceedException ex) { Console.WriteLine(ex.Message); } } }
private void createToy_Click(object sender, EventArgs e) { IToy selectedToyType = ToyTypesList[createToyCombo.SelectedIndex]; UpdateToyFromControls(selectedToyType, speedCreateUpDown, volumeCreateUpDown, openableCreateCheckbox); if (selectedToyType is Car) { ToyBoxList.Add(new Car(selectedToyType as Car)); } if (selectedToyType is Teddy) { ToyBoxList.Add(new Teddy(selectedToyType as Teddy)); } if (selectedToyType is Chest) { ToyBoxList.Add(new Chest(selectedToyType as Chest)); } if (selectedToyType is Wagon) { ToyBoxList.Add(new Wagon(selectedToyType as Wagon)); } MessageBox.Show("Toy created successfully!"); }
private void UpdateControlsFromToy(IToy selectedToy, NumericUpDown speedUpDown, NumericUpDown volumeUpDown, CheckBox openableCheckbox) { speedUpDown.Value = 0; volumeUpDown.Value = 0; openableCheckbox.Checked = false; //reset controls speedUpDown.Enabled = false; volumeUpDown.Enabled = false; openableCheckbox.Enabled = false; if (selectedToy is IAccelerable) { speedUpDown.Value = (selectedToy as IAccelerable).GetSpeed(); speedUpDown.Enabled = true; } if (selectedToy is IFillable) { volumeUpDown.Value = (selectedToy as IFillable).GetFillLevel(); volumeUpDown.Enabled = true; } if (selectedToy is IOpenable) { openableCheckbox.Checked = (selectedToy as IOpenable).GetOpen(); openableCheckbox.Enabled = true; } }
private Dictionary <int, Dictionary <int, IToy> > SetupCabinet(Dictionary <int, TableConfig> TableConfigDict, Cabinet Cabinet) { Dictionary <int, Dictionary <int, IToy> > ToyAssignments = new Dictionary <int, Dictionary <int, IToy> >(); Dictionary <int, LedWizEquivalent> LedWizEquivalentDict = new Dictionary <int, LedWizEquivalent>(); foreach (IToy T in Cabinet.Toys.Where(Toy => Toy is LedWizEquivalent).ToList()) { LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T); } foreach (KeyValuePair <int, TableConfig> KV in TableConfigDict) { int LedWizNr = KV.Key; ToyAssignments.Add(LedWizNr, new Dictionary <int, IToy>()); TableConfig TC = KV.Value; if (LedWizEquivalentDict.ContainsKey(LedWizNr)) { LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr]; foreach (TableConfigColumn TCC in TC.Columns) { IToy TargetToy = null; switch (TCC.RequiredOutputCount) { case 3: //RGB Led if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2)) { //Try to get the toy try { //Toy does already exist TargetToy = (IToy)Cabinet.Toys.First(Toy => Toy is IRGBAToy && ((IRGBAToy)Toy).OutputNameRed == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName&& ((IRGBAToy)Toy).OutputNameGreen == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName&& ((IRGBAToy)Toy).OutputNameBlue == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName); } catch { //Toy does not exist. Create toyname and toy string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number); if (Cabinet.Toys.Contains(ToyName)) { int Cnt = 1; while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt))) { Cnt++; } ToyName = "{0} {1}".Build(ToyName, Cnt); } TargetToy = (IToy) new RGBAToy() { Name = ToyName, OutputNameRed = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName, OutputNameGreen = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName, OutputNameBlue = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName }; Cabinet.Toys.Add(TargetToy); } ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy); } break; case 1: //Single output //Analog output if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber)) { try { TargetToy = Cabinet.Toys.First(Toy => Toy is IAnalogAlphaToy && ((IAnalogAlphaToy)Toy).OutputName == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName); } catch { //Toy does not exist. Create toyname and toy string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number); if (Cabinet.Toys.Contains(ToyName)) { int Cnt = 1; while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt))) { Cnt++; } ToyName = "{0} {1}".Build(ToyName, Cnt); } TargetToy = (IToy) new AnalogAlphaToy() { Name = ToyName, OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName }; Cabinet.Toys.Add(TargetToy); } ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy); } break; default: //Unknow value Log.Warning("A illegal number ({0}) of required outputs has been found in a table config colum {0} for ledcontrol nr. {2}. Cant configure toy.".Build(TCC.RequiredOutputCount, TCC.Number, LedWizNr)); break; } } } } return(ToyAssignments); }
/// <summary> /// Initializes a new instance of the <see cref="ToyEventArgs"/> class. /// </summary> /// <param name="Toy">The toy.</param> public ToyEventArgs(IToy Toy) { this.Toy = Toy; }
/// <summary> /// Set position /// </summary> /// <param name="toy">The toy</param> /// <returns>Set the new position</returns> public override IPosition Execute(IToy toy) { // Do nothing on toy // return the position set in constructor return(pos); }
public DressDecorator(IToy toy, bool _type) : base(toy) { type = _type; }
public SwordDecorator(IToy toy) : base(toy) { }
public DanceDecorator(IToy toy, string _type) : base(toy) { type = _type; }
public JumpDecorator(IToy toy) : base(toy) { }
private void SetupTable(Table.Table Table, Dictionary <int, TableConfig> TableConfigDict, Dictionary <int, Dictionary <int, IToy> > ToyAssignments) { foreach (KeyValuePair <int, TableConfig> KV in TableConfigDict) { int LedWizNr = KV.Key; if (ToyAssignments.ContainsKey(LedWizNr)) { TableConfig TC = KV.Value; foreach (TableConfigColumn TCC in TC.Columns) { if (ToyAssignments[LedWizNr].ContainsKey(TCC.Number)) { IToy Toy = ToyAssignments[LedWizNr][TCC.Number]; int SettingNumber = 0; foreach (TableConfigSetting TCS in TCC) { SettingNumber++; IEffect Effect = null; int Layer = (TCS.Layer.HasValue ? TCS.Layer.Value : SettingNumber); if (Toy is IRGBAToy || Toy is IAnalogAlphaToy) { if (Toy is IRGBAToy) { RGBAColor ActiveColor = null; if (TCS.ColorConfig != null) { ActiveColor = TCS.ColorConfig.GetCabinetColor().GetRGBAColor(); } else { if (!TCS.ColorName.IsNullOrWhiteSpace()) { if (TCS.ColorName.StartsWith("#")) { ActiveColor = new RGBAColor(); if (!ActiveColor.SetColor(TCS.ColorName)) { ActiveColor = null; Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.ColorName })); } } else { Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.ColorName })); } } else { Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since it does not contain a color specification.".Build(SettingNumber, TCC.Number, LedWizNr)); } } if (ActiveColor != null) { if (TCS.FadingDownDurationMs > 0 || TCS.FadingUpDurationMs > 0) { //Must fade, use fadeeffect Effect = new RGBAFadeOnOffEffect() { ToyName = Toy.Name, Layer = Layer, FadeActiveDurationMs = TCS.FadingUpDurationMs, FadeInactiveDurationMs = TCS.FadingDownDurationMs, RetriggerBehaviour = RetriggerBehaviourEnum.IgnoreRetrigger, FadeMode = FadeModeEnum.CurrentToDefined, ActiveColor = ActiveColor, InactiveColor = new RGBAColor(0, 0, 0, 0) }; } else { //No fadinging, set color directly Effect = new RGBAOnOffEffect() { ToyName = Toy.Name, Layer = Layer, ActiveColor = ActiveColor, InactiveColor = new RGBAColor(0, 0, 0, 0) }; } } } else if (Toy is IAnalogAlphaToy) { AnalogAlphaValue AAV = new AnalogAlphaValue(((int)((double)TCS.Intensity * 5.3125)).Limit(0, 255)); if (TCS.FadingDownDurationMs > 0 || TCS.FadingUpDurationMs > 0) { Effect = new AnalogToyFadeOnOffEffect() { ToyName = Toy.Name, Layer = Layer, FadeActiveDurationMs = TCS.FadingUpDurationMs, FadeInactiveDurationMs = TCS.FadingDownDurationMs, RetriggerBehaviour = RetriggerBehaviourEnum.IgnoreRetrigger, FadeMode = FadeModeEnum.CurrentToDefined, ActiveValue = AAV, InactiveValue = new AnalogAlphaValue(0, 0) }; } else { Effect = new AnalogToyOnOffEffect() { ToyName = Toy.Name, Layer = Layer, ActiveValue = AAV, InactiveValue = new AnalogAlphaValue(0, 0) }; } } if (Effect != null) { Effect.Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(new object[] { LedWizNr, TCC.Number, SettingNumber, Effect.GetType().Name }); MakeEffectNameUnique(Effect, Table); Table.Effects.Add(Effect); if (TCS.Blink != 0) { Effect = new BlinkEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} BlinkEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DurationActiveMs = TCS.BlinkIntervalMs, DurationInactiveMs = TCS.BlinkIntervalMs }; MakeEffectNameUnique(Effect, Table); Table.Effects.Add(Effect); } if (TCS.DurationMs > 0 || TCS.Blink > 0) { int Duration = (TCS.DurationMs > 0 ? TCS.DurationMs : (TCS.Blink * 2 - 1) * TCS.BlinkIntervalMs + 1); Effect = new DurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} DurationEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DurationMs = Duration, RetriggerBehaviour = RetriggerBehaviourEnum.RestartEffect }; MakeEffectNameUnique(Effect, Table); Table.Effects.Add(Effect); } if (TCS.MinDurationMs > 0 || (Toy is IRGBAToy && EffectRGBMinDurationMs > 0) || (!(Toy is IRGBAToy) && EffectMinDurationMs > 0)) { string N = (TCS.MinDurationMs > 0 ? "MinDuratonEffect" : "DefaultMinDurationEffect"); int Min = (TCS.MinDurationMs > 0 ? TCS.MinDurationMs : (Toy is IRGBAToy ? EffectRGBMinDurationMs : EffectMinDurationMs)); Effect = new MinDurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(new object[] { LedWizNr, TCC.Number, SettingNumber, N }), TargetEffectName = Effect.Name, MinDurationMs = Min }; MakeEffectNameUnique(Effect, Table); Table.Effects.Add(Effect); } if (TCS.WaitDurationMs > 0) { Effect = new DelayEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} DelayEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DelayMs = TCS.WaitDurationMs }; MakeEffectNameUnique(Effect, Table); Table.Effects.Add(Effect); } switch (TCS.OutputControl) { case OutputControlEnum.FixedOn: Table.AssignedStaticEffects.Add(new AssignedEffect(Effect.Name)); break; case OutputControlEnum.Controlled: if (!Table.TableElements.Contains(TCS.TableElementType, TCS.TableElementNumber)) { Table.TableElements.UpdateState(TCS.TableElementType, TCS.TableElementNumber, 0); } Table.TableElements[TCS.TableElementType, TCS.TableElementNumber].AssignedEffects.Add(new AssignedEffect(Effect.Name)); break; case OutputControlEnum.FixedOff: default: break; } } } } } } } } }
public AddDress(IToy toy, string pattern) : base(toy) { this.pattern = pattern; }
public AddHelmet(IToy toy) : base(toy) { }
public AddSword(IToy toy) : base(toy) { }
public void PlayWithAnimal(IToy toy) { // handles toy values this._boredom += toy.funLevel; // handles pet preferences int pleasureAmnt = 0; // what the pet wants - what they get = pleasure level pleasureAmnt += toy.bouncy - _Prefs.bouncePref; pleasureAmnt += toy.smooth - _Prefs.smoothPref; pleasureAmnt += toy.squishey - _Prefs.squishPref; // adds to pets happiness happiness += pleasureAmnt; // fatigue effects fatigue -= (int)(toy.funLevel / 2); CalculateHealth(); }
public JumpDecorator(IToy b) : base(b) { }
public ToyDecorator(IToy toy) { _toy = toy; }
public DanceDecorator(IToy b, string a) : base(b) { dance = a; }
public StorytellingDecorator(IToy toy, bool _type) : base(toy) { type = _type; }
public StoryDecorator(IToy b, bool a) : base(b) { joke = a; }
public HelmetDecorator(IToy toy) : base(toy) { }
bool d;//true flower //If it’s flower it increases the cost of the toy by 20 and //by 19.99 if it’s dotted. public DressDecorator(IToy toy, bool b) : base(toy) { this.d = b; }
public ToyController(IToy toy, Day14AssignmentContext _context) { context = _context; this.toy = toy; }
public virtual IPosition Execute(IToy toy) { throw new NotImplementedException(); }