public void DraughtConstructorTest2() { BoardPoint point = new BoardPoint(2, 4); DraughtType type = DraughtType.Queen; Players player = Players.PlayerTwo; Draught target = new Draught(point, type, player); Assert.AreEqual(point, target.Point); Assert.AreEqual(type, target.Type); Assert.AreEqual(player, target.Player); }
public void Turn(BoardPoint startPoint, BoardPoint endPoint) { Turn(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); }
private void TurnQueenDraught(Draught draught, int endX, int endY) { if (Math.Abs(endX - draught.X) == Math.Abs(endY - draught.Y)) { int count = Math.Abs(endX - draught.X) - 1; BoardPoint point = new BoardPoint(); if (draught.X < endX && draught.Y > endY) // вверх-вправо { point = CheckRange(draught, draught.X + 1, draught.X + count, endY + 1, endY + count); } else if (draught.X > endX && draught.Y > endY) // вверх-влево { point = CheckRange(draught, endX + 1, endX + count, endY + 1, endY + count); } else if (draught.X > endX && draught.Y < endY) // вниз-влево { point = CheckRange(draught, endX + 1, endX + count, draught.Y + 1, draught.Y + count); } else if (draught.X < endX && draught.Y < endY) // вниз-вправо { point = CheckRange(draught, draught.X + 1, draught.X + count, draught.Y + 1, draught.Y + count); } if (point.X != -1 && point.Y != -1) { TurnKill(draught, endX, endY, point.X, point.Y); } else { TurnMove(draught, endX, endY); } } else { throw new DraughtsGameException("Неверный ход дамкой."); } }
private BoardPoint CheckRange(Draught queen, int fromX, int toX, int fromY, int toY) { int draughtsCount = 0; BoardPoint point = new BoardPoint(-1, -1); for (int y = fromY; y <= toY; y++) { for (int x = fromX; x <= toX; x++) { if (board[y, x] != null) { if (board[y, x].Player == queen.Player) throw new DraughtsGameException("Вы не можете побить свою шашку."); draughtsCount++; if (draughtsCount > 1) { throw new DraughtsGameException("Бить больше, чем одну шашку нельзя."); } point = new BoardPoint(y, x); } } } return point; }
public void ItemTest3() { Board target = new Board(); BoardPoint point = new BoardPoint(5, 4); Draught expected = target[point]; Assert.AreEqual<Draught>(expected, target[point]); target[point] = expected; Assert.AreEqual<Draught>(target[point], expected); }
public void RemoveTest5() { Board target = new Board(); BoardPoint point = new BoardPoint(2, 3); target.Remove(point); Assert.IsNull(target[point]); }
public void MoveTest8() { Board board = new Board(); Draught dr = board[2, 1]; BoardPoint point = new BoardPoint(3, 2); board.Move(dr, point); Assert.AreEqual(board[point], dr); }
public void MoveTest7() { Board target = new Board(); BoardPoint oldPoint = new BoardPoint(2, 3); Draught draught = target[oldPoint]; BoardPoint newPoint = new BoardPoint(3, 4); target.Move(draught, newPoint); Assert.AreEqual<Draught>(draught, target[newPoint]); }
public void Move(Draught draught, BoardPoint point) { if (draught == null) throw new ArgumentNullException(); Move(draught.X, draught.Y, point.X, point.Y); }
public Draught this[BoardPoint point] { get { return this[point.Y, point.X]; } set { this[point.Y, point.X] = value; } }
public void Remove(BoardPoint point) { Remove(point.X, point.Y); }
public Draught(BoardPoint point, DraughtType type, Players player) { this.point = point; this.type = type; this.player = player; }
public void TurnTest1() { DraughtsGame target = new DraughtsGame(); BoardPoint startPoint = new BoardPoint(5, 2); Draught draught = target.GameBoard[startPoint]; BoardPoint endPoint = new BoardPoint(4, 3); target.Turn(startPoint, endPoint); Assert.AreEqual(draught, target.GameBoard[endPoint]); }
public bool Equals(BoardPoint other) { return other.x == x && other.y == y; }