Example #1
0
        public void TestCircleSquare()
        {
            var circle = new Circle(2);
            var square = SquareFactory.GetSquare(circle);

            Assert.AreEqual(4 * Math.PI, square);
        }
Example #2
0
        private void toolStripButtonSquare_Click(object sender, EventArgs e)
        {
            CurrentFactory = new SquareShapeFactory();
            Factory current = new SquareFactory(pnlMain);

            CurrentDrawman = current.FactoryMethod();
        }
        static void Main(string[] args)
        {
            ShapeFactory rectangleFactory = new RectangleFactory();
            ShapeFactory squareFactory    = new SquareFactory();
            ShapeFactory tritangleFactory = new TritangleFactory();
            int          allarea          = 0;

            for (int i = 0; i < 10; i++)
            {
                Random random = new Random(); //在外面生成对象
                int    r      = random.Next(1, 4);
                switch (r)
                {
                case 1:

                    allarea += rectangleFactory.createShape().getarea();
                    Console.WriteLine("产生了一个长方形,面积为:{0}", rectangleFactory.createShape().getarea());
                    break;

                case 2:
                    allarea += squareFactory.createShape().getarea();
                    Console.WriteLine("产生了一个正方形,面积为:{0}", squareFactory.createShape().getarea());
                    break;

                case 3:
                    allarea += tritangleFactory.createShape().getarea();
                    Console.WriteLine("产生了一个三角形,面积为:{0}", tritangleFactory.createShape().getarea());
                    break;
                }
            }
            Console.WriteLine("十个形状总面积为:{0}", allarea);
        }
Example #4
0
        public void TestTriangleSquare()
        {
            var triangle = new Triangle(3, 4, 5);
            var square   = SquareFactory.GetSquare(triangle);

            Assert.AreEqual(6, square);
        }
        public void HandleEvent()
        {
            squareFactory           = new SquareFactory();
            Canvas.CurFigureFactory = squareFactory;
            MouseEventArgs eMouse = (MouseEventArgs)E;

            Canvas.PrevPoint = new PointF(eMouse.X, eMouse.Y);
        }
Example #6
0
        public void TestComputeArea()
        {
            ShapeFactory sf = new SquareFactory();

            Square square = (Square)sf.Create2dShape();

            square.SetSquare(2, 2, 2);
            Assert.AreEqual(4, square.ComputeArea(), 0);
        }
Example #7
0
        public void TestValidConstruction()
        {
            ShapeFactory sf = new SquareFactory();

            Square square = (Square)sf.Create2dShape();

            square.SetSquare(1, 2, 3);
            Assert.AreEqual(1, square.Point1.X);
            Assert.AreEqual(2, square.Point1.Y);
        }
Example #8
0
    private void Awake()
    {
        if (Instance)
        {
            DestroyImmediate(this);
            return;
        }

        instance = this;
    }
Example #9
0
        public void TestMove()
        {
            ShapeFactory sf = new SquareFactory();

            Square square = (Square)sf.Create2dShape();

            square.SetSquare(1, 2, 3);
            square.Move(2, 3);
            Assert.AreEqual(3, square.Point1.X);
            Assert.AreEqual(5, square.Point1.Y);
        }
Example #10
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (cmboShapeType.SelectedItem is null)
            {
                errorMessage("Please select a type of shape");
            }
            else if (ValidateInfo())
            {
                ShapeFactory factory = null;
                switch (cmboShapeType.SelectedItem.ToString())
                {
                case "Circle":
                    Shapes.Point CirclePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new CircleFactory(CirclePoint, Int32.Parse(txtRadius1.Text));
                    break;

                case "Ellipse":
                    Shapes.Point EllipsePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new EllipseFactory(EllipsePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text));
                    break;

                case "Rectangle":
                    Shapes.Point RectanglePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new RectangleFactory(RectanglePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text));
                    break;

                case "Square":
                    Shapes.Point SquarePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new SquareFactory(SquarePoint, Int32.Parse(txtRadius1.Text));
                    break;

                case "Triangle":
                    Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text));
                    Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text));
                    factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3);
                    break;

                case "Composite Image":
                    factory = new CompositeImageFactory(filepath);
                    break;

                case "Embedded Pic":
                    Shapes.Point EmbeddedPoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new EmbeddedPicFactory(EmbeddedPoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text), filepath);
                    break;
                }
                Shape shape = factory.GetShape();
                Console.WriteLine(shape.ShapeType);
                shapeToDraw = shape;
                this.Close();
            }
        }
Example #11
0
    /**
     * Erstellt ein doppeltverkettetes Array bestehend aus den gegebenen Feldern,
     * welches das Spielfeld simuliert.
     * @preconditions Die Variable filePath darf nicht null sein.
     * @param boardObject Auf welchem gearbeitet wird.
     * @return Doppeltverkettetes Array mit den Feldern des Spielses
     */
    private Square[][] boardMaker(Board boardObject)
    {
        Assert.IsTrue(filePath != null);
        string[][]    file  = readFile();
        Square[][]    board = new Square[file.Length][];
        SquareFactory sf    = new SquareFactory();

        for (int i = 0; i < file.Length; i++)
        {
            board [i] = new Square[file [i].Length];
            for (int j = 0; j < file [i].Length; j++)
            {
                board [i] [j] = sf.makeSquare(file[i][j], i, j, boardObject, position);
            }
        }
        Assert.AreEqual(file.Length, board.Length);
        Assert.AreEqual(file [0].Length, board [0].Length);
        return(board);
    }
Example #12
0
    public void StartGame()
    {
        SwitchToGame();

        ScoreText.text = string.Empty;
        LivesText.text = string.Empty;

        switch (selectedGameModeIndex)
        {
        case 0:
            activeGameMode = new TimeAttack();
            break;

        case 1:
            activeGameMode = new Survival();
            break;

        case 2:
            activeGameMode = new Anchor();
            break;

        case 3:
            activeGameMode = new ColorCode();
            break;

        default:
            break;
        }

        activeGameMode.OnScoreChanged += HandleScoreChanged;
        activeGameMode.OnTimerChanged += HandleTimerChanged;
        activeGameMode.OnLivesChanged += HandleLivesChanged;
        activeGameMode.OnGameEnded    += HandleGameEnded;

        activeGameMode.SelectedDifficulty         = Difficulties[selectedDifficultyIndex];
        activeGameMode.ActiveFactory              = SquareFactory.CreateFactory();
        activeGameMode.ActiveFactory.SquarePrefab = SquarePrefab;

        activeGameMode.InitializeGame();

        StartCoroutine(activeGameMode.InitializeGrid());
    }
Example #13
0
        static Shape CreateShape(string shapeName)
        {
            IShapeFactory shapeFactory = null;

            switch (shapeName)
            {
            case "circle":
                shapeFactory = new CircileFactory();
                break;

            case "square":
                shapeFactory = new SquareFactory();
                break;

            default:
                break;
            }

            return(shapeFactory.CreateShape());
        }
Example #14
0
        static void Main(string[] args)
        {
            var squareSide   = new SquareFactory().Create().Parameter;
            var circleRadius = new CircleFactory().Create().Parameter;

            string result;

            if (squareSide >= 2 * circleRadius)
            {
                result = "Circle inscribed in square";
            }
            else if (Math.Round(Math.Sqrt(2) / 2 * squareSide, 2) <= circleRadius)
            {
                result = "The circle described around the square";
            }
            else
            {
                result = "Figures intersect";
            }
            Console.WriteLine(result);
            Console.ReadKey();
        }
        static void Main()
        {
            Figure         factory = new Figure();
            Random         rand    = new Random();
            List <IFigure> figures = new List <IFigure>();
            bool           finish  = false;

            for (int i = 0; i < 5; i++)
            {
                figures.Add(factory.Create((Dict)rand.Next(0, 3)));
            }
            do
            {
                Console.WriteLine("1. Wyświetl figury.");
                Console.WriteLine("2. Dodaj figurę.");
                Console.WriteLine("K. Wyjdź.");
                string choice;
                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    Console.Clear();
                    do
                    {
                        Console.WriteLine("Aby zwiększyc, zmniejszyć lub usunąć figurę wybierz ją po numerze.");
                        for (int i = 0; i < figures.Count; i++)
                        {
                            Console.WriteLine("{0}. {1}", i + 1, figures[i].ToString());
                        }
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        if (choice == "K" || choice == "k")
                        {
                            finish = true;
                            Console.Clear();
                        }
                        else
                        {
                            try
                            {
                                int index = Convert.ToInt32(choice) - 1;
                                Console.Clear();
                                do
                                {
                                    Console.WriteLine(figures[index].ToString());
                                    Console.WriteLine("1. Powiększ.");
                                    Console.WriteLine("2. Zmniejsz.");
                                    Console.WriteLine("3. Usuń.");
                                    Console.WriteLine("K. Wróć.");
                                    choice = Console.ReadLine();
                                    Console.Clear();
                                    switch (choice)
                                    {
                                    case "1":
                                        figures[index].Increase();
                                        break;

                                    case "2":
                                        figures[index].Decrease();
                                        break;

                                    case "3":
                                        figures.RemoveAt(index);
                                        finish = true;
                                        break;

                                    case "k":
                                    case "K":
                                        finish = true;
                                        break;

                                    default:
                                        Console.WriteLine("Zła wartość. Wpisz ponownie.");
                                        break;
                                    }
                                }while (!finish);
                                finish = false;
                            }
                            catch
                            {
                                Console.Clear();
                                Console.WriteLine("Zła wartość. Podaj ponownie.");
                            }
                        }
                    }while (!finish);
                    finish = false;
                    break;

                case "2":
                    do
                    {
                        Console.WriteLine("Wybierz jaką figurę tworzysz:");
                        Console.WriteLine("1. Kwadrat.");
                        Console.WriteLine("2. Prostokąt.");
                        Console.WriteLine("3. Koło.");
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        Console.Clear();
                        double a, b;
                        switch (choice)
                        {
                        case "1":
                            SquareFactory squareFactory = new SquareFactory();
                            Console.WriteLine("Podaj długość boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(squareFactory.Create(a));
                            break;

                        case "2":
                            RectangleFactory rectangleFactory = new RectangleFactory();
                            Console.WriteLine("Podaj długość pierwszego boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            Console.WriteLine("Podaj długość drugiego boku. ");
                            b = Convert.ToDouble(Console.ReadLine());
                            figures.Add(rectangleFactory.Create(a, b));
                            break;

                        case "3":
                            CircleFactory circleFactory = new CircleFactory();
                            Console.WriteLine("Podaj długość promienia. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(circleFactory.Create(a));
                            break;

                        case "k":
                        case "K":
                            finish = true;
                            break;

                        default:
                            Console.Clear();
                            Console.WriteLine("Zły wybór. Wybierz ponownie.");
                            break;
                        }
                    }while (!finish);
                    finish = false;
                    Console.Clear();
                    break;

                case "k":
                case "K":
                    finish = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Zły wybór. Wybierz ponownie.");
                    break;
                }
            }while (!finish);
        }
 public SquareFactoryTests()
 {
     _factory = new SquareFactory();
 }
Example #17
0
        public Shape getShape(int initialX, int initialY, int secondaryX, int secondaryY, bool add)
        {
            if (designation == shapeDesignation.EMBEDDED_PIC)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                DialogResult   result          = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string file = openFileDialog1.FileName;
                    Console.WriteLine(openFileDialog1.FileName);
                    embeddedPicFilepath = openFileDialog1.FileName;
                }
            }
            ShapeFactory factory = null;

            switch (designation)
            {
            case shapeDesignation.CIRCLE:
                Shapes.Point CirclePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new CircleFactory(CirclePoint, Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.ELLIPSE:
                Shapes.Point EllipsePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new EllipseFactory(EllipsePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.RECTANGLE:
                Shapes.Point RectanglePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new RectangleFactory(RectanglePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.SQUARE:
                Shapes.Point SquarePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new SquareFactory(SquarePoint, Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.TRIANGLE:
                //TODO: Figure out rectangular triangle drawing
                //Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                //Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text));
                //Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text));
                //factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3);
                break;

            case shapeDesignation.EMBEDDED_PIC:
                Shapes.Point EmbeddedPoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new EmbeddedPicFactory(EmbeddedPoint, Math.Abs(secondaryX - initialX), Math.Abs(secondaryY - initialY), embeddedPicFilepath);
                break;

            case shapeDesignation.LINE:
                //TODO: Create Line in shapes
                break;

            default:
                return(null);
            }
            Shape shape = factory.GetShape();

            if (add)
            {
                addToList(shape);
            }
            return(shape);
        }
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new SquareFactory();

            IShape square = shapeFactory.CreateShape();
        }
Example #19
0
 public void NewFigure()
 {
     FigureFactory fact;
     Random r = new Random();
     Y = 0;
     X = 5;
     Id = r.Next(0, 7);
     //Id = 6; //тест
     if (Id == 0)
     {
         fact = new LineFactory();
     }
     else if (Id == 1)
     {
         fact = new SquareFactory();
     }
     else if (Id == 2)
     {
         fact = new PyramideFactory();
     }
     else if (Id == 3)
     {
         fact = new LeftZFactory();
     }
     else if (Id == 4)
     {
         fact = new RightZFactory();
     }
     else if (Id == 5)
     {
         fact = new LeftLFactory();
     }
     else if (Id == 6)
     {
         fact = new RightLFactory();
     }
     else
     {
         Id = 0;
         fact = new LineFactory();
     }
     f = fact.CreateFigure();
     f.Create();
     Copy();
 }