public async Task Replace() { var stack = new ObservableStack <int>(); // Initialize stack to be replaced stack.Push(13); stack.Push(37); // Replace all elements stack.Replace(1, 2, 3); Assert.AreEqual(Optional.Some(3), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.Some(2), await stack.PeekUnder.FirstAsync()); // Pop them off again stack.Pop(); Assert.AreEqual(Optional.Some(2), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.Some(1), await stack.PeekUnder.FirstAsync()); stack.Pop(); Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync()); stack.Pop(); Assert.AreEqual(Optional.None <int>(), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync()); // Push after it was cleared stack.Push(1); Assert.AreEqual(1, stack.Value); Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync()); }
//Removes item from the slot public void RemoveItem(Item item) { if (!IsEmpty) { InventoryScript.MyInstance.OnItemCountChanged(items.Pop()); } }
public void RemoveItem() { if (!IsEmpty) { items.Pop(); } }
} //end of the function Additems public void RemoveItem(Item item) { if (!IsEmpty) { items.Pop(); } }//end of RemoveItem function
public async Task PopScope() { _scope.Pop(); var scope = _scope.Value; await RecordState(scope.Root, scope.CurrentSelection.Value); }
/// <summary> /// Places a stack of items in a new slot of the bags or tries to stack them if they are of the same type /// </summary> /// <param name="newItems"></param> /// <returns></returns> public bool AddItems(ObservableStack <Item> newItems) { // if the slot is empty or if the slot has items of the same type if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType()) { // how many items do I have in my hand? int count = newItems.Count; // for each of the items I have in my hand for (int i = 0; i < count; i++) { // if the stack is full if (IsFull) { // then stop trying to add items to it return(false); } // if its not full then add the current iteration of the items in my hand AddItem(newItems.Pop()); } // we managed to get through all the items and we have no more items in our hand return(true); } // this slot is not empty or the things there are not of the same type so the function cannot do anything return(false); }
/// <summary> /// Responsible for trying to add the items to the slot. /// </summary> /// <param name="newItems">the stack of new items</param> /// <returns></returns> public bool AddItems(ObservableStack <Item> newItems) { if (newItems.Peek().GetInventoryType() != slotType && slotType != InventoryType.None) { return(false); } if (IsEmpty || newItems.Peek().GetName() == item.GetName()) { int count = newItems.Count; for (int i = 0; i < count; i++) { if (IsFull) { return(false); } AddItem(newItems.Pop()); } return(true); } return(false); }
public async Task PushPopAndPushAgain() { var stack = new ObservableStack <int>(); // Push one element stack.Push(1); Assert.AreEqual(1, stack.Value); Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync()); // Pop it back to empty var pop1 = stack.Pop(); Assert.AreEqual(1, pop1); Assert.Throws <InvalidOperationException>(() => { var a = stack.Value; }); Assert.AreEqual(Optional.None <int>(), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync()); // Push two elements stack.Push(1); stack.Push(2); Assert.AreEqual(2, stack.Value); Assert.AreEqual(Optional.Some(2), await stack.Peek.FirstAsync()); Assert.AreEqual(Optional.Some(1), await stack.PeekUnder.FirstAsync()); }
/** Remove Item from Slot */ public void RemoveItem(Item item) { if (!IsEmpty) { items.Pop(); background.color = new Color(0, 0, 0, 0); // keine sinnvolle Lösung. der Background sollte EIGENTLICH mit dem Item wieder popen } }
public void RemoveItem(Item item) { if (!IsEmpty) { items.Pop(); //UIManager.MyInstance.UpdateStackSize(this); } }
public void RemoveItem(Item item) { if (!IsEmpty && item == MyItem) //I added this, because otherwise, for some reason, the inventoryslot wanted to remove the sword instead of the bow { //The item is being called from the Item script. //Debug.Log("The code has reached the slot to remove the item: " + item.name); //Debug.Log("In this slot there is a " + MyItem); itemStack.Pop(); //removes item } }
public void ShouldNotPopItemWhenEmpty() { // arrange var target = new ObservableStack<string>(); // act Assert.Throws<InvalidOperationException>( () => target.Pop() ); // assert }
/// <summary> /// Redo the last undone action. /// </summary> public void Redo() { if (_redoableActions.Count <= 0) { return; } IUndoable action = _redoableActions.Pop(); action.ExecuteDo(); _undoableActions.Push(action); _saveLoadManager.Unsaved = true; }
public void ShouldPopItemWithEvents() { // arrange var expected = "1"; string actual = null; var target = new ObservableStack<string>(); target.Push( expected ); // act Assert.PropertyChanged( target, "Count", () => actual = target.Pop() ); // assert Assert.Equal( 0, target.Count ); Assert.Equal( expected, actual ); }
public bool AddItems(ObservableStack <Item> newItems) { if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType()) { int count = newItems.Count; for (int i = 0; i < count; i++) { if (IsFull) { return(false); } AddItem(newItems.Pop()); } return(true); } return(false); }
public bool AddItems(ObservableStack <Item> newItems) { if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType()) { int count = newItems.Count; for (int i = 0; i < count; i++) { if (IsFull) { Debug.Log("The slot is full"); return(false); } AddItem(newItems.Pop()); //puts all items in the slot if its not full } return(true); } return(false); }
}//end of AddItem function public bool AddItems(ObservableStack <Item> newItems) { if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType()) //check for empty slot or items are same type { int count = newItems.Count; //if the above condition matches set the count of items for (int i = 0; i < count; i++) // take all the item one by one and put it in the new slot { if (IsFull) { return(false); }//end of if inside for loop AddItem(newItems.Pop()); } //end of for return(true); } //end of if return(false); } //end of the function Additems
public NavigationService(ISettings settings, IViewModelLocator locator) { _settings = settings; _locator = locator; _viewModelLocator.Add(Screen.Login, () => locator.LoginViewModel); _viewModelLocator.Add(Screen.AgentMeeting, () => locator.AgentMeetingViewModel); _viewModelLocator.Add(Screen.MeetingList, () => locator.MeetingListViewModel); _viewModelLocator.Add(Screen.ClientMeeting, () => locator.ClientMeetingViewModel); _viewModelLocator.Add(Screen.Lobby, () => locator.LobbyViewModel); // Setup the backstack var stackChanged = Observable.FromEventPattern <NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>( h => _navigationStack.CollectionChanged += h, h => _navigationStack.CollectionChanged -= h).Select(p => p.EventArgs); var count = stackChanged.Select(_ => _navigationStack.Count); var backCmd = new ReactiveCommand(count.Select(v => v > 1)); _backCmdSub = backCmd.RegisterAsyncAction(_ => _navigationStack.Pop(), Scheduler.Immediate).Subscribe(); BackCommand = backCmd; var latestAfterPop = stackChanged .Where(args => args.Action == NotifyCollectionChangedAction.Remove) .Select(a => new { Popped = (Tuple <Screen, IScreenViewModel>)a.OldItems[0], Latest = _navigationStack.Peek() }); _poppedSub = latestAfterPop .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(t => { // Navigate away from the prev one t.Popped.Item2.OnNavigatedAway(); // Nav to the prev one t.Latest.Item2.OnNavigatedTo(NavigateDirection.Back); CurrentViewModel = t.Latest.Item2; Screen = t.Latest.Item1; // Cleanup t.Popped.Item2.Dispose(); }); var added = stackChanged .Where(args => args.Action == NotifyCollectionChangedAction.Add) .Select(a => { var t = (Tuple <Screen, IScreenViewModel>)a.NewItems[0]; return(Tuple.Create(t.Item1, t.Item2, NavigateDirection.Forward)); }); var removed = latestAfterPop.Select(t => Tuple.Create(t.Latest.Item1, t.Latest.Item2, NavigateDirection.Back)); var connectable = added.Merge(removed).Publish(); _currentScreenSub = connectable.Connect(); // make it hot CurrentScreen = connectable; }