Beispiel #1
0
    /// <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);
    }
Beispiel #2
0
    /// <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);
    }
        public void ShouldPushItemWithEvents()
        {
            // arrange
            var expected = "1";
            var target = new ObservableStack<string>();

            // act
            Assert.PropertyChanged( target, "Count", () => target.Push( expected ) );

            // assert
            Assert.Equal( 1, target.Count );
            Assert.Equal( expected, target.Peek() );
        }
        public void ShouldPeekItem()
        {
            // arrange
            var target = new ObservableStack<string>();

            target.Push( "2" );
            target.Push( "1" );
            target.Push( "3" );

            // act
            var actual = target.Peek();

            // assert
            Assert.Equal( "3", actual );
        }
Beispiel #5
0
    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
Beispiel #8
0
        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;
        }
        public void ShoulNotdPeekItemWhenEmpty()
        {
            // arrange
            var target = new ObservableStack<string>();

            // act
            Assert.Throws<InvalidOperationException>( () => target.Peek() );

            // assert
        }
 private bool IsValidPlacing(ObservableStack<TowerPlate> tower,
                             TowerPlate plate) =>
                         tower.Count != 0 ? tower.Peek() > plate : true;