public static GrassArea[,] ToArray(Garden source) { var toRet = new GrassArea[source.MyField.Width / GrassArea.DefaultSizeInCm, source.MyField.Height / GrassArea.DefaultSizeInCm]; foreach (var grassArea in source.GrassInTotal) { toRet[(int)grassArea.Position.X / GrassArea.DefaultSizeInCm, (int)grassArea.Position.Y / GrassArea.DefaultSizeInCm] = grassArea; } return(toRet); }
public void Start() { _paused = false; Task.Factory.StartNew(() => { while (myGarden.LeftToMowe.Count > 0) { Update(); Console.WriteLine("X: " + myMower.Boundary.Position.X + "\t Y: " + myMower.Boundary.Position.Y); } OnFinished?.Invoke(new FinishedEventArgs(Garden.ToArray(myGarden))); }, _cancellationTokenSource.Token); }
/// <summary> /// Initializes the current simulation. /// </summary> /// <param name="field">Field (defined in count of grass areas).</param> /// <param name="mower"></param> /// <param name="rand"></param> public void Initilize(Field field, Mower mower, Random rand) { lock (Locker) { if (Rand != null) { return; } Rand = rand; } if (_initialized) { return; } myGarden = new Garden(field); myMower = mower; _initialized = true; }