2016-03-04 44 views
0

即时通讯做投币机游戏,其一个简单的,基本上它会滚在picurebox图像分成一个随机图像。使用此代码投币机游戏C#图像值

PictureBox[] PictureboxArray = new PictureBox[5]; 

5个picureboxes使用这行代码

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; 

和图片框的INTIAL图像分配被分配像

  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]); 
      } 

RND是一个新的随机

Random Rnd = new Random(); 

辊在一个int用于保存辊

int[] Roll = new int[5]; 

一切的索引工作正常,图片滚动不同图像的每一秒时间,因为我预定义了,现在是什么即时试图做的是转让本

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

到图像

Image[] Rollimage = new Image[5]; 

这意味着其是Properties.Resources.K;具有100 实际值等,第一辊图像是有办法做到这一点?

+0

你只是想改变他们被访问的名字吗? – Jacobr365

+0

有点困惑问题是什么。您想要将值与数组中的每个索引关联,并且您有一个包含值的并行数组。所以..对于'RollImage [i]'你有'PictureValues [i]'的值你是否真的想把值赋给图像对象,这样你就没有两个独立的数组了? –

+0

我试图简单地做的是,在图像停止滚动后,程序检查图片框中的图像,然后检查该图像的值,然后将其添加到总的EG,如果它是'Rollimage [0] = Properties.Resource .K'然后它的值为100从'int [] PictureValues = new int [] {100,225,550,775,1000};' – ZainHikary

回答

0

所以..如果我理解正确的您的问题,一旦选择了图像,您需要一种方法来扭转它回到它具有价值相关联。一种方法可能如下:

注意:看来每个显示的图片盒都被命名为king/joker等等。所以如果你在看“slot machine”的前面,你会看到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 
    } 
} 

的唯一的事情我不是100%是比较法。此外,您可以使用图片框的ImageLocation属性来存储图像的路径,然后将其与文件名进行比较,以确定显示的图像。

示例如何比较图像:Stack Overflow Image Compare

鉴于例如,您可能想尝试==使用当前图像阵列..如果不工作,你可能需要定义位图的数组与之比较。看起来像是浪费我的记忆,但它应该工作。

编辑

下面的代码正确地求和的图像的值。我只是将两个图片框,一个控制按钮和一个标签放在一起,带有两个资源的快速示例程序。这应该演示执行你所需要的所有技术。

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(); 
    } 
} 
+0

没有运气可言:(,香港专业教育学院一直在努力了5天,到目前为止,像天要弄清楚这一点,我只是不能,它肯定它简单,但我只是无法得到解决它... – ZainHikary

+0

我将起草8小时举个例子,当我回到一台带有vs的计算机上,并且看看我们是否无法在这个地方找到某个地方时,图像比较不应该太困难,我会在大约一小时内尝试发布一个更新 –

+0

谢谢很多!这实际上是有意义的即时通讯制作,生病给它今天的尝试,并尽快给你反馈 – ZainHikary