0

好的,所以我正在做一个程序,希望随机选择一个游戏并根据该类显示信息。所以现在我有

namespace Twitch_Roulette
{
    class GameClass
    {
        private string gameName;
        private string developer;
        private string publisher;
        private string releaseDate;
        private string platform;
        private string genre;
        private string numPlayers;
        private string description;
    }
}

接下来我想包含一个将成为游戏 boxart 的图像,但我该怎么做呢?

4

3 回答 3

2
namespace Twitch_Roulette
{
    class GameClass
    {
        private string gameName;
        private string developer;
        private string publisher;
        private string releaseDate;
        private string platform;
        private string genre;
        private string numPlayers;
        private string description;
        private Image boxArt;
    }
}

Image 类位于 System.Drawing 中,您可能必须在文件顶部包含 using 语句。

using System.Drawing;
于 2013-04-02T05:37:24.653 回答
1

您可以像这样访问该类:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        GameClass gameclass = new GameClass();
        gameclass.GameName = "Name of Game";
        gameclass.GameGenre = GameClass.Genre.RPG;
        //Add the rest of the fields here.
    }
}

GameClass 类如下所示:

class GameClass
{
    public enum Genre
    {
        RPG,
        MMO,
        RTS,
        Other
    }

    public enum Platform
    {
        Windows,
        Linux,
        MAC
    }

    private string gameName;
    private string developer;
    private string publisher;
    private DateTime releaseDate;
    private Platform platform;
    private Genre genre;
    private int numPlayers;
    private string description;
    private Bitmap picture;

    public string GameName
    {
        get
        {
            return gameName;
        }
        set
        {
            gameName = value;
        }
    }

    public Genre GameGenre
    {
        get
        {
            return genre;
        }
        set
        {
            genre = value;
        }
    }

    //... Other get set methods
}
于 2013-04-02T06:46:06.323 回答
0

就这么简单(System.Drawing.dll必须包含在您的参考文献中):

class GameClass
{
    //your fields

    private System.Drawing.Bitmap image;
}
于 2013-04-02T05:36:18.237 回答