示例#1
0
        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);
        }
示例#2
0
 public void Turn(BoardPoint startPoint, BoardPoint endPoint)
 {
     Turn(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
 }
示例#3
0
        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("Неверный ход дамкой.");
            }
        }
示例#4
0
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        public void RemoveTest5()
        {
            Board target = new Board();
            BoardPoint point = new BoardPoint(2, 3);
            target.Remove(point);

            Assert.IsNull(target[point]);
        }
示例#7
0
        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);
        }
示例#8
0
        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]);
        }
示例#9
0
文件: Board.cs 项目: sys27/Draughts
        public void Move(Draught draught, BoardPoint point)
        {
            if (draught == null)
                throw new ArgumentNullException();

            Move(draught.X, draught.Y, point.X, point.Y);
        }
示例#10
0
文件: Board.cs 项目: sys27/Draughts
 public Draught this[BoardPoint point]
 {
     get { return this[point.Y, point.X]; }
     set { this[point.Y, point.X] = value; }
 }
示例#11
0
文件: Board.cs 项目: sys27/Draughts
 public void Remove(BoardPoint point)
 {
     Remove(point.X, point.Y);
 }
示例#12
0
文件: Draught.cs 项目: sys27/Draughts
 public Draught(BoardPoint point, DraughtType type, Players player)
 {
     this.point = point;
     this.type = type;
     this.player = player;
 }
示例#13
0
        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]);
        }
示例#14
0
 public bool Equals(BoardPoint other)
 {
     return other.x == x && other.y == y;
 }