示例#1
0
        public Boolean VerifyMove(Position start, Position end)
        {
            ICell attacker = CellAtPos(start);
            ICell defender = CellAtPos(end);

            if (attacker is null || attacker.GetOwnership() == Ownership.Board || defender is null ||
                defender.GetOwnership() == attacker.GetOwnership() || defender is WaterCell)
            {
                return(false);
            }

            return(attacker.GetValidMoves(this, start).Contains(end));
        }
示例#2
0
 public static void CellFormaterPrinter(ICell cell)
 {
     //Console.Write("| ",);
     //Drawing.Color slateBlue = Color.FromName("SlateBlue");
     Console.Write("| ");
     Console.Write("{0}", cell.ToDisplayString(), OwnershipToColor(cell.GetOwnership()));
 }
示例#3
0
        // Should return either attacker, defender or empty
        // Assuming that if attacker is movable its movement is legal
        // TODO: Rewrite as conditioned Switch

        public static ICell Handle(Piece attacker, ICell defender)
        {
            if (attacker.GetOwnership() == defender.GetOwnership() || attacker.GetOwnership() == Ownership.Board ||
                !(attacker is MovablePiece) || defender is WaterCell || defender is Enemy)
            {
                throw new PieceConflictHandlerException("Illegal Attacker or Defender");
            }

            if (defender is EmptyCell)
            {
                return(attacker);
            }

            if (defender is Piece)
            {
                ICell ans;
                switch (((Piece)defender).GetRank())
                {
                case Rank.Bomb:
                    ans = attacker.GetRank() == Rank.Miner ? attacker : defender;
                    break;

                case Rank.Flag:
                    // TODO: alert game over?
                    // If not, could handled by default case
                    ans = attacker;
                    break;

                case Rank.Marshal:
                    ans = attacker.GetRank() == Rank.Spy ? attacker : SimpleHandler(attacker, (Piece)defender);
                    break;

                default:
                    ans = SimpleHandler(attacker, (Piece)defender);
                    break;
                }
                return(ans);
            }

            else
            {
                throw new PieceConflictHandlerException("Unexpected Defender");
            }
        }