示例#1
0
        /// <summary>
        /// Creates a new random block.
        /// </summary>
        /// <returns></returns>
        public Block GetNewBlock()
        {
            Block newBlock;

            if (bag.Count == 0)
            {
                FillBag();
            }

            //Retrieve random block from bag
            int randomValue = rand.Next(0, bag.Count);
            BlockTypes shapeType = bag[randomValue];
            bag.RemoveAt(randomValue);
            
            //Retrieve the block as integer matrix
            switch (shapeType)
            {
                case BlockTypes.I:
                    newBlock = new Shapes.I();
                    break;
                case BlockTypes.O:
                    newBlock = new Shapes.O();
                    break;
                case BlockTypes.J:
                    newBlock = new Shapes.J();
                    break;
                case BlockTypes.L:
                    newBlock = new Shapes.L();
                    break;
                case BlockTypes.S:
                    newBlock = new Shapes.S();
                    break;
                case BlockTypes.T:
                    newBlock = new Shapes.T();
                    break;
                case BlockTypes.Z:
                    newBlock = new Shapes.Z();
                    break;
                default:
                    throw new NotImplementedException();
            }
            
            return newBlock;
        }
示例#2
0
        /// <summary>
        /// Creates a new random block.
        /// </summary>
        /// <returns></returns>
        public Block GetNewBlock()
        {
            Block newBlock;

            if (bag.Count == 0)
            {
                FillBag();
            }

            //Retrieve random block from bag
            int randomValue = rand.Next(0, bag.Count);
            BlockTypes shapeType = bag[randomValue];
            bag.RemoveAt(randomValue);

            //Retrieve the block as integer matrix
            switch (shapeType)
            {
                case BlockTypes.I:
                    newBlock = new Shapes.I();
                    break;
                case BlockTypes.O:
                    newBlock = new Shapes.O();
                    break;
                case BlockTypes.J:
                    newBlock = new Shapes.J();
                    break;
                case BlockTypes.L:
                    newBlock = new Shapes.L();
                    break;
                case BlockTypes.S:
                    newBlock = new Shapes.S();
                    break;
                case BlockTypes.T:
                    newBlock = new Shapes.T();
                    break;
                case BlockTypes.Z:
                    newBlock = new Shapes.Z();
                    break;
                default:
                    throw new NotImplementedException();
            }

            return newBlock;
        }