Exemple #1
0
        private bool SlotToSlot(int prevSlotNo, Hashtable prevArmies, int slotNo, Hashtable armies)
        {
            // get previous army InCastle
            if (!prevArmies.ContainsKey(prevSlotNo))
            {
                // error
                return false;
            }
            Army prevArmy = (Army)prevArmies[prevSlotNo];

            if (armies.ContainsKey(slotNo))
            {
                // merge / exchange slot
                Army army = (Army)armies[slotNo];

                if (army._id == prevArmy._id)
                {
                    // merge

                    if (prevArmies.Count <= 1)
                    {
                        // hero must has at least one slot
                        if (IsHeroEmptyAfterRemove(prevArmies))
                        {
                            MessageBox.Show("Hero must has a least 1 army.");
                            return false;
                        }
                    }

                    army._qty += prevArmy._qty;
                    prevArmies.Remove(prevSlotNo);

                    // set hero Id
                    army._heroId = GetHeroId(armies);
                }
                else
                {
                    // exchange slot
                    prevArmy._slotNo = slotNo;
                    army._slotNo = prevSlotNo;

                    armies[slotNo] = prevArmy;
                    prevArmies[prevSlotNo] = army;

                    // set hero Id
                    prevArmy._heroId = GetHeroId(armies);
                    army._heroId = GetHeroId(prevArmies);
                }
            }
            else
            {
                // move

                // if not move in same armies, check empy armies
                if (!prevArmies.Equals(armies) && prevArmies.Count <= 1)
                {
                    // hero must has at least one slot
                    if (IsHeroEmptyAfterRemove(prevArmies))
                    {
                        MessageBox.Show("Hero must has a least 1 army.");
                        return false;
                    }
                }

                prevArmy._slotNo = slotNo;

                if (armies.ContainsKey(slotNo))
                    armies[slotNo] = prevArmy;
                else
                    armies.Add(slotNo, prevArmy);

                prevArmies.Remove(prevSlotNo);

                // set hero Id
                prevArmy._heroId = GetHeroId(armies);
            }

            return true;
        }
Exemple #2
0
        private bool IsHeroEmptyAfterRemove(Hashtable prevArmies)
        {
            // hero must has at least one slot
            if ((this._town._heroVisit != null && prevArmies.Equals(this._town._heroVisit._armyKSlots))
                || (this._town._heroInCastle != null && prevArmies.Equals(this._town._heroInCastle._armyKSlots)))
                return true;

            return false;
        }