public DealAnimation(Board board, List <Card> cardsToDeal) { _board = board; _cardAnimations = new List <CardAnimationView>(Board.StackCount); // TODO: Revive this rule at some point? /*int cardCount = 0; * int stacksEmpty = 0; * for (int i = 0; i < Board.StackCount; i++) * { * int stackSize = board.GetStack(i).Count; * if (stackSize == 0) * stacksEmpty++; * cardCount += stackSize; * } * * if (stacksEmpty > 0 && cardCount >= Board.StackCount) * { * string errorMsg = CardResources.Strings.GetString("EmptyStacksDealError"); * _board.View.AddError(errorMsg); * return; * }*/ int dealPos = board.CountOfExtraDealingsLeft() - 1; const double delay = 0.1; const double duration = 0.2; var bounds = board.View.GetViewArea(); var cardSize = board.View.GetCardSize(); var startPoint = new Point(bounds.Width - cardSize.X - dealPos * 25, bounds.Height - cardSize.Y); for (int i = 0; i < cardsToDeal.Count; i++) { Card cardDealt = cardsToDeal[i]; cardDealt.Reveal(); cardDealt.View.Animating = true; Point destPoint = board.View.GetLocationOfCardInStack(board.GetStack(i), board.GetStack(i).Count); var animation = new CardAnimationView(cardDealt, i * delay, duration, startPoint, destPoint, cardSize.X, cardSize.Y); _cardAnimations.Insert(0, animation); } _stopTime = DateTime.Now.AddSeconds(cardsToDeal.Count * delay + duration); UpdateCardAnimations(); }
public void Render(Rectangle rc, SpriteBatch batch) { // TODO:V2: Render move count and score? batch.Begin(); batch.Draw(CardResources.GradientTex, rc, Color.Green); batch.End(); int cardWidth = rc.Width / 10 - 4; int cardHeight = (int)(cardWidth * (3.5 / 2.5)); int spacing = (rc.Width - cardWidth * Board.StackCount) / (Board.StackCount - 1); // Draw the game board for (int i = 0; i < Board.StackCount; i++) { int stackSize = _board.GetStack(i).Count; if (stackSize == 0) { var cardRect = new Rectangle(i * (cardWidth + spacing), 0, cardWidth, cardHeight); batch.Begin(); batch.Draw(CardResources.PlaceholderTex, cardRect, Color.White); batch.End(); } else { int stackCount = _board.GetStack(i).Count - (_currentAction == CardAction.Dragging && i == _currentStack ? _cardsInAction.Count : 0); for (int c = 0; c < stackSize; c++) { Card card = _board.GetStack(i).GetCard(c); if (!card.View.Animating && c < stackCount) { card.View.Render(batch); } } } } // Draw the current mover overlay if (_currentAction == CardAction.Moving) { CardStack stack = _board.GetStack(_currentStack); int stackSize = stack.Count; Point pt = _board.View.GetLocationOfCardInStack(_board.GetStack(_currentStack), stackSize - _cardsInAction.Count); Point pt2 = _board.View.GetLocationOfCardInStack(_board.GetStack(_currentStack), stackSize - 1); Point size = _board.View.GetCardSize(); var overlayRect = new Rectangle(pt.X, pt.Y, size.X, pt2.Y - pt.Y + size.Y); overlayRect.Inflate(size.X / 20, size.Y / 20); var topRect = new Rectangle(overlayRect.Left, overlayRect.Top, overlayRect.Width, size.Y / 4); var bottomRect = new Rectangle(overlayRect.Left, overlayRect.Bottom - topRect.Height, overlayRect.Width, topRect.Height); var centerRect = new Rectangle(overlayRect.Left, overlayRect.Top + topRect.Height, overlayRect.Width, overlayRect.Height - topRect.Height * 2); batch.Begin(); batch.Draw(CardResources.HighlightEndTex, topRect, Color.White); batch.Draw(CardResources.HighlightEndTex, bottomRect, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0.0f); batch.Draw(CardResources.HightlightCenterTex, centerRect, Color.White); batch.End(); } // Draw the extra stacks for (int i = 0; i < _board.CountOfExtraDealingsLeft(); i++) { var cardRect = new Rectangle(rc.Width - cardWidth - i * 25, rc.Height - cardHeight, cardWidth, cardHeight); batch.Begin(); batch.Draw(CardResources.CardBackTex, cardRect, Options.CardBackColor); batch.End(); } // Draw the undo button Color undoColor = (_board.CanUndo() ? Color.White : Color.Multiply(Color.White, 0.4f)); batch.Begin(); batch.Draw(CardResources.UndoTex, _undoButtonRect, undoColor); batch.End(); // Draw the completed stacks for (int i = 0; i < _board.CompletedCount(); i++) { Card completedCard = _board.GetCompletedStack(i); completedCard.View.Render(batch); } // Draw the cards being dragged if (_currentAction == CardAction.Dragging) { foreach (Card card in _cardsInAction) { card.View.Render(batch); } } if (_board.IsBoardClear()) { var winTextSize = CardResources.WinFont.MeasureString(Strings.Game_WinMessage); var winPos = new Vector2(_viewRect.Width / 2.0f - winTextSize.X / 2, _viewRect.Height / 2.0f - winTextSize.Y / 2); batch.Begin(); batch.DrawString(CardResources.WinFont, Strings.Game_WinMessage, winPos, Color.Black); batch.End(); if (_completed) { var newGameSize = CardResources.AgainFont.MeasureString(Strings.Game_Again); var pos = new Vector2(_viewRect.Width / 2.0f - newGameSize.X / 2, _viewRect.Height / 2.0f - newGameSize.Y / 2 + winTextSize.Y); batch.Begin(); batch.DrawString(CardResources.AgainFont, Strings.Game_Again, pos, Color.Black); batch.End(); } } else if (Errors.Count > 0) { } foreach (Animation animation in _currentAnimations) { animation.Render(batch); } if (_currentAction == CardAction.Selecting) { batch.Begin(); batch.Draw(CardResources.BlankTex, _board.View.GetViewArea(), new Color(0, 0, 0, 128)); batch.End(); foreach (CardAnimationView animation in _cardsSelectionAnimation) { animation.Render(batch); } } }