public Animal(MutexTable table, int range, int tickTimeMsec, WanderDelegate wander, EvadeOrHuntDelegate evadeOrHunt) { _thread = new Thread(doBehaviour); _thread.SetApartmentState(ApartmentState.STA); if (table == null) throw new NullReferenceException(); _table = table; _tickTimeMsec = tickTimeMsec; if (range <= 0) throw new InvalidOperationException(); _range = range; if (evadeOrHunt == null || wander == null) throw new InvalidOperationException(); _evadeOrHunt = evadeOrHunt; _wander = wander; _symbol = new Ellipse(); Dispatcher.FromThread(_table.WindowThread).BeginInvoke(DispatcherPriority.Render, (Action)(() => { _table.DrawingGrid.Children.Add(_symbol); } )); }
public Wolf(MutexTable table, WanderDelegate wander, EvadeOrHuntDelegate evadeOrHunt) : base(table, table.WolfRange, table.WolfTickTimeMsec, wander, evadeOrHunt) { _symbol.Height = 12; _symbol.Width = 12; _symbol.Fill= System.Windows.Media.Brushes.Blue; _symbol.StrokeThickness = 2; }
public Wolf(MutexTable table, WanderDelegate wander, EvadeOrHuntDelegate evadeOrHunt) : base(table, table.WolfRange, table.WolfTickTimeMsec, wander, evadeOrHunt) { _symbol.Height = 12; _symbol.Width = 12; _symbol.Fill = System.Windows.Media.Brushes.Blue; _symbol.StrokeThickness = 2; }
public Sheep(MutexTable table, WanderDelegate wander, EvadeOrHuntDelegate evadeOrHunt) : base(table, table.SheepRange, table.SheepTickTimeMsec, wander, evadeOrHunt) { //do nothing for now _symbol.Height = 10; _symbol.Width = 10; _symbol.Stroke = System.Windows.Media.Brushes.Red; _symbol.Fill = System.Windows.Media.Brushes.Red; _symbol.StrokeThickness = 2; }
public Sheep addSheep(int x, int y, WanderDelegate wander, EvadeOrHuntDelegate evade) { if (_wolves.Count + _sheep.Count < _table.Length) { Sheep sheep = new Sheep(this, wander, evade); _sheep.Add(sheep); sheep.activate(x, y); return(sheep); } return(null); }
/// <summary> /// Add a wolf to the grid, at the specified coordinates. This does activate the wolf. /// </summary> /// <param name="x">x coordinate on the grid</param> /// <param name="y">y coordinate on the grid</param> /// <param name="wander">Function that controls the way the wolf moves when it sees no sheep</param> /// <param name="evadeOrHunt">Function that controls the way the wolf moves when it sees at least one sheep</param> /// <returns>True is it succedes, false if there are problems. This should be changed to exceptions.</returns> public Wolf addWolf(int x, int y, WanderDelegate wander, EvadeOrHuntDelegate hunt) { if (_wolves.Count + _sheep.Count < _table.Length) { Wolf wolf = new Wolf(this, wander, hunt); _wolves.Add(wolf); wolf.activate(x, y); return(wolf); } return(null); }
public Animal(MutexTable table, int range, int tickTimeMsec, WanderDelegate wander, EvadeOrHuntDelegate evadeOrHunt) { _thread = new Thread(doBehaviour); _thread.SetApartmentState(ApartmentState.STA); if (table == null) { throw new NullReferenceException(); } _table = table; _tickTimeMsec = tickTimeMsec; if (range <= 0) { throw new InvalidOperationException(); } _range = range; if (evadeOrHunt == null || wander == null) { throw new InvalidOperationException(); } _evadeOrHunt = evadeOrHunt; _wander = wander; _symbol = new Ellipse(); Dispatcher.FromThread(_table.WindowThread).BeginInvoke(DispatcherPriority.Render, (Action)(() => { _table.DrawingGrid.Children.Add(_symbol); } )); }
/// <summary> /// Add a wolf to the grid, at the specified coordinates. This does activate the wolf. /// </summary> /// <param name="x">x coordinate on the grid</param> /// <param name="y">y coordinate on the grid</param> /// <param name="wander">Function that controls the way the wolf moves when it sees no sheep</param> /// <param name="evadeOrHunt">Function that controls the way the wolf moves when it sees at least one sheep</param> /// <returns>True is it succedes, false if there are problems. This should be changed to exceptions.</returns> public Wolf addWolf(int x, int y, WanderDelegate wander, EvadeOrHuntDelegate hunt) { if (_wolves.Count + _sheep.Count < _table.Length) { Wolf wolf = new Wolf(this, wander, hunt); _wolves.Add(wolf); wolf.activate(x, y); return wolf; } return null; }
public Sheep addSheep(int x, int y, WanderDelegate wander, EvadeOrHuntDelegate evade) { if (_wolves.Count + _sheep.Count < _table.Length) { Sheep sheep = new Sheep(this, wander, evade); _sheep.Add(sheep); sheep.activate(x, y); return sheep; } return null; }