0

我正在尝试使用创建多个图像时使用的数组来创建计数器,经过一定时间后,如果不单击图像,图像应该会消失,我是 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;
        }
    }
}
4

1 回答 1

3

在我看来,从未输入过递减计数器的循环

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

应该

for (int j  = 0; j < NumofImages; j++)
于 2013-06-05T19:12:51.680 回答