减少计数器不工作

时间:2013-06-05 19:01:55

标签: c# image grid

我正在尝试使用我在创建多个图像时使用的数组来制作计数器,如果没有单击图像,图像应该消失一段时间,我是C#的新手,我很困惑。我认为我在大多数情况下都拥有它,但它似乎不起作用,谢谢。在代码中我包括使用这个数组的两个方法,CreateImage()创建“Mole”图像,然后将其添加到网格上的随机点,以及deleteMole(),我试图在4秒后删除这个痣

代码:

private void ChangeImage()
{
    string Moleimage = TUtils.GetIniFileString(Moleini, "ImagePath", "PictureFile", Root + "mole2.png");
    NumofImages = TUtils.GetIniInt(Moleini, "NumPictures", "pictures", 8);
    String MoleImageFunction = TUtils.GetIniFileString(Moleini, "ImagePath", "PictureFile", Root + "mole2.png");

    for (int j = 0; j > NumofImages; j++)
    {
        ListArray[j]++;
    }
    Image newImage = HoleImage();

    molePopup = MoleImage();

    int numCol = Convert.ToInt32(NumberOfColumns);

    int ranCol = randomColumns.Next(1, numCol);

    int ranRow = randomRow.Next(1, NumberofRows);


    Image mole = new Image();
    //for (int i = 0; i < NumofImages; i++)
    //{

    mole.Source = new BitmapImage(new Uri(MoleImageFunction));
    mole.Name = "Mole" + ListArray;
    mole.Width = ImageSize;
    mole.Height = ImageHeight;
    //}

    Grid.SetColumn(mole, ranCol);
    Grid.SetRow(mole, ranRow);
    grid_Main.Children.Add(mole);

    //Calling MoileLifeCounter for Mole Death
    moleLifeCounter();

    mole.MouseUp += new MouseButtonEventHandler((o, e) =>
    {
        grid_Main.Children.Remove(mole);
        MolePoints++;
    });
}

private void deleteMole()
{
    NumofImages = TUtils.GetIniInt(Moleini, "NumPictures", "pictures", 8);
    int NumberofImages;
    NumberofImages = Convert.ToInt32(NumofImages);

    for (int j  = 0; j > NumofImages; j++)
    {
        ListArray[j]--;

        if (ListArray[j] == 0)
        {
            int numCol = Convert.ToInt32(NumberOfColumns);

            int ranCol = randomColumns.Next(1, numCol);

            int ranRow = randomRow.Next(1, NumberofRows);

            Image newImage = HoleImage();

            Grid.SetColumn(HoleImage(), ranCol);
            Grid.SetRow(HoleImage(), ranRow);
            grid_Main.Children.Add(HoleImage());

            Console.WriteLine("TIMER WORKED!");
        }
        else
        {
            break;
        }
    }
}

1 个答案:

答案 0 :(得分:3)

对我来说就像从来没有输入递减计数器的循环

for (int j  = 0; j > NumofImages; j++)   // wrong!

应该是

for (int j  = 0; j < NumofImages; j++)
相关问题