老虎机游戏c#图像值

老虎机游戏c#图像值,c#,arrays,C#,Arrays,我在做一个吃角子老虎机游戏,这是一个简单的游戏,基本上它会将picurebox中的图像滚动成随机图像。使用此代码 PictureBox[] PictureboxArray = new PictureBox[5]; 使用这行代码分配5个PicureBox PictureboxArray[0] = pbxK; PictureboxArray[1] = pbxQueen; PictureboxArray[2] = pbxKing;

我在做一个吃角子老虎机游戏,这是一个简单的游戏,基本上它会将picurebox中的图像滚动成随机图像。使用此代码

PictureBox[] PictureboxArray = new PictureBox[5];
使用这行代码分配5个PicureBox

PictureboxArray[0] = pbxK;
            PictureboxArray[1] = pbxQueen;
            PictureboxArray[2] = pbxKing;
            PictureboxArray[3] = pbxJoker;
            PictureboxArray[4] = pbxAce;
图像是这样分配的

Image[] Rollimage = new Image[5];
            Rollimage[0] = Properties.Resources.K;
            Rollimage[1] = Properties.Resources.Queen;
            Rollimage[2] = Properties.Resources.King;
            Rollimage[3] = Properties.Resources.Joker;
            Rollimage[4] = Properties.Resources.Ace;
picturebox的初始图像是这样分配的

            pbxK.Image = Rollimage[0];
            pbxQueen.Image = Rollimage[1];
            pbxKing.Image = Rollimage[2];
            pbxJoker.Image = Rollimage[3];
            pbxAce.Image = Rollimage[4]; 
图像滚动的实际代码如下所示

for (int i = 0; i <= 4; i++)
            {
                if (PictureboxArray[i].Enabled == true)
                {

                    Roll[i] = Rnd.Next(0, 4);
                }
                PictureboxImage(PictureboxArray[i], Roll[i]); 
            }
滚动输入一个整数以保存滚动的索引

int[] Roll = new int[5];
一切正常,图片每秒滚动不同的图像,正如我预先定义的,现在我要做的是分配这个

 int[] PictureValues = new int[]{100, 225, 550, 775, 1000};
对图像

Image[] Rollimage = new Image[5];
这意味着第一个滚动图像是
Properties.Resources.K的实际值为100

等等,有没有办法做到这一点呢。。如果我正确理解了您的问题,那么一旦选择了图像,您需要一种方法将其反转回来,以便将其与值关联。一种方法可以是:

注意:显示的每个图片框都被命名为king/joker等。。因此,如果你看“老虎机”的正面,你会看到5个盒子,分别命名为pbxk、pbxQueen、pbxKing、pbxJoker、pbxAce,但它们不一定显示与其名称相关的图像

int total = 0;
for(int i=0;i<Rollimage.Length;i++)
{
    if(pbxk.Image.Equals(Rollimage[i]))
    {
        total += PictureValues[i];
    }
    if(pbxQueen...)
    {
        //Do the same thing for each pbx
    }
}
int-total=0;

对于(int i=0;i您只想更改访问它们的名称?有点困惑问题是什么。您想将一个值与数组中的每个索引关联,并且有一个并行数组与值关联。因此..对于
RollImage[i]
您的值为
PictureValues[i]
您是否希望实际将值分配到图像对象中,这样就不会有两个单独的数组?我只是想在图像停止滚动后,程序检查picturebox中的图像,然后检查该图像的值,然后将其添加到总数中,例如,如果它是
Rollimage[0]=Properties.Resource.K
那么它的值为100,来自
int[]PictureValues=newint[]{1002255507751000}
你可以使用属性和枚举来做你想做的事情。看看这个问题的答案,看看这是否对你有帮助。我找不到我需要的东西,这就像是一个非常简单的过程,我尝试使用if语句,比如
if(pbxK.Image==Rollimage[0]| pbxQueen.Image==Rollimage[0]| pbxKing.Image==Rollimage[0]| | pbxJoker.Image==Rollimage[0]| | pbxAce.Image==Rollimage[0]){testotal+=100;}
根本不起作用一点运气都没有:)到目前为止,我已经试了5天了,每天大概8个小时来解决这个问题,我就是做不到,这很简单,但我就是解决不了……当我回到一台装有vs的电脑前,我会起草一个例子,看看我们是否能在这方面有所作为。图像比较不应该太难。考虑到所有的事情,我会尝试大约一个小时后这里有一个更新谢谢!这对我所做的很有意义,我今天会尝试一下,并尽快给你反馈。Nate,一切正常,你是传奇人物,但你的代码只有在图片是静态的,而不是滚动成不同的图片时才能工作,我有一个滚动命令,就是这个
用于(int i=0;i)上面的代码片段不是为了解决您的整个问题,而是为了演示如何着手解决您的问题背后的原则。代码非常容易扩展,以解决稍微复杂的图像循环数组问题。同样,上面的代码片段演示了与solvi相关的所有原则在少量定制的情况下,解决您的编码问题。
int total = 0;
for(int i=0;i<Rollimage.Length;i++)
{
    if(pbxk.Image.Equals(Rollimage[i]))
    {
        total += PictureValues[i];
    }
    if(pbxQueen...)
    {
        //Do the same thing for each pbx
    }
}
public partial class Form1 : Form
{
    PictureBox[] PictureboxArray = new PictureBox[2];
    Image[] Rollimage = new Image[2];
    int[] pictureValues = new int[2];
    public Form1()
    {
        InitializeComponent();
        pictureValues[0] = 100;
        pictureValues[1] = 200;

        Rollimage[0] = Properties.Resources.TitleBar;
        Rollimage[1] = Properties.Resources.Untitled;

        PictureboxArray[0] = this.pictureBox1;
        PictureboxArray[1] = this.pictureBox2;
        PictureboxArray[1].Image = Rollimage[0];
        PictureboxArray[0].Image = Rollimage[0];
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int total = 0;
        for(int i = 0;i<Rollimage.Length;i++)
        {
            foreach(var box in PictureboxArray)
            {
                if(box.Image == Rollimage[i])
                {
                    total += pictureValues[i];
                }
            }
        }
        label1.Text = total.ToString();
    }
}