Exemplo n.º 1
0
 public void DrawCascade(Graphics g, Cascade cascade)
 {
     foreach (Card card in cascade.Cards)
     {
         DrawCard(g, card);
     }
 }
Exemplo n.º 2
0
        public Cascade GetCopy()
        {
            Cascade cascade = new Cascade(X, Y);

            foreach (Card card in Cards)
            {
                Card newCard = card.GetCopy();
                cascade.Cards.AddLast(newCard);
            }
            return(cascade);
        }
Exemplo n.º 3
0
        public Tableau GetCopy()
        {
            Tableau t = new Tableau();

            foreach (Cascade cascade in cascades)
            {
                Cascade newCascade = cascade.GetCopy();
                t.cascades.AddLast(newCascade);
            }

            return(t);
        }
Exemplo n.º 4
0
        private void SelectOrderedCascadeFromCascade(Cascade cascade, int mouseX, int mouseY)
        {
            Card           card           = cascade.SelectCard(mouseX, mouseY);
            OrderedCascade orderedCascade = cascade.SelectOrderedCascade(card);

            if (orderedCascade != null)
            {
                UnselectOrderedCascade();
                UnselectCellWithCard(false);
                selectedOrderedCascade = orderedCascade;
                selectedOrderedCascade.SetSelected(true);
            }
        }
Exemplo n.º 5
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            GameData currentState = new GameData(tableau, foundations, cells, selectedOrderedCascade, selectedCellWithCard);

            gameData.Push(currentState);

            Cascade clickedCascade         = tableau.GetClickedCascade(e.X, e.Y);
            int     clickedCellIndex       = GetClickedCellIndex(e.X, e.Y);
            int     clickedFoundationIndex = GetClickedFoundationIndex(e.X, e.Y);

            if (clickedCascade != null)
            {
                if (selectedCellWithCard != null)
                {
                    // move card
                    bool isMoved = clickedCascade.TryAddCardFromCell(selectedCellWithCard);
                    if (isMoved)
                    {
                        UnselectCellWithCard(true);
                    }
                    else
                    {
                        SelectOrderedCascadeFromCascade(clickedCascade, e.X, e.Y);
                    }
                }
                else if (selectedOrderedCascade != null)
                {
                    // move ordered cascade
                    bool isMoved = clickedCascade.TryMoveOrderedCascade(selectedOrderedCascade, GetMaxNumberOfSuperMoves());
                    if (isMoved)
                    {
                        UnselectOrderedCascade();
                    }
                    else
                    {
                        SelectOrderedCascadeFromCascade(clickedCascade, e.X, e.Y);
                    }
                }
                else
                {
                    SelectOrderedCascadeFromCascade(clickedCascade, e.X, e.Y);
                }
            }
            else if (clickedCellIndex != -1)
            {
                Card card = cells[clickedCellIndex].Top();
                if (card != null)
                {
                    UnselectCellWithCard(false);
                    UnselectOrderedCascade();

                    // select new cell with card
                    card.IsSelected      = true;
                    selectedCellWithCard = cells[clickedCellIndex];
                }
                else if (selectedOrderedCascade != null)
                {
                    if (cells[clickedCellIndex].TryMove(selectedOrderedCascade))
                    {
                        UnselectOrderedCascade();
                    }
                }
            }
            else if (clickedFoundationIndex != -1)
            {
                if (selectedCellWithCard != null)
                {
                    bool isMoved = foundations[clickedFoundationIndex].TryAddCard(selectedCellWithCard.Top());
                    if (isMoved)
                    {
                        UnselectCellWithCard(true);
                    }
                }
                else if (selectedOrderedCascade != null)
                {
                    bool isMoved = foundations[clickedFoundationIndex].TryMoveOrderedCascade(selectedOrderedCascade);
                    if (isMoved)
                    {
                        UnselectOrderedCascade();
                    }
                }
            }

            Invalidate();

            if (foundations[0].Count == 13 && foundations[1].Count == 13 && foundations[2].Count == 13 && foundations[3].Count == 13)
            {
                MessageBox.Show("Congratulation. You win!!!");
            }
        }
Exemplo n.º 6
0
 public OrderedCascade(Cascade cascade)
 {
     this.cascade = cascade;
     cards        = new LinkedList <Card>();
 }