Example #1
0
        public Shape Rotate() {
            Cell[,] cells = new Cell[Cells.GetLength(1), Cells.GetLength(0)];

            for (int i = 0; i < Cells.GetLength(0); i++) {
                for (int j = 0; j < Cells.GetLength(1); j++) {
                    cells[j, i] = Cells[i, Cells.GetLength(1) - 1 - j];
                }
            }

            Shape shape = new Shape();
            shape.Cells = cells;

            return shape;
        }
Example #2
0
        public DrawEventArgs(Cup cup, Shape shape, Point shapePoint, int level, int score)
            : base(level, score) {
            if (cup == null) {
                throw new ArgumentNullException("cup");
            }

            if (shape == null) {
                throw new ArgumentNullException("shape");
            }

            if (shapePoint == null) {
                throw new ArgumentNullException("shapePoint");
            }

            Cup = cup;
            Shape = shape;
            ShapePoint = shapePoint;
        }
Example #3
0
        public int MergeShape(Shape shape, Point shapePoint) {
            for (int i = 0; i < shape.Width; i++) {
                for (int j = 0; j < shape.Height; j++) {
                    if (shape.Cells[i, j] == Cell.Occupied &&
                        IsInternalPoint(shapePoint.X + i, shapePoint.Y + j)) {
                        _Cells[shapePoint.X + i, shapePoint.Y + j] = Cell.Occupied;
                    }
                }
            }

            int droppedLinesCount = 0;

            for (int j = _Cells.GetLength(1) - 1; j >= 0; j--) {
                bool flag = true;

                for (int i = 0; i < _Cells.GetLength(0); i++) {
                    if (_Cells[i, j] == Cell.Free) {
                        flag = false;
                        break;
                    }
                }

                if (flag) {
                    droppedLinesCount++;
                    DropLine(j++);
                }
            }

            return droppedLinesCount;
        }
Example #4
0
        public bool CanShapeBePlaced(Point shapePoint, Shape shape) {
            if (shapePoint.X >= 0 && shapePoint.Y >= 0 &&
                shapePoint.X + shape.Width <= Width &&
                shapePoint.Y + shape.Height <= Height) {
                bool flag = true;

                for (int i = 0; i < shape.Width; i++) {
                    for (int j = 0; j < shape.Height; j++) {
                        if (shape.Cells[i, j] == Cell.Occupied &&
                            _Cells[shapePoint.X + i, shapePoint.Y + j] == Cell.Occupied) {
                            flag = false;
                            break;
                        }
                    }

                    if (!flag) {
                        break;
                    }
                }

                return flag;
            } else {
                return false;
            }
        }
Example #5
0
        private void DrawField(Image image, Cup cup, Shape shape, Point shapePoint) {
            using (Graphics g = Graphics.FromImage(image)) {
                g.Clear(Color.Black);

                for (int i = 0; i < cup.Width; i++) {
                    for (int j = 0; j < cup.Height; j++) {
                        if (cup[i, j] == Cell.Occupied) {
                            DrawCell(g, i, j, cup[i, j], Color.Green);
                        } else {
                            DrawCell(g, i, j, cup[i, j], Color.Gray);
                        }
                    }
                }

                if (shape != null) {
                    for (int i = 0; i < shape.Width; i++) {
                        for (int j = 0; j < shape.Height; j++) {
                            if (shape.Cells[i, j] == Cell.Occupied) {
                                Rectangle rect = new Rectangle((shapePoint.X + i) * RectSize, (shapePoint.Y + j) * RectSize, RectSize, RectSize);
                                g.FillRectangle(Brushes.Black, rect);
                                DrawCell(g, shapePoint.X + i, shapePoint.Y + j, Cell.Occupied, Color.Red);
                            }
                        }
                    }
                }
            }
        }