Esempio n. 1
0
        public void ShowValidPositions(Block block)
        {
            if (block == null)
            {
                return;
            }

            Piece piece = block.GetPiece();

            if (piece == null)
            {
                return;
            }

            PositionCalculator PosCalc = PosCalculatorFactory.GetPositionCalculator(piece.GetPieceType(), game.GetCurrentPlayer());

            Graphics g = container.CreateGraphics();

            try
            {
                ArrayList tempBlockList = PosCalc.CalculatePositions(block, false);
                ValidBlockList = (ArrayList)tempBlockList.Clone();

                for (int i = 0; i < ValidBlockList.Count; i++)
                {
                    ((Block)ValidBlockList[i]).SetIsHighLight(true);
                    DrawBlock(g, (Block)ValidBlockList[i], true, ((Block)ValidBlockList[i]).GetIsLastMove());
                }
            }
            finally
            {
                g.Dispose();
            }
        }
Esempio n. 2
0
        private bool CheckForOpponent(PieceColor pColor, Player aPlayer)
        {
            ArrayList TargetList     = new ArrayList();
            ArrayList tempTargetList = new ArrayList();

            ArrayList tempList;
            Piece     OpponentKingPiece;

            if (pColor == PieceColor.WHITE)
            {
                tempList          = WhitePieceList;
                OpponentKingPiece = BlackKingPiece;
            }
            else
            {
                tempList          = BlackPieceList;
                OpponentKingPiece = WhiteKingPiece;
            }

            for (int i = 0; i < PieceCount; i++)
            {
                Piece piece = (Piece)tempList[i];

                if (piece != null)
                {
                    Block block = piece.GetContainerBlock();
                    if (block != null)
                    {
                        PositionCalculator posCalculator = PosCalculatorFactory.GetPositionCalculator(piece.GetPieceType(), aPlayer);
                        tempTargetList = posCalculator.CalculatePositions(block, true);

                        TargetList.AddRange(tempTargetList);
                    }
                }
                tempTargetList.Clear();
            }

            return(IsKingInDanger(OpponentKingPiece, TargetList));
        }