protected Figure2D(float x, float y, ColorFig color, bool hide) { X = x; Y = y; Color = color; Hide = hide; }
public Cell[,] BuildScreen(int width, int height) { Cell[,] result = new Cell[width, height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { result[j, i] = new Cell(); } } foreach (Figure2D figure in _figures) { if (figure != null) { Point[] points = figure.BuildFigure(); ColorFig col = figure.Color; bool hide = figure.Hide; foreach (Point point in points) { result[point.X, point.Y].Exist = true; result[point.X, point.Y].Color = col; result[point.X, point.Y].Hide = hide; } } } return(result); }
private static ConsoleColor GetColor(ColorFig sourse) { ConsoleColor col = ConsoleColor.Black; switch (sourse) { case ColorFig.Red: col = ConsoleColor.Red; break; case ColorFig.Green: col = ConsoleColor.Green; break; case ColorFig.Yellow: col = ConsoleColor.Yellow; break; case ColorFig.DarkRed: col = ConsoleColor.DarkRed; break; case ColorFig.Blue: col = ConsoleColor.Blue; break; case ColorFig.White: col = ConsoleColor.White; break; case ColorFig.DarkYellow: col = ConsoleColor.DarkYellow; break; } return(col); }
public Triangle(float x, float y, ColorFig color, Point2D a2, Point2D a3, bool hide) : base(x, y, color, hide) { A2 = new Point2D(a2); A3 = new Point2D(a3); }
public Ellipse(float x, float y, ColorFig color, float r1, float r2, bool hide) : base(x, y, color, r1, hide) { R2 = r2; }
public Circle(float x, float y, ColorFig color, float r, bool hide) : base(x, y, color, hide) { R1 = r; }
public Square(float x, float y, ColorFig color, float l1, bool hide) : base(x, y, color, hide) { L1 = l1; }
static void Main(string[] args) { FigureContainer container = new FigureContainer(); const int xStart = 20; const int yStart = 20; int indexCurrentFigure = 0; UI.StartShow(); UI.Kevt.KeyPress += (sender, e) => { UI.ShowIndex(indexCurrentFigure); Figure2D tempFig; switch (e.Key.Key) { case ConsoleKey.D1: ColorFig col = GetColor(); tempFig = new Triangle(xStart, yStart, col, new Point2D(25, 25, col, false), new Point2D(15, 25, col, false), false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D2: tempFig = new Square(xStart, yStart, GetColor(), 6, false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D3: tempFig = new Rectangle(xStart, yStart, GetColor(), 12, 4, false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D4: tempFig = new Circle(xStart, yStart, GetColor(), 3, false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D5: tempFig = new Ellipse(xStart, yStart, GetColor(), 8, 2, false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D6: container.Delete(indexCurrentFigure); indexCurrentFigure = ChooseAnotherFigure(container, indexCurrentFigure); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D7: if (container[indexCurrentFigure]) { container.Hide(indexCurrentFigure, false); } else { container.Hide(indexCurrentFigure, true); } UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D8: container.Rotate(indexCurrentFigure); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.D9: tempFig = new CircleInSquare(xStart, yStart, GetColor(), 6, false); indexCurrentFigure = container.Add(tempFig); UI.Show(container.BuildScreen(UI.WindowWidth, UI.WindowHeight - 2)); break; case ConsoleKey.LeftArrow: Move(container, indexCurrentFigure, -1, 0); break; case ConsoleKey.RightArrow: Move(container, indexCurrentFigure, 1, 0); break; case ConsoleKey.DownArrow: Move(container, indexCurrentFigure, 0, 1); break; case ConsoleKey.UpArrow: Move(container, indexCurrentFigure, 0, -1); break; case ConsoleKey.Add: IncreaseFigure(container, indexCurrentFigure); break; case ConsoleKey.Subtract: ReduceFigure(container, indexCurrentFigure); break; case ConsoleKey.PageUp: for (int i = indexCurrentFigure; i < container.Length - 1; i++) { if (container.GetExistFigure(indexCurrentFigure + 1) != false) { indexCurrentFigure++; break; } } break; case ConsoleKey.PageDown: for (int i = indexCurrentFigure; i > 0; i--) { if (container.GetExistFigure(indexCurrentFigure - 1) != false) { indexCurrentFigure--; break; } } break; } }; UI.GetPush(); }
// конструктор с 3-мя параметрами (наиболее полная версия конструктора) public Point2D(float x, float y, ColorFig color, bool hide) : base(x, y, color, hide) // вызов конструктора базового класса с 3-мя параметрами { }
public CircleInSquare(float x, float y, ColorFig color, float l1, bool hide) : base(x, y, color, l1, hide) { _circle = new Circle(x, y, color, l1 / 2, hide); _square = new Square(x, y, color, l1, hide); }
public Rectangle(float x, float y, ColorFig color, float l1, float l2, bool hide) : base(x, y, color, l1, hide) { L2 = l2; }