public string[] GetFieldsToMove(string figure, int posX, int posY) { Figure fig; List <string> results = new List <string>(); try { fig = FigureFactory.GetFigure(figure, posX, posY); List <Field> fields = fig.GetFieldsToMove() .Where(p => (p.X < 8) && (p.Y < 8)) .Where(p => (p.X >= 0) && (p.Y >= 0)) .ToList(); foreach (Field item in fields) { string key = string.Format("{0},{1}", item.X, item.Y); results.Add(key); } } catch (Exception) { ; } return(results.ToArray()); }
public bool CheckMove(string dataStr) { string[] splitTab = dataStr.Split("|"); int posX = Convert.ToInt32(splitTab[0]); int posY = Convert.ToInt32(splitTab[1]); int nextX = Convert.ToInt32(splitTab[2]); int nextY = Convert.ToInt32(splitTab[3]); string figure = splitTab[4]; Figure fig; List <Field> fields = new List <Field>(); try { fig = FigureFactory.GetFigure(figure, posX, posY); fields = fig.GetFieldsToMove() .Where(p => (p.X < 8) && (p.Y < 8)) .Where(p => (p.X >= 0) && (p.Y >= 0)) .ToList(); } catch (Exception) { ; } return(fields.Where(p => p.X.Equals(nextX) && p.Y.Equals(nextY)).Count() > 0); }
private void Form1_MouseClick(object sender, MouseEventArgs e) { var figure = FigureFactory.GetFigure(); int.TryParse(guna2TextBox1.Text, out int widht); int.TryParse(guna2TextBox2.Text, out int height); if (widht > 0 && height > 0) { if (figure is Rectangle) { SetFigure(figure, new Size(widht, height)); if (guna2RadioButton4.Checked) { figure.Points[0] = e.Location; } } else if (figure is Circle) { SetFigure(figure, new Size(widht, height)); figure.Points[0] = e.Location; } else if (figure is Triangle) { SetFigure(figure, new Size(widht, height)); figure.Points[0] = e.Location; figure.Points[1].X = e.Location.X + figure.Size.Width / 2; figure.Points[1].Y = e.Location.Y + figure.Size.Height; figure.Points[2].X = e.Location.X - figure.Size.Width / 2; figure.Points[2].Y = e.Location.Y + figure.Size.Height; } figures.Add(figure); this.Refresh(); } }
private void Form1_MouseClick(object sender, MouseEventArgs e) { Pen pen = new Pen(FigureColor); Brush brush = new SolidBrush(FigureColor); if (FigureFactory.GetFigure() is TriAngle tr) { tr.Color = FigureColor; tr.Point = e.Location; tr.Size = new Size(int.Parse(textBoxWidth.Text), int.Parse(textBoxHeight.Text)); if (radioButtonFill.Checked) { tr.IsFilled = true; } else { tr.IsFilled = false; } figures.Add(tr); } else if (FigureFactory.GetFigure() is Rectangle rt) { rt.Color = FigureColor; rt.Point = e.Location; rt.Size = new Size(int.Parse(textBoxWidth.Text), int.Parse(textBoxHeight.Text)); if (radioButtonFill.Checked) { rt.IsFilled = true; } else { rt.IsFilled = false; } figures.Add(rt); } else if (FigureFactory.GetFigure() is Circle cr) { cr.Color = FigureColor; cr.Point = e.Location; cr.Size = new Size(int.Parse(textBoxWidth.Text), int.Parse(textBoxHeight.Text)); if (radioButtonFill.Checked) { cr.IsFilled = true; } else { cr.IsFilled = false; } figures.Add(cr); } this.Refresh(); }
private void Start() { Core.FirstPlayerData.Deck = new Deck() { Pawn = _pawnFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()), King = _kingFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()), Queen = _queenFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()), Bishop = _bishopFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()), Rook = _rookFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()), Horse = _horseFactory.GetFigure(Team.White, GetRandomSkill(), GetRandomTalent()) }; Core.SecondPlayerData.Deck = new Deck() { Pawn = _pawnFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()), King = _kingFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()), Queen = _queenFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()), Bishop = _bishopFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()), Rook = _rookFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()), Horse = _horseFactory.GetFigure(Team.Black, GetRandomSkill(), GetRandomTalent()) }; }
private void Form1_MouseClick(object sender, MouseEventArgs e) { if (FigureFactory.GetFigure() is Rectangle rect) { rect.Color = FigureColor; rect.Point = e.Location; rect.Size = new Size(int.Parse(widthTxtb.Text), int.Parse(heightTxtb.Text)); rect.isFilled = false; Figures.Add(rect); } this.Refresh(); }
private bool ValidateMove(Figure figure, int toRow, int toCol) { PositionModel toPosition = new PositionModel() { Row = toRow, Col = toCol }; PositionModel fromPosition = new PositionModel() { Row = figure.PositionRow, Col = figure.PositionCol }; if (toRow > 8 || toCol > 8) { return(false); } if (toRow < 0 || toCol < 0) { return(false); } var currentFigure = FigureFactory.GetFigure(figure); List <PositionModel> possibleMoves = currentFigure.GetPossibleMoves(); List <PositionModel> possibleHits = currentFigure.GetPossibleHits(); var checkedPosMoves = possibleMoves.Find(x => x.Col == toPosition.Col && x.Row == toPosition.Row); var checkedPosHits = possibleHits.Find(x => x.Col == toPosition.Col && x.Row == toPosition.Row); if (checkedPosMoves == null && checkedPosHits == null) { return(false); } if (!currentFigure.CanJump()) { FigureRepository figureRepository = data.GetFigureRepository(); HashSet <PositionModel> movePath = GetMovePath(fromPosition, toPosition); IQueryable <Figure> allGameFigures = figureRepository.GetGameFigures(figure.GameId); HashSet <PositionModel> gameFiguresPositions = new HashSet <PositionModel>(); foreach (Figure gameFig in allGameFigures) { gameFiguresPositions.Add(new PositionModel() { Row = gameFig.PositionRow, Col = gameFig.PositionCol }); } var positionIntersection = movePath.Intersect <PositionModel>(gameFiguresPositions); if (positionIntersection.Count() > 0) { return(false); } } return(true); }
private void button2_Click(object sender, EventArgs e) { IDrawAPI rectangle = FigureFactory.GetFigure("Rectangle"); rectangle.GetFigure(GetRandom(200), GetRandom(200), GetRandom(200), GetRandom(200), PictureBox); }
private void button1_Click(object sender, EventArgs e) { IDrawAPI circle = FigureFactory.GetFigure("Circle"); circle.GetFigure(GetRandom(200), GetRandom(200), GetRandom(200), PictureBox); }