Esempio n. 1
0
        public void CheckForWin()
        {
            // Check for Winning here
            // ***************************************************************************************
            Class.Structure.Info infoR = Class.Structure.CheckWinning(this.MStructures);
            // ***************************************************************************************
            if (infoR.OK)
            {
                Class.ExtendendList <Class.Cart> toRemove = new Class.ExtendendList <Class.Cart>();
                for (int i = infoR.CurrentStructure.lstCards.IndexOf(infoR.SelectedCart); i <= infoR.CurrentStructure.lstCards.Count - 1; i++)
                {
                    toRemove.Add(infoR.CurrentStructure.lstCards[i]);
                }

                // 0 ... 1 it doesn't matter
                Cart.GameMode currentMode = toRemove[0].GameMode_;

                foreach (Class.Cart toRem in toRemove)
                {
                    infoR.CurrentStructure.lstCards.Remove(toRem);
                }
                this.ReDraw();

                // Add a structure wird currentMode to the array.
                this.WinningCards[WCounter++] = new SpecialCard(currentMode);
                this.ReDraw();

                foreach (Class.Structure s in this.MStructures)
                {
                    if (s.lstCards.Count != 0)
                    {
                        if (!(s.lstCards[s.lstCards.Count - 1].Active))
                        {
                            s.lstCards[s.lstCards.Count - 1].Active = true;
                        }
                    }
                }
            }
            bool gameend = false;

            foreach (Class.Structure current in this.MStructures)
            {
                gameend = (current.lstCards.Count == 0);
                if (!gameend)
                {
                    break;
                }
            }
            this.endOfGame = gameend;
            this.throwEvent();
            // ---------------------------------------------------------------------------------------
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public SpecialCard(Cart.GameMode mode) : base(cType.Default, mode)
 {
 }