0

我正在制作一款游戏,该游戏涉及在网格中查找并单击一个数字(0-9),每次单击正确的数字时都会随机化。

我想得到它,以便当您单击正确的数字时,网格会再次随机化。你会怎么做?

这就是它最终的样子:

http://puu.sh/4jphx.jpg

4

2 回答 2

3

I assume you're rendering an array of integers in order:

for (int i = 0; i < arrayOfNumbers.Length; i++ ) {
    // rendering here
    render(arrayOfNumbers[i]);
}

If thats the case.. just randomize the array after a successful click.. somewhat like this:

var rnd = new System.Random();
var arrayOfNumbers = Enumerable.Range(1, 9).OrderBy(r => rnd.Next()).ToArray();

Then you can just re-render (or let your game loop continue to render the array). Since the array has changed, your rendering will too.

于 2013-09-05T04:45:18.477 回答
0

每次您检测到点击正确的数字时(我希望您知道如何执行此操作),您只需随机化您在网格中显示的数字数组:

//Fisher-Yates algorithm
Random generator = new System.Random();
int len = array.Length;
while (len > 1)
{
    len--;
    int k = generator.Next(len + 1);
    int temp = array[k];
    array[k] = array[len];
    array[len] = temp;
}
于 2013-09-05T11:22:21.347 回答