简体   繁体   English

如何使用队列随机化图像?

[英]How do I use Queues to randomize images?

I previously asked a question about randomizing images in Windows Form application (Visual Studio) for an Uno game.我之前问过一个关于在 Windows 窗体应用程序 (Visual Studio) 中为 Uno 游戏随机化图像的问题。 I was suggested an approach using queues.有人建议我使用队列的方法。 I'm afraid that I can't get it to work, mostly because I can't figure out how to queue the files and then dequeue them when the files are applied to the image boxes.恐怕我无法让它工作,主要是因为我不知道如何对文件进行排队,然后在将文件应用于图像框时将它们出列。 How can I do this?我怎样才能做到这一点?

Forgot using queues for randomizing.忘记使用队列进行随机化。 What you need to do is:你需要做的是:

  1. Create Card Objections with everything you need使用您需要的一切创建卡片异议
  2. Create a List of the Cards创建卡片列表
  3. Shuffle the list随机播放列表

Here is an example of how to do that这是一个如何做到这一点的例子

private static Random rng = new Random();
public static void Shuffle<T>(this IList<T> list)  
{  
    int n = list.Count;  
    while (n > 1) {  
        n--;  
        int k = rng.Next(n + 1);  
        T value = list[k];  
        list[k] = list[n];  
        list[n] = value;  
    }  
}
  1. Create a new queue from the list var queue = new Queue(list);从列表中创建一个新队列var queue = new Queue(list);
  2. Use the Enqueue and Dequeue commands to draw.使用EnqueueDequeue命令进行绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM