Exemple #1
0
        // TODO: Change signature?
        // TODO: TEST
        public Boolean ApplyValidMove(Position start, Position end)
        {
            // Hold both pieces
            // try:
            //     ask conflict handler for result
            // try:
            //     put the result at end position
            //    put an empty at start position

            Piece attacker;
            ICell defender;

            try
            {
                attacker = (Piece)CellAtPos(start);
                defender = CellAtPos(end);
            }
            catch
            {
                return(false);
            }

            if (attacker == null || defender == null)
            {
                return(false);
            }

            ICell winner = ConflictHandler.Handle(attacker, defender);

            State[end.to_board_index(DefaultBoardSize)]   = winner;
            State[start.to_board_index(DefaultBoardSize)] = new EmptyCell();
            return(true);
        }
Exemple #2
0
        public void TestMinerFlag()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            ICell def = new Flag(Ownership.SecondPlayer);

            Assert.True(att == ConflictHandler.Handle(att, def));
        }
Exemple #3
0
        public void TestSpyMarshal()
        {
            Piece att = new Spy(Ownership.FirstPlayer);
            ICell def = new Marshal(Ownership.SecondPlayer);

            Assert.True(att == ConflictHandler.Handle(att, def));
        }
Exemple #4
0
        public void TestColonelColonel()
        {
            Piece att = new Colonel(Ownership.FirstPlayer);
            Piece def = new Colonel(Ownership.SecondPlayer);

            Assert.True(ConflictHandler.Handle(att, def) is EmptyCell);
        }
Exemple #5
0
        public void TestMinerEmpty()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            ICell def = new EmptyCell();

            Assert.True(att == ConflictHandler.Handle(att, def));
        }
Exemple #6
0
        public void TestMajorGeneral()
        {
            Piece att = new Major(Ownership.SecondPlayer);
            ICell def = new General(Ownership.FirstPlayer);

            Assert.True(def == ConflictHandler.Handle(att, def));
        }
Exemple #7
0
        public void TestMinerLieutenant()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            Piece def = new Lieutenant(Ownership.SecondPlayer);

            Assert.True(def == ConflictHandler.Handle(att, def));
        }
Exemple #8
0
        public void TestMinerBomb()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            Piece def = new Bomb(Ownership.SecondPlayer);
            ICell ans = ConflictHandler.Handle(att, def);

            Assert.True(att == ans);
        }
Exemple #9
0
        public void TestFailOnSameSideAttackColonalFlag__ThrowsPieceConflictHandlerException()
        {
            Piece att = new Colonel(Ownership.SecondPlayer);
            ICell def = new Flag(Ownership.SecondPlayer);

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }
Exemple #10
0
        public void TestFailOnSameSideAttackSpySergeant__ThrowsPieceConflictHandlerException()
        {
            Piece att = new Spy(Ownership.FirstPlayer);
            ICell def = new Sergeant(Ownership.FirstPlayer);

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }
Exemple #11
0
        public void TestFailOnAttackWaterMiner_ThrowsPieceConflictHandlerException()
        {
            Piece att = new Miner(Ownership.SecondPlayer);
            ICell def = new WaterCell();

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }
Exemple #12
0
        public void TestFailOnAttackerBomb_ThrowsPieceConflictHandlerException()
        {
            Piece att = new Bomb(Ownership.FirstPlayer);
            ICell def = new Scout(Ownership.SecondPlayer);

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }