1

I am in the process of building a game.

I have an object GamePiece (there will also be a Card Deck also)

public enum PieceColor
{
    Blue=0,
    Yellow,
    Red,
    Green
}

public class GamePiece : PictureBox
{
    PieceColor _color;
    public PieceColor Color {
        get {

            return _color;
        }
        set
        {
            _color = value;

            if (_color == PieceColor.Blue)
                this.Image = global::GameEntities.Properties.Resources.pieceBlue;
        }
    }

What I was thinking is putting four images, one of each color into a ImageList then the above line can be changed to

  this.Image = ImageList[(int)_color];

The problem I foresee with this is that I would be creating a ImageList for every GamePiece and that is a strain on memory.

A couple options would be

  • Create a Static Class of ImageList objects, then have all pieces reference that static class
  • Create one resource bitmap with all 4 pieces on it as one image, then use size manipulation to just show the one piece
  • Leave the code the way it is and just have four different IF statements

So my questions are,

  • Is one solution preferred over the other when it comes to managing memory with the same images used over and over?
  • Is there any Design Patterns when it comes to display images, or any other related Game Concepts that I could study up on?

Thank you

4

1 回答 1

1

创建一个存储图像的单例类并创建获取颜色并返回图像图标的 getImage 方法。

于 2013-03-01T17:43:58.657 回答