/// <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(); } }
/// <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("Неверные данные!"); } }
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; } }
public Task <long> SaveFigureAsync(FigureBase figure, CancellationToken cancellationToken) { if (figure == null) { return(Task.FromException <long>(new ArgumentNullException(nameof(figure)))); } return(_repository.SaveFigureAsync(figure, cancellationToken)); }
public virtual double?TryCalculateArea(FigureBase figure) { if (figure is TFigure typedFigure) { return(TryCalculateArea(typedFigure)); } return(null); }
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)); }
/// <summary> /// 增加图元到绘图面板 /// </summary> /// <param name="figure"></param> private void AddFigureToDiagram(FigureBase figure) { var shape = new FigureShape() { DataContext = figure }; diagram.AddShape(shape); }
private FigureBase Turn(FigureBase figure) { var number = Random.Next(4); for (var i = 0; i < number; i++) { figure.Turn(); } return(figure); }
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()} не найдено"); }
/// <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; } } } }
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())); } }
// Обработка события выбора фигуры 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); } }
/// <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(); } }
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); }
/// <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); }
/// <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(); }
// 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); }
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"); }
/// <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(); } }
/// <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); } }
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(); //} } }
/// <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); } }
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); }
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(); } }
public AreaCalculationException(FigureBase figure, string message) : base(message) { Figure = figure; }
// Обработка события завершения хода private void FigureMoveCompleteEventHandler() { ActiveFiguresColor = ActiveFiguresColor == FigureColor.BLACK ? FigureColor.WHITE : FigureColor.BLACK; SelectedFigure = null; }
public double CalculateArea(FigureBase figure) { return(figure.GetArea()); }
/// <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"); }
/// <summary> /// Вывести информацию в консоль /// </summary> /// <param name="figure">Экземпляр класса Фигура</param> public static void GetVolumeInfo(FigureBase figure) { Console.WriteLine($"Объем фигуры равен " + $"{figure.Volume} м^3."); }