Exemplo n.º 1
0
        /// <summary>
        /// Функция опускания фигуры на единицу и проверка упала или еще летит
        /// </summary>
        public void MakeIteration()
        {
            IsEndGame = GetIsEndGame();

            if (!IsEndGame)
            {
                if (Field.IsCanSetUpFigure(_figure, _x, _y + 1))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _y++;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    Field.SetUp(_figure, _y, _x, CellType.Border);
                    _timer.Interval = _speed;

                    PlayerScore += Field.Remove();

                    _figure = NextFigure;

                    _x = (Field.M - _figure.M) / 2;
                    _y = 1;

                    NextFigure = FigureFactory.Create();
                }

                FieldChanged?.Invoke();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Добавление фигуры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            FigureBase figure = null;

            try
            {
                if (comboBoxType.Text == _figureKey[FigureType.Ball])
                {
                    figure = new Ball(GetCorrect(Convert.ToDouble, maskedTextBox1.Text));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Pyramid])
                {
                    figure = new Pyramid(GetCorrect(Convert.ToDouble, maskedTextBox2.Text),
                                         GetCorrect(Convert.ToDouble, maskedTextBox3.Text));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Parallelepiped])
                {
                    figure = new Parallelepiped(GetCorrect(Convert.ToDouble, maskedTextBox2.Text),
                                                GetCorrect(Convert.ToDouble, maskedTextBox3.Text), GetCorrect(Convert.ToDouble, maskedTextBox1.Text));
                }

                Figure = figure ?? throw new ArgumentException("Тип не выбран!");

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Неверные данные!");
            }
        }
Exemplo n.º 3
0
        public void figreSet(int i, int j, bool firstMove, string[,] chessBoardString)
        {
            switch (chessBoardString[i, j])
            {
            //white
            case "WP":
                gameManager.addFigure(CreateFigure(figureBox.whitePown, j, i, 1, firstMove));
                break;

            case "WR":
                gameManager.addFigure(CreateFigure(figureBox.whiteRook, j, i, 1, firstMove));
                break;

            case "WH":
                gameManager.addFigure(CreateFigure(figureBox.whiteHorse, j, i, 1, firstMove));
                break;

            case "WB":
                gameManager.addFigure(CreateFigure(figureBox.whiteBishop, j, i, 1, firstMove));
                break;

            case "WK":
                FigureBase wk = CreateFigure(figureBox.whiteKing, j, i, 1, firstMove);
                gameManager.addFigure(wk);
                boardScript.whiteKing = (KingScript)wk;
                break;

            case "WQ":
                gameManager.addFigure(CreateFigure(figureBox.whiteQueen, j, i, 1, firstMove));
                break;

            //black
            case "BP":
                gameManager.addFigure(CreateFigure(figureBox.blackPown, j, i, -1, firstMove));
                break;

            case "BR":
                gameManager.addFigure(CreateFigure(figureBox.blackRook, j, i, -1, firstMove));
                break;

            case "BH":
                gameManager.addFigure(CreateFigure(figureBox.blackHorse, j, i, -1, firstMove));
                break;

            case "BB":
                gameManager.addFigure(CreateFigure(figureBox.blackBishop, j, i, -1, firstMove));
                break;

            case "BK":
                FigureBase bk = CreateFigure(figureBox.blackKing, j, i, -1, firstMove);
                gameManager.addFigure(bk);
                boardScript.blackKing = (KingScript)bk;
                break;

            case "BQ":
                gameManager.addFigure(CreateFigure(figureBox.blackQueen, j, i, -1, firstMove));
                break;
            }
        }
Exemplo n.º 4
0
        public Task <long> SaveFigureAsync(FigureBase figure, CancellationToken cancellationToken)
        {
            if (figure == null)
            {
                return(Task.FromException <long>(new ArgumentNullException(nameof(figure))));
            }

            return(_repository.SaveFigureAsync(figure, cancellationToken));
        }
Exemplo n.º 5
0
        public virtual double?TryCalculateArea(FigureBase figure)
        {
            if (figure is TFigure typedFigure)
            {
                return(TryCalculateArea(typedFigure));
            }

            return(null);
        }
Exemplo n.º 6
0
 public double CalculateArea(FigureBase figure)
 {
     figure = figure ?? throw new ArgumentNullException(nameof(figure));
     return(Calculators
            .OrderByDescending(it => (it as ITryAreaCalculatorWithPriority)?.GetPriority(figure) ?? 0)
            .Select(it => it.TryCalculateArea(figure))
            .FirstOrDefault(it => it != null)
            ?? throw new AreaCalculationException(figure, "Cannot calculate area for " + figure));
 }
Exemplo n.º 7
0
        /// <summary>
        /// 增加图元到绘图面板
        /// </summary>
        /// <param name="figure"></param>
        private void AddFigureToDiagram(FigureBase figure)
        {
            var shape = new FigureShape()
            {
                DataContext = figure
            };

            diagram.AddShape(shape);
        }
Exemplo n.º 8
0
        private FigureBase Turn(FigureBase figure)
        {
            var number = Random.Next(4);

            for (var i = 0; i < number; i++)
            {
                figure.Turn();
            }

            return(figure);
        }
Exemplo n.º 9
0
        public static DtoBase FindAppropriateDto(this FigureBase figure)
        {
            if (figure is Triangle triangle)
            {
                return(CreateTriangleDto(triangle));
            }
            if (figure is Circle circle)
            {
                return(CreateCircleDto(circle));
            }

            throw new KeyNotFoundException($"Dto для типа {figure.GetType()} не найдено");
        }
Exemplo n.º 10
0
 /// <summary>
 /// Установка на поле в соответствии с трафаретом фигуры значение v
 /// </summary>
 /// <param name="gameFieldsEnum"></param>
 public void SetUp(FigureBase figure, int y, int x, CellType cellType)
 {
     for (var i = 0; i < figure.N; i++)
     {
         for (var j = 0; j < figure.M; j++)
         {
             if (figure[i, j] == (int)CellType.Border)
             {
                 FieldArray[y + i, x + j] = cellType;
             }
         }
     }
 }
Exemplo n.º 11
0
        public Task <long> SaveFigureAsync(FigureBase figure, CancellationToken cancellationToken)
        {
            var figureDto = figure.FindAppropriateDto();

            using (var connection = new SqliteConnection(DB_NAME))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText = $"INSERT INTO Figures (Data, Type) VALUES ('{figureDto.Data}', {figureDto.Type}); SELECT last_insert_rowid() ";

                return(Task.FromResult((long)command.ExecuteScalar()));
            }
        }
Exemplo n.º 12
0
//      Обработка события выбора фигуры
        private void FigureSelectEventHandler(IFigure figure)
        {
            if (ActiveFiguresColor == figure.FigureColor)
            {
                _selectedFigure = figure;
                SelectedFigure  = (FigureBase)_selectedFigure;
                SelectedFigure.GetAvalableCellsForMove(_board);
            }
            else if (ActiveFiguresColor != figure.FigureColor &&
                     SelectedFigure != null)
            {
                SelectedFigure.AttackFigure(figure);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Добавление фигуры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonAddFigure_Click(object sender, EventArgs e)
        {
            AddFigureForm newForm           = new AddFigureForm();
            const int     masterSheetNumber = 3;

            if (newForm.ShowDialog() == DialogResult.OK)
            {
                FigureBase figure = newForm.Figure;
                _figureList.Add(figure);
                MessageBox.Show("Shape added!");
                listViewType.Items[masterSheetNumber].Selected = true;
                ListViewType_SelectedIndexChanged(this, null);
                listViewType.Select();
            }
        }
Exemplo n.º 14
0
        private FigureBase CreateFigure(GameObject figure, int y, int x, int color, bool firstMove)
        {
            GameObject created = Instantiate(figure, new Vector3(transform.position.x + x, transform.position.y + y, 0),
                                             Quaternion.identity);
            Transform transformObj = created.transform;

            transformObj.eulerAngles = new Vector3(0, 0, 180.0f);
            FigureBase figureBase = created.GetComponent <FigureBase>();

            figureBase.posX      = x;
            figureBase.posY      = y;
            figureBase.color     = color;
            figureBase.firstMove = firstMove;
            return(figureBase);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Проверка, можно ли поставить трафарет фигуры на игровое поле с координатой x, y
        /// </summary>
        /// <param name="x">Х координата текущей фигуры</param>
        /// <param name="y">У координата текущей фигуры</param>
        /// <returns>True - да, False - нет</returns>
        public bool IsCanSetUpFigure(FigureBase figure, int x, int y)
        {
            for (var i = 0; i < figure.N; i++)
            {
                for (var j = 0; j < figure.M; j++)
                {
                    if (FieldArray[y + i, x + j] == CellType.Border && figure[i, j] == (int)CellType.Border)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Перезапуск игры
        /// </summary>
        public void Restart()
        {
            Field.Clear();

            _figure    = FigureFactory.Create();
            NextFigure = FigureFactory.Create();

            _x = (Field.M - _figure.M) / 2;
            _y = 1;

            PlayerScore = 0;

            FieldChanged?.Invoke();

            _timer.Start();
        }
Exemplo n.º 17
0
        // call to this method from Swagger UI is not supported
        public async Task <FigureBase> FindSmallestFigure(IAsyncEnumerable <FigureBase> figures, CancellationToken token)
        {
            FigureBase result     = null;
            var        resultArea = .0;

            await foreach (var figure in figures.WithCancellation(token))
            {
                var area = CalculateArea(figure);
                if (result == null || area > resultArea)
                {
                    result = figure;
                }
            }

            return(result);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            var getHead         = new Head();
            var getHeadCovering = new HeadCovering();
            var getLeftArm      = new LeftArm();
            var getRightArm     = new RightArm();
            var getLegs         = new Legs();

            Console.WriteLine("You have been given a basic body piece. It is up to you to create the perfect specimen of Legohood.");
            var figureItems = new FigureBase[] { getHead, getHeadCovering, getLeftArm, getRightArm, getLegs };

            foreach (var piece in figureItems)
            {
                piece.GetPiece();
            }
            Console.WriteLine("Press Enter to Escape");
        }
Exemplo n.º 19
0
        /// <summary>
		/// Добавление фигуры
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ButtonAddFigure_Click(object sender, EventArgs e)
        {
            AddFigureForm newForm = new AddFigureForm();
            if (newForm.ShowDialog() == DialogResult.OK)
            {
                FigureBase figure = newForm.Figure;
                _figureList.Add(figure);
                MessageBox.Show("Фигура добавлена!");

                var itemNumber = 
                    _listViewFigure.FirstOrDefault(
                        x => x.Value == figure.GetType()).Key;
                listViewType.Items[itemNumber].Selected = true;

                ListViewType_SelectedIndexChanged(this, null);
                listViewType.Select();
                            
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Occures when mouse button is pushed.
        /// On the basis of implement mode we draw figure.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            FigureBase figure = null;

            switch (_currentlyCheckedShape.Content.ToString())
            {
            case "Circle":
                figure = new Circle();
                break;

            case "Rectangle":
                figure = new Rectangle();
                break;

            case "Triangle":
                figure = new Triangle();
                break;
            }

            // No figueres may be selected or chose right.
            // Cach that exception:
            try
            {
                switch (_currentlyCheckedImplementation.Content.ToString())
                {
                case "Windows implementetion":
                    figure.Implementor = new WindowsImplementation();
                    break;

                case "WPF implementetion":
                    figure.Implementor = new WpfImplementation(this, e);
                    break;
                }

                figure.Show();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("There are either no such figures or implementetions were found." +
                                " Make sure your check boxes are handled in UIElement_OnMouseDown()", "Exception",
                                MessageBoxButton.OK);
            }
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            FigureBase[] array = new FigureBase[5];
            array[0] = new Ring();
            array[1] = new Rectangle();
            array[2] = new Line();
            array[3] = new Round();
            array[4] = new Circle();

            foreach (var item in array)
            {
                item.Draw();

                //if (item is Line)
                //{
                //    var line = item as Line;
                //    line.LineGood();
                //}
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Добавление фигуры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            FigureBase figure = null;

            try
            {
                if (comboBoxType.Text == _figureKey[FigureType.Ball])
                {
                    figure = new Ball
                                 (CheckStringNullOrEmpty(maskedTextBox1.Text, "Radius"));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Pyramid])
                {
                    figure = new Pyramid
                                 (CheckStringNullOrEmpty(maskedTextBox2.Text, "Base area"),
                                 CheckStringNullOrEmpty(maskedTextBox3.Text, "Height"));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Parallelepiped])
                {
                    figure = new Parallelepiped
                                 (CheckStringNullOrEmpty(maskedTextBox1.Text, "Height"),
                                 CheckStringNullOrEmpty(maskedTextBox2.Text, "Width"),
                                 CheckStringNullOrEmpty(maskedTextBox3.Text, "Length"));
                }

                Figure = figure ?? throw new ArgumentException("Type not selected!");

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 23
0
        public override void Show(FigureBase figure)
        {
            Shape shape = null;

            switch (figure.ToString())
            {
            case "Circle":
                shape = CreateCircle();
                break;

            case "Rectangle":
                shape = CreateRectangle();
                break;

            case "Triangle":
                throw new Exception("No implementation of triangle drawing. Please make it.");
            }

            Canvas.SetLeft(shape, _mouseButtonEventArgs.GetPosition(_context.Canvas).X);
            Canvas.SetTop(shape, _mouseButtonEventArgs.GetPosition(_context.Canvas).Y);

            _context.Canvas.Children.Add(shape);
        }
Exemplo n.º 24
0
        public bool Validate(FigureBase figure)
        {
            switch (figure.FigureType)
            {
            case FigureType.Circle:
                if (!(figure is Circle))
                {
                    throw new FigureNegativeParameterException();
                }

                return(ValidateCicleParameters(figure as Circle));

            case FigureType.Triangle:
                if (!(figure is Triangle))
                {
                    throw new FigureNegativeParameterException();
                }

                return(ValidateTriangleParameters(figure as Triangle));

            default:
                throw new FigureNegativeParameterException();
            }
        }
Exemplo n.º 25
0
 public AreaCalculationException(FigureBase figure, string message)
     : base(message)
 {
     Figure = figure;
 }
Exemplo n.º 26
0
//      Обработка события завершения хода
        private void FigureMoveCompleteEventHandler()
        {
            ActiveFiguresColor = ActiveFiguresColor == FigureColor.BLACK ? FigureColor.WHITE : FigureColor.BLACK;
            SelectedFigure     = null;
        }
Exemplo n.º 27
0
 public double CalculateArea(FigureBase figure)
 {
     return(figure.GetArea());
 }
Exemplo n.º 28
0
 /// <summary>
 /// Вывод рассчитанной площади в консоль
 /// </summary>
 static void GetInfo(FigureBase figureBase)
 {
     //Console.WriteLine($"Площадь фигуры = {figureBase.GetInfo}\n");
 }
 private void DrawBase(FigureBase figure, int x, int y)
 {
     Console.WriteLine($"Draw \"{figure.Name}\" on point: ({x}, {y}) in HyperbolicGeometry");
 }
Exemplo n.º 30
0
 /// <summary>
 /// Вывести информацию в консоль
 /// </summary>
 /// <param name="figure">Экземпляр класса Фигура</param>
 public static void GetVolumeInfo(FigureBase figure)
 {
     Console.WriteLine($"Объем фигуры равен " +
                       $"{figure.Volume} м^3.");
 }