Ejemplo 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();
            // ---------------------------------------------------------------------------------------
        }
Ejemplo n.º 2
0
        public Class.ExtendendList <Class.Cart> GetShouldSelectedCards(Class.Structure.Info strM)
        {
            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; i <= strM.CurrentStructure.lstCards.Count - 1; i++)
                {
                    Class.Cart current = strM.CurrentStructure.lstCards[i];
                    shouldSelected.Add(current);
                }
            }
            return(shouldSelected);
        }
Ejemplo n.º 3
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();

                }
            }
        }
Ejemplo n.º 4
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();
            // ---------------------------------------------------------------------------------------
        }
Ejemplo n.º 5
0
 public Class.ExtendendList<Class.Cart> GetShouldSelectedCards(Class.Structure.Info strM)
 {
     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; i <= strM.CurrentStructure.lstCards.Count - 1; i++)
         {
             Class.Cart current = strM.CurrentStructure.lstCards[i];
             shouldSelected.Add(current);
         }
     }
     return shouldSelected;
 }