Exemple #1
0
        public static ExtendendList <Cart> CreateNewCarts(Game.Mode gameMode)
        {
            ExtendendList <Class.Cart> lstCarts = new ExtendendList <Class.Cart>();

            if (gameMode == Game.Mode.OneSuit)
            {
                for (int i = 0; i <= 7; i++)
                {
                    for (int y = 1; y <= 13; y++)
                    {
                        lstCarts.Add(new Class.Cart((Class.Cart.cType)y, GameMode.Black));
                    }
                }
            }
            else
            {
                for (int i = 0; i <= 7; i++)
                {
                    bool addFlag = false;
                    for (int y = 1; y <= 13; y++)
                    {
                        lstCarts.Add(new Class.Cart((Class.Cart.cType)y, (addFlag ? GameMode.Black : GameMode.Red)));
                        addFlag = !addFlag;
                    }
                }
            }
            // List is filled now.
            Cart.Shuffle <Cart>(lstCarts);
            return(lstCarts);
        }
Exemple #2
0
 public static bool DistributeNewCars(ExtendendList <Structure> tmpLst, Game currentGame)
 {
     if (Structure.CanDistributeCards(tmpLst))
     {
         if (currentGame.OtherCards.Count != 0 && currentGame.OtherCards.Count > 9)
         {
             int count = 0;
             ExtendendList <Cart> saved = new ExtendendList <Cart>();
             foreach (Structure str in tmpLst)
             {
                 Cart toAdd = currentGame.OtherCards[count];
                 saved.Add(toAdd);
                 toAdd.Active = true;
                 str.lstCards.Add(toAdd);
                 count++;
             }
             for (int i = 0; i <= count - 1; i++)
             {
                 currentGame.OtherCards.Remove(saved[i]);
             }
             Structure.SetState(tmpLst, false);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #3
0
        public ExtendendList <T> Clone()
        {
            ExtendendList <T> tmpLst = new ExtendendList <T>();

            foreach (T tmp in base.ToArray())
            {
                tmpLst.Add(tmp);
            }
            return(tmpLst);
        }
Exemple #4
0
        public static ExtendendList <Cart> FindActiveCars(ExtendendList <Cart> lst)
        {
            ExtendendList <Cart> tmp = new ExtendendList <Cart>();

            foreach (Cart ctr in lst)
            {
                if (ctr.Active)
                {
                    tmp.Add(ctr);
                }
            }
            return(tmp);
        }
Exemple #5
0
        public static ExtendendList <Cart> GetActiveCards(ExtendendList <Cart> lstCart)
        {
            ExtendendList <Cart> cd = new ExtendendList <Cart>();

            foreach (Cart tmp in lstCart)
            {
                if (tmp.Active)
                {
                    cd.Add(tmp);
                }
            }
            return(cd);
        }
Exemple #6
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 #7
0
        public static ExtendendList <Structure> GetSelectedStructures(ExtendendList <Structure> lst)
        {
            ExtendendList <Structure> tmpLst = new ExtendendList <Structure>();

            foreach (Structure tmp in lst)
            {
                foreach (Cart tmpC in tmp.lstCards)
                {
                    if (tmpC.Selection)
                    {
                        tmpLst.Add(tmp);
                    }
                }
            }
            return(tmpLst);
        }
Exemple #8
0
        public static ExtendendList <Structure> CreateStructureList(Game currentGame)
        {
            ExtendendList <Cart>       mCarts = Class.Cart.CreateNewCarts(currentGame.GameMode);
            ExtendendList <Structure>  mStructures = new ExtendendList <Class.Structure>();
            ExtendendList <Class.Cart> tmpLst = new ExtendendList <Class.Cart>();
            int index = 0, ct = 0;

            for (int i = 0; i <= 9; i++)
            {
                Structure.SType cType  = (i >= 4) ? Structure.SType.Five : SType.Six;
                Structure       str    = new Structure(null, cType);
                int             cCards = (i >= 4) ? 5 : 6;
                for (int c = 0; c <= cCards - 1; c++)
                {
                    Cart curCart = mCarts[index];
                    //  curCart.owner = str;
                    if (c == cCards - 1)
                    {
                        curCart.Active = true;
                    }
                    tmpLst.Add(curCart);
                    index++;
                    ct++;
                }
                str.lstCards = tmpLst.Clone();
                tmpLst.Clear();
                mStructures.Add(str);
            }

            currentGame.OtherCards.Clear();
            for (int c = ct; c <= mCarts.Count - 1; c++)
            {
                currentGame.OtherCards.Add(mCarts[c]);
            }
            return(mStructures);
        }
Exemple #9
0
        public static ExtendendList <Tipp> ShowsAllTipps(ExtendendList <Structure> lst)
        {
            ExtendendList <Tipp> toReturn = new ExtendendList <Tipp>();

            foreach (Structure ms in lst)
            {
                ExtendendList <Cart> active = new ExtendendList <Cart>();
                foreach (Cart cmr in ms.lstCards)
                {
                    if (cmr.Active)
                    {
                        active.Add(cmr);
                    }
                }
                ExtendendList <Cart> proove  = new ExtendendList <Cart>();
                ExtendendList <Cart> testLst = new ExtendendList <Cart>();
                bool okay = false;
                for (int i = 0; i <= active.Count - 1; i++)
                {
                    proove.Clear();
                    for (int j = i; j <= active.Count - 1; j++)
                    {
                        proove.Add(active[j]);
                    }

                    okay = Structure.CanMoveCards(proove);
                    if (proove.Count != 1 && okay)
                    {
                        // If you try to switch more than one card, all cards have to be the same color.
                        Cart.GameMode currentMode = Cart.GameMode.Black;
                        bool          ok          = false;
                        for (int y = 0; y <= proove.Count - 1; y++)
                        {
                            if (y == 0)
                            {
                                currentMode = proove[y].GameMode_;
                            }
                            else
                            {
                                if (currentMode != proove[y].GameMode_)
                                {
                                    ok = false;
                                    break;
                                }
                            }
                        }
                        okay = ok;
                    }
                    if (okay)
                    {
                        // At first, we have have to check out, whether the structure fits to the last cart from another structure!
                        bool goOn = false;
                        foreach (Structure d1 in lst)
                        {
                            if (d1.lstCards.Count == 0)
                            {
                                goOn = true;
                            }
                            else
                            {
                                testLst.Clear();
                                testLst.Add(d1.lstCards[d1.lstCards.Count - 1]);
                                testLst.AddRange(proove);
                                goOn = Structure.CanMoveCards(testLst);
                                if (goOn)
                                {
                                    foreach (Cart cs1 in testLst)
                                    {
                                        cs1.IsTipp = true;
                                    }
                                }
                            }
                            if (goOn)
                            {
                                if (testLst.Count != 0)
                                {
                                    foreach (Cart cs1 in proove)
                                    {
                                        cs1.IsTipp = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(toReturn);
        }
Exemple #10
0
        public static Info CheckWinning(ExtendendList <Structure> lst)
        {
            // Idea: Create a structure for the first to last, then for the second to the last and ...
            // If a structure fits to the here created structure then returns the structure.
            Info toRetrun = new Info();
            // Create mainList:
            ExtendendList <Cart.cType> mainList = new ExtendendList <Cart.cType>();

            foreach (string cmr in Enum.GetNames(typeof(Class.Cart.cType)))
            {
                mainList.Add((Class.Cart.cType)Enum.Parse(typeof(Class.Cart.cType), cmr));
            }
            mainList.Reverse();
            mainList.Remove(Cart.cType.Default);

            foreach (Structure curStr in lst)
            {
                // Filter active cars.
                ExtendendList <Cart> active = new ExtendendList <Cart>();
                foreach (Cart mCart in curStr.lstCards)
                {
                    if (mCart.Active)
                    {
                        active.Add(mCart);
                    }
                }
                for (int i = 0; i <= active.Count - 1; i++)
                {
                    ExtendendList <Cart> compare = new ExtendendList <Cart>();
                    for (int j = i; j <= active.Count - 1; j++)
                    {
                        compare.Add(active[j]);
                    }
                    // Compare these lists
                    if (Structure.CompareLists(mainList, compare))
                    {
                        toRetrun.CurrentStructure = curStr;
                        Cart.GameMode currentState = Cart.GameMode.Black;

                        for (int k = 0; k <= compare.Count - 1; k++)
                        {
                            if (k == 0)
                            {
                                currentState = compare[k].GameMode_;
                            }
                            else
                            {
                                if (currentState != compare[k].GameMode_)
                                {
                                    toRetrun.OK = false;
                                    break;
                                }
                                else
                                {
                                    toRetrun.OK = true;
                                }
                            }
                        }

                        if (compare.Count > 0)
                        {
                            toRetrun.SelectedCart = compare[0];
                        }
                        return(toRetrun); // We don't go on in the loop, we want to leave here and break leaves only one loop, but there are another, so it is easier.
                    }
                }
            }
            return(toRetrun);
        }
Exemple #11
0
        private void CurrentRenderer_MouseDown(MouseEventArgs e)
        {
            Class.Structure.Info strM = Class.Structure.FindByLocation(this.currentGame.MStructures, e.Location);
            if (strM.CurrentStructure != null)
            {
                if (Class.Structure.GetState(this.currentGame.MStructures))
                {
                    if (oldOne == strM.CurrentStructure)
                    {
                        Class.Structure.SetState(this.currentGame.MStructures, false);
                        this.Invalidate();
                        return;
                    }
                    Class.Structure oldStructure = Class.Structure.GetSelectedStructures(this.currentGame.MStructures)[0];
                    // --------------------------------------------------------------------------------------
                    Class.ExtendendList <Class.Cart> items = new Class.ExtendendList <Class.Cart>();
                    foreach (Class.Cart cC in oldStructure.lstCards)
                    {
                        if (cC.Active && cC.Selection)
                        {
                            items.Add(cC);
                        }
                    }

                    bool canMoveStructureWithMoreThanThreeCards = Class.Structure.CanMoveCards(items);
                    bool canGoOn = false;

                    if (strM.CurrentStructure.lstCards.Count == 0)
                    {
                        canGoOn = canMoveStructureWithMoreThanThreeCards;
                    }
                    else if (items.Count < 2)
                    {
                        Class.Cart fCardOldOne = items[0];
                        Class.Cart fCardNewOne = strM.CurrentStructure.lstCards[strM.CurrentStructure.lstCards.Count - 1];
                        // Calculate the difference now!
                        int diff = Class.Cart.CalculateDifference(fCardOldOne.ccType, fCardNewOne.ccType);
                        canGoOn = (diff == 1);
                    }
                    else
                    {
                        if (canMoveStructureWithMoreThanThreeCards)
                        {
                            // Proove: First card of the new structure have to be a difference from 1 to the first card in the structrue(oldone)
                            Class.Cart fCardOldOne = items[0];
                            Class.Cart fCardNewOne = strM.CurrentStructure.lstCards[strM.CurrentStructure.lstCards.Count - 1];
                            // Calculate the difference now!
                            int diff = Class.Cart.CalculateDifference(fCardOldOne.ccType, fCardNewOne.ccType);
                            canGoOn = (diff == 1);
                        }
                    }
                    if (!canGoOn)
                    {
                        System.Console.Beep();
                        foreach (Class.Cart c in items)
                        {
                            c.Selection = false;
                        }
                        this.Invalidate();
                        return;
                    }
                    oldOne = null;
                    Class.ExtendendList <Class.Cart> tmp = new Class.ExtendendList <Class.Cart>();
                    foreach (Class.Cart cC in oldStructure.lstCards)
                    {
                        if (cC.Active && cC.Selection)
                        {
                            tmp.Add(cC);
                            strM.CurrentStructure.lstCards.Add(cC);
                        }
                    }
                    Class.Structure.SetState(oldStructure, false);
                    Class.Structure.SetLastCartActiveIfPossible(oldStructure);
                    foreach (Class.Cart curCart in tmp)
                    {
                        oldStructure.lstCards.Remove(curCart);
                    }
                    if (oldStructure.lstCards.Count != 0)
                    {
                        oldStructure.lstCards[oldStructure.lstCards.Count - 1].Active = true;
                    }
                    this.Invalidate();
                    this.currentGame.CheckForWin();
                }
                else
                {
                    Class.Structure.SetState(this.currentGame.MStructures, false);
                    if (strM.SelectedCart == null)
                    {
                        return;
                    }
                    strM.SelectedCart.Selection = true;
                    oldOne = strM.CurrentStructure;

                    bool tryFinding = Class.Cart.CanMoveAllCards(this.currentGame.GetShouldSelectedCards(strM));
                    if (!tryFinding && this.currentGame.GetShouldSelectedCards(strM).Count == 0)
                    {
                        Class.ExtendendList <Class.Cart> lstCards = new Class.ExtendendList <Class.Cart>();
                        lstCards.Add(strM.SelectedCart);
                        tryFinding = Class.Cart.CanMoveAllCards(lstCards);
                    }

                    if (tryFinding)
                    {
                        Class.ExtendendList <Class.Cart> shouldSelected = new Class.ExtendendList <Class.Cart>();
                        // Select carts, which are under this cart
                        int index = strM.CurrentStructure.lstCards.IndexOf(strM.SelectedCart);
                        if (index != -1)
                        {
                            for (int i = index + 1; i <= strM.CurrentStructure.lstCards.Count - 1; i++)
                            {
                                Class.Cart current = strM.CurrentStructure.lstCards[i];
                                current.Selection = true;
                            }
                        }
                    }
                    else
                    {
                        strM.SelectedCart.Selection = false;
                        Console.Beep();
                    }

                    this.currentGame.CheckForWin();
                    this.Invalidate();
                }
            }
        }