Example #1
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();
                }
            }
        }
Example #2
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();

                }
            }
        }
Example #3
0
 public Info(Structure CurrentStructure, Cart SelectedCart, bool OK)
 {
     this.CurrentStructure = CurrentStructure;
     this.SelectedCart = SelectedCart;
     this.OK = OK;
 }
Example #4
0
 public static void SetState(Structure lst, bool state)
 {
     foreach (Cart c in lst.lstCards)
         c.Selection = state;
 }
Example #5
0
        public static bool SetLastCartActiveIfPossible(Structure lst)
        {
            if (lst.lstCards.Count == 0)
                return false;

            lst.lstCards[lst.lstCards.Count - 1].Active = true;
            return true;
        }
Example #6
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;
        }