//-----------------------------------------------------------------------------
// ShuffleAnimation.cs
//
// Abstract base class for card shuffle animations
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace CardsFramework
{
///
/// Abstract base class for shuffle animations. Defines the interface for
/// creating different types of card shuffles (riffle, overhand, Hindu, etc.)
///
public abstract class ShuffleAnimation
{
///
/// The position where the shuffle animation takes place (typically dealer position)
///
public Vector2 Position { get; set; }
///
/// Total duration of the shuffle animation
///
public TimeSpan Duration { get; set; }
///
/// The card game this animation belongs to
///
protected CardsGame CardGame { get; private set; }
///
/// Random number generator for animation variations
///
protected Random Random { get; private set; }
///
/// Size of a single card
///
protected Vector2 CardSize { get; private set; }
///
/// Callback to invoke when the animation starts
///
public Action OnAnimationStart { get; set; }
///
/// Callback to invoke when the animation completes
///
public Action OnAnimationComplete { get; set; }
///
/// Creates a new shuffle animation
///
/// The card game instance
/// Position where shuffle occurs
/// How long the animation should last
/// Size of each card
protected ShuffleAnimation(CardsGame cardGame, Vector2 position, TimeSpan duration, Vector2 cardSize)
{
CardGame = cardGame;
Position = position;
Duration = duration;
CardSize = cardSize;
Random = new Random();
}
///
/// Creates the animated card components for this shuffle animation.
/// Each shuffle type implements this differently.
///
/// The list of cards to shuffle
/// Shared sprite batch for rendering
/// Transformation matrix for scaling
/// List of animated card components with animations applied
public abstract List CreateAnimatedCards(
List deck,
SpriteBatch spriteBatch,
Matrix globalTransformation);
///
/// Helper method to create a standard card component
///
protected AnimatedCardsGameComponent CreateCardComponent(
TraditionalCard card,
SpriteBatch spriteBatch,
Matrix globalTransformation,
Vector2 startPosition,
bool faceDown = true)
{
var cardComponent = new AnimatedCardsGameComponent(card, CardGame, spriteBatch, globalTransformation)
{
CurrentPosition = startPosition,
IsFaceDown = faceDown,
Visible = true
};
return cardComponent;
}
///
/// Helper to add a transition animation to a card
///
protected void AddTransition(
AnimatedCardsGameComponent card,
Vector2 destination,
TimeSpan startDelay,
TimeSpan duration)
{
var transition = new TransitionGameComponentAnimation(card.CurrentPosition, destination)
{
StartTime = DateTime.Now + startDelay,
Duration = duration
};
card.AddAnimation(transition);
}
///
/// Helper to add a scale animation to a card
///
protected void AddScale(
AnimatedCardsGameComponent card,
float startScale,
float endScale,
TimeSpan startDelay,
TimeSpan duration)
{
var scale = new ScaleGameComponentAnimation(startScale, endScale)
{
StartTime = DateTime.Now + startDelay,
Duration = duration
};
card.AddAnimation(scale);
}
}
}