private void ManagePipes() { if (!Pipes.Any() || Pipes.Last().DistanceFromLeft < GameWidth / 2) { Pipes.Add(new PipeModel(GameWidth)); } if (Pipes.First().IsOffScreen()) { Pipes.Remove(Pipes.First()); } }
void ManagePipes() { if (!Pipes.Any() || Pipes.Last().DistanceFromleft <= 250) { Pipes.Add(new PipeModel()); } if (Pipes.First().IsOffScreen()) { Pipes.Remove(Pipes.First()); } }
private void ManagePipes() { if (Pipes.Count == 0 || Pipes.Last().DistanceFromLeft <= 250) { Pipes.Add(new PipeModel()); } if (Pipes[0].IsOffScreen()) { Pipes.Remove(Pipes[0]); } }
public void ManagePipes() { //if the list of pipes don't have any objects in it... //OR if the last pipe in the list is halfway across the screen... if (!Pipes.Any() || Pipes.Last().DistanceFromLeft <= 250) { //add another pipe to the list Pipes.Add(new PipeModel()); } //if it is true that the first pipe in the list if off the screen... if (Pipes.First().IsOffScreen()) { //remove the pipe from the list of pipes Pipes.Remove(Pipes.First()); } }
private void OnStrokeCollected(SenderAwareEventArgs e) { var container = e.Sender as FrameworkElement; var eventArgs = e.OriginalEventArgs as StrokeEventArgs; Debug.Assert(eventArgs != null, "event args need to be != null"); var pg = PathGeometry.CreateFromGeometry(eventArgs.Stroke.GetGeometry()); var elementsInGeometry = HitTestHelper.GetElementsInGeometry <PipeView>(pg, container); var linksToDelete = elementsInGeometry.Select(view => view.DataContext).OfType <PipeViewModel>().ToArray(); // As user if pipes should be deleted. if (linksToDelete.Any()) { var deletePipes = MessageBox.Show("Do you want to delete pipes?", "Delete Pipes", MessageBoxButton.YesNo, MessageBoxImage.Question); if (deletePipes != MessageBoxResult.Yes) { return; } } // TODO: add method to model, which is capable of deleting more than one link safely foreach (var vm in linksToDelete) { var source = vm.Source as BaseProcessor; var target = vm.Target as BaseProcessor; if (source != null) { source.Targets.Remove(target); } if (target != null) { target.Sources.Remove(source); } Pipes.Remove(vm); } }
public async void MainLoop() { IsRunning = true; while (IsRunning) { Bird.Fall(_gravity); foreach (var pipe in Pipes) { pipe.Move(_speed); } var centeredPipe = GetCenteredPipe(); if (centeredPipe != null) { var min = 300 - 150 + centeredPipe.DistanceFromBottom; var max = 430 - 150 + centeredPipe.DistanceFromBottom - 45; if (Bird.DistanceFromBottom < min || Bird.DistanceFromBottom > max) { GameOver(); } } if (!Pipes.Any() || Pipes.Last().DistanceFromLeft < 250) { GeneratePipe(); } if (Pipes.First().DistanceFromLeft < -60) { Pipes.Remove(Pipes.First()); } await Task.Delay(20); // wait 20ms } }
public T Request <T>() where T : IWorker { List <WorkerContainer> Matches = new List <WorkerContainer>(); UI.Log(""); UI.Log(""); if (Pipes.Count > 0) { for (int i = 0; i < Pipes.Count; i++) { WorkerContainer iwc = Pipes[i]; if (iwc.Worker is T && (((iwc.Worker.WorkerType & IWorkerType.Reusable) != 0) || !iwc.Used)) { int mi = Matches.Count; Matches.Add(iwc); UI.Log($"{mi}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} "); } } } int MatchedPipes = Matches.Count; if (Services.Count > 0) { UI.Log(""); for (int i = 0; i < Services.Count; i++) { WorkerContainer iwc = Services[i]; if (iwc.Worker is T && (((iwc.Worker.WorkerType & IWorkerType.Reusable) != 0) || !iwc.Used)) { int mi = Matches.Count; Matches.Add(iwc); UI.Log($"{i}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} "); } } } UI.Log(""); if (Matches.Count == 0) { return(RequestNew <T>()); } else { PrompIndex: string r = UI.Prompt("[Enter] to create a new worker OR input index to use").Trim().ToLower(); if (string.IsNullOrEmpty(r)) { return(RequestNew <T>()); } else { if (int.TryParse(r, out int ri) && ri < Matches.Count) { WorkerContainer workerContainer = Matches[ri]; if ((workerContainer.Worker.WorkerType & IWorkerType.Reusable) == 0) { workerContainer.Used = true; Pipes.Remove(workerContainer); Services.Remove(workerContainer); } return((T)workerContainer.Worker); } else { UI.Log("What?"); goto PrompIndex; } } } }