-
Notifications
You must be signed in to change notification settings - Fork 33
/
BlockQueue.cs
46 lines (38 loc) · 947 Bytes
/
BlockQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
namespace Tetris
{
public class BlockQueue
{
private readonly Block[] blocks = new Block[]
{
new IBlock(),
new JBlock(),
new LBlock(),
new OBlock(),
new SBlock(),
new TBlock(),
new ZBlock()
};
private readonly Random random = new Random();
public Block NextBlock { get; private set; }
public BlockQueue()
{
NextBlock = RandomBlock();
}
private Block RandomBlock()
{
return blocks[random.Next(blocks.Length)];
}
public Block GetAndUpdate()
{
Block block = NextBlock;
do
{
NextBlock = RandomBlock();
}
//这里不会有连续重复的块
while (block.Id == NextBlock.Id);
return block;
}
}
}