Beispiel #1
0
 public Block(Figure figure)
 {
     Figure = figure;
 }
Beispiel #2
0
        bool AddFigure(Figure fig)
        {
            var rnd = new Random ();

            bool isFigurePlaced;
            int x, y, tries = 0;
            do {
                tries++;
                x = rnd.Next (boardWidth);
                y = rnd.Next (bufforHeight + 1);

                isFigurePlaced = true;
                foreach (var b in fig.Blocks) {
                    var X = x + b.X;
                    var Y = y + b.Y;

                    if (X >= 0 && X < BoardWidth && Y >= 0 && Y <= bufforHeight) {
                        isFigurePlaced &= (board[X, Y] == null);

                    } else {
                        isFigurePlaced = false;
                        break;
                    }
                }
            } while (!isFigurePlaced && tries < 100);

            if (!isFigurePlaced) {
                return false;
            }

            if (isFigurePlaced) {
                foreach (var b in fig.Blocks) {
                    b.X += x;
                    b.Y += y;
                    board[b.X, b.Y] = b;
                }

                figures.Add (fig);
                return true;
            }

            return false;
        }
Beispiel #3
0
        public static Figure Generate()
        {
            var f = new Figure ();

            var shapeNum = rnd.Next (figureShape.GetLength (0));
            for (int i = 0; i < f.Blocks.Length; i++) {
                f.Blocks[i].X = figureShape[shapeNum, i, 0];
                f.Blocks[i].Y = figureShape[shapeNum, i, 1];
            }

            return f;
        }