private void MoveOn(PawnAdapter pawn) { if (null == selectedPawn) { return; } if (!BasicMoveValidator.IsValid(selectedPawn, pawn) && !JumpMoveValidator.IsValid(selectedPawn, pawn, bluePawns, redPawns)) { return; } bool beaten = BeatPawnService.TryToBeatPawn(selectedPawn, pawn, bluePawns, redPawns); int oldRow = selectedPawn.Row(); int oldColumn = selectedPawn.Column(); selectedPawn.Row(pawn.Row()); selectedPawn.Column(pawn.Column()); selectedPawn.CheckAndConvertToJumper(); ShowLogMessage(pawn, oldRow, oldColumn); UpdateResult(beaten); if (beaten && ExtraMoveValidator.IsValid(selectedPawn, bluePawns, redPawns)) { extraMove = true; return; } extraMove = false; selectedPawn.Color(Color.Black); selectedPawn = null; ++turn; }
public bool IsValid(PawnAdapter selectedPawn, List <PawnAdapter> bluePawns, List <PawnAdapter> redPawns) { List <PawnAdapter> oponentPlayer = selectedPawn.Player() == PlayerEnum.Red ? bluePawns : redPawns; List <Point> positions = new List <Point>(); int nextPosition = selectedPawn.Player() == PlayerEnum.Red ? RuleConfig.moveBackTwoRows : RuleConfig.moveTwoRows; positions.Add(new Point(selectedPawn.Column() + RuleConfig.moveTwoColumns, selectedPawn.Row() + nextPosition)); positions.Add(new Point(selectedPawn.Column() - RuleConfig.moveTwoColumns, selectedPawn.Row() + nextPosition)); if (selectedPawn.Type() == PawnTypeEnum.Jumper) { positions.Add(new Point(selectedPawn.Column() + RuleConfig.moveTwoColumns, selectedPawn.Row() - nextPosition)); positions.Add(new Point(selectedPawn.Column() - RuleConfig.moveTwoColumns, selectedPawn.Row() - nextPosition)); } foreach (Point position in positions) { if (IsInField(position) && !ShouldOccupy(position, redPawns, bluePawns)) { Point middlePoint = new Point(AverageCalculator.CalculateAverage(position.X, selectedPawn.Column()), AverageCalculator.CalculateAverage(position.Y, selectedPawn.Row())); if (Occupy(middlePoint, oponentPlayer)) { return(true); } } } return(false); }
private void ChoosePawn(PictureBox file) { PawnAdapter tempPawn = PawnAdapterFactory.Create(PlayerEnumMethods.GetPlayer(file.Name.ToString()), file); if (PlayerEnumMethods.GetPlayer(file.Name.ToString()) == PlayerEnum.Red) { foreach (PawnAdapter pawn in redPawns) { if (tempPawn.Equals(pawn)) { this.selectedPawn = pawn; } } } if (PlayerEnumMethods.GetPlayer(file.Name.ToString()) == PlayerEnum.Blue) { foreach (PawnAdapter pawn in bluePawns) { if (tempPawn.Equals(pawn)) { this.selectedPawn = pawn; } } } }
public int CalculateMovedRows(PawnAdapter origin, PawnAdapter destination) { int movedRows = origin.Row() - destination.Row(); movedRows = origin.Player() == PlayerEnum.Red ? movedRows : (movedRows * -1); return(origin.Type() == PawnTypeEnum.Jumper ? Math.Abs(movedRows) : movedRows); }
public bool IsValid(PawnAdapter origin, PawnAdapter destination) { int movedRows = MoveCalculator.CalculateMovedRows(origin, destination); movedRows = origin.Type() == PawnTypeEnum.Jumper ? Math.Abs(movedRows) : movedRows; int movedColumns = MoveCalculator.CalculateMovedColumns(origin, destination); return(movedRows == RuleConfig.moveOneRow && Math.Abs(movedColumns) == RuleConfig.moveOneColumn); }
private void ShowLogMessage(PawnAdapter pawn, int oldRow, int oldColumn) { statusText.Text = string.Format("Player: {0} moved from: {1}{2} to: {3}{4} \n{5}", selectedPawn.Player().ToString(), RowToUserReadableTransformator.Transform(oldColumn), oldRow.ToString(), RowToUserReadableTransformator.Transform(pawn.Column()), pawn.Row().ToString(), statusText.Text ); }
public bool TryToBeatPawn(PawnAdapter origin, PawnAdapter destination, List <PawnAdapter> bluePawns, List <PawnAdapter> redPawns) { int movedRows = MoveCalculator.CalculateMovedRows(origin, destination); int movedColumns = MoveCalculator.CalculateMovedColumns(origin, destination); if (RuleConfig.moveTwoRows == movedRows && RuleConfig.moveTwoColumns == Math.Abs(movedColumns)) { AverageCalculator averageCalculator = new AverageCalculator(); int skippedColumn = averageCalculator.CalculateAverage(destination.Column(), origin.Column()); int skippedRow = averageCalculator.CalculateAverage(destination.Row(), origin.Row()); List <PawnAdapter> oppositeSide = origin.Player() == PlayerEnum.Red ? bluePawns : redPawns; foreach (PawnAdapter oppositePawnAdapter in oppositeSide) { if (oppositePawnAdapter.Row() == skippedRow && oppositePawnAdapter.Column() == skippedColumn) { oppositePawnAdapter.Hide(); return(true); } } } return(false); }
public bool IsValid(PawnAdapter origin, PawnAdapter destination, List <PawnAdapter> bluePawns, List <PawnAdapter> redPawns) { int movedRows = MoveCalculator.CalculateMovedRows(origin, destination); int movedColumns = MoveCalculator.CalculateMovedColumns(origin, destination); if (RuleConfig.moveTwoRows != movedRows || RuleConfig.moveTwoColumns != Math.Abs(movedColumns)) { return(false); } int skippedColumn = AverageCalculator.CalculateAverage(destination.Column(), origin.Column()); int skippedRow = AverageCalculator.CalculateAverage(destination.Row(), origin.Row()); List <PawnAdapter> oppositeSide = origin.Player() == PlayerEnum.Red ? bluePawns : redPawns; foreach (PawnAdapter oppositePawnAdapter in oppositeSide) { if (oppositePawnAdapter.Row() == skippedRow && oppositePawnAdapter.Column() == skippedColumn) { return(true); } } return(false); }
public int CalculateMovedColumns(PawnAdapter origin, PawnAdapter destination) { return(origin.Column() - destination.Column()); }