vendredi 16 mars 2018

Drawing an object in Monogame from another Dll

I am creating a card game using .NET Standard and Monogame. I have created and tested the core of the game in a dll (PlayingCards.Common.Dll).

I now need to add a GUI layer and am having problems with the design.

For example, my card class lives in PlayingCards.Common.Dll. The GUI needs to use this player card but add a texture, position and possibly an update.

I am aware that I can use the decorator pattern and create a GuiCard that holds a Card and the extra functionality needed for the GUI however when my dealer class deals cards to users (As this is done in the core) they will only receive a Card and not a GuiCard.

It is also the Player class that holds a hand which contains x amount of cards so when drawing in the Gui I need to somehow draw all cards for all players....

Classes of interest:

public class Card
{
        ...

        public Card(Suit suit, Value value)
        {
            Suit = suit;
            Value = value;
            ...
        }
}

public class Dealer
{
    private readonly Deck _deck = new Deck();

    ...

    private Card DealCard() => _deck.Draw();
}


//This is in GUI.DLL
public class CardEntity
{
    ...
    private readonly Position _position;
    private readonly Card _card = new Card(Suit.Spades, Value.King);

    public CardEntity(GraphicsDevice graphicsDevice, Card card) 
    {
        _position = new Position();
        ...
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        var topLeftOfSprite = new Vector2(_position.X, _position.Y);
        var sourceRectangle = new Rectangle
        {
            X = XPosOnSpriteSheet,
            Y = YPosOnSpriteSheet,
            Height = CardTextureHeight,
            Width = CardTextureWidth - Offset
        };
        spriteBatch.Draw(_cardsSheetTexture, topLeftOfSprite, sourceRectangle, XnaColor.White);
    }
}

Thank you.

Aucun commentaire:

Enregistrer un commentaire