Exemple #1
0
        public static int CalculateDifference(cType one, cType two)
        {
            ExtendendList <cType> cTmp = new ExtendendList <cType>();

            foreach (string item in Enum.GetNames(typeof(cType)))
            {
                cType tmp = cType.Default;
                if (Enum.TryParse <cType>(item, out tmp))
                {
                    cTmp.Add(tmp);
                }
            }
            return(Structure.Abs(cTmp.IndexOf(one) - cTmp.IndexOf(two)));
        }
Exemple #2
0
        public static bool CanMoveAllCards(ExtendendList <Cart> lst)
        {
            ExtendendList <Cart> activeCards = Cart.GetActiveCards(lst);

            if (lst.Count == 1)
            {
                return(true);
            }

            int diff = 0;

            for (int s = 0; s <= lst.Count - 1; s++)
            {
                if (s + 1 > lst.Count - 1)
                {
                    // Check if all cards are the same color, otherwise it isn't possible to move.
                    GameMode mdr = GameMode.Black;
                    for (int y = 0; y <= lst.Count - 1; y++)
                    {
                        if (y == 0)
                        {
                            mdr = lst[y].GameMode_;
                        }
                        else
                        {
                            if (mdr != lst[y].GameMode_)
                            {
                                return(false);
                            }
                        }
                    }

                    return(true);
                }
                diff = Cart.CalculateDifference(lst[s].ccType, lst[s + 1].ccType);
                if (Structure.Abs(diff) != 1)
                {
                    return(false);
                }
            }

            return(false);
        }
Exemple #3
0
        public static bool CanMoveCards(ExtendendList <Cart> ct)
        {
            List <Cart.cType> cmrList = new List <Cart.cType>();

            foreach (string tmp in Enum.GetNames(typeof(Cart.cType)))
            {
                Cart.cType d = Cart.cType.Default;
                if (Enum.TryParse <Cart.cType>(tmp, out d))
                {
                    cmrList.Add(d);
                }
            }
            cmrList.Reverse();
            for (int i = 0; i <= ct.Count - 2; i++)                                                          // Not - 1, but - 2. Last item won't needed.
            {
                int diff = Structure.Abs(cmrList.IndexOf(ct[i].ccType) - cmrList.IndexOf(ct[i + 1].ccType)); // It works within three cards.
                if (diff != 1)
                {
                    return(false);
                }
            }
            return(true);
        }