예제 #1
0
        public SquareNode(BoardNode board, Piece.Colour colour, Position position)
        {
            Board = board;

            Colour   = colour;
            Position = position;
        }
예제 #2
0
        public PieceDrawer(BoardNode board)
        {
            Board = board;

            Board.WhitePlayer.MoveFromSelected += MoveFromSelected;
            Board.BlackPlayer.MoveFromSelected += MoveFromSelected;
        }
예제 #3
0
        public override void _Ready()
        {
            Rect = new ColorRect();
            AddChild(Rect);
            Rect.Color    = Colour == Piece.Colour.White ? WhiteColour : BlackColour;
            Rect.RectSize = new Vector2(SquareSize, SquareSize);

            var pos = BoardNode.ScreenCoords(Position);

            Rect.RectPosition = pos;
        }
예제 #4
0
        public override void _Ready()
        {
            Board = GetParent <BoardNode>();

            Board.Checkmate += OnCheckmate;
            Board.Stalemate += OnStalemate;

            PromotionUI = GetNode <PromotionUI>("Promotion");

            GetNode <Button>("Checkmate/Menu").Connect("pressed", this, nameof(Menu));
            GetNode <Button>("Stalemate/Menu").Connect("pressed", this, nameof(Menu));
        }
예제 #5
0
        public HumanPlayer(BoardNode board, Piece.Colour colour) : base(board, colour)
        {
            SquareClickedTcs     = new TaskCompletionSource <Position>();
            board.SquareClicked += p =>
            {
                if (Board.CurrentPlayer != Colour)
                {
                    return;
                }

                SquareClickedTcs.SetResult(p);
                SquareClickedTcs = new TaskCompletionSource <Position>();
            };
        }
예제 #6
0
        private void DrawPieces()
        {
            for (int i = 0; i < Chess.Board.Size; i++)
            {
                for (int j = 0; j < Chess.Board.Size; j++)
                {
                    var position = new Position(j, i);

                    if (Board.Board[position] is Piece piece)
                    {
                        DrawTexture(PieceTexture(piece), BoardNode.ScreenCoords(position));
                    }
                }
            }
        }
예제 #7
0
        public override void _Ready()
        {
            Board = GetParent <UI>().GetParent <BoardNode>();

            Tcs = new TaskCompletionSource <Piece.PieceType>();

            Rook   = GetNode <TextureButton>("Choices/Rook");
            Knight = GetNode <TextureButton>("Choices/Knight");
            Bishop = GetNode <TextureButton>("Choices/Bishop");
            Queen  = GetNode <TextureButton>("Choices/Queen");

            Rook.Connect("pressed", this, nameof(RookChosen));
            Knight.Connect("pressed", this, nameof(KnightChosen));
            Bishop.Connect("pressed", this, nameof(BishopChosen));
            Queen.Connect("pressed", this, nameof(QueenChosen));
        }
예제 #8
0
파일: Menu.cs 프로젝트: Leowbattle/Chess
        private Player CreatePlayer(PlayerTypeSelector.PlayerType type, BoardNode board, Piece.Colour colour)
        {
            switch (type)
            {
            case PlayerTypeSelector.PlayerType.Human:
                return(new HumanPlayer(board, colour));

            case PlayerTypeSelector.PlayerType.Computer:
                return(new AIPlayer(board, colour));

            case PlayerTypeSelector.PlayerType.Random:
                return(new RandomPlayer(board, colour));

            default:
                throw new ApplicationException($"Invalid player type {type}");
            }
        }
예제 #9
0
        private void VisualiseMoves()
        {
            if (MoveFrom.HasValue)
            {
                DrawRect(new Rect2(BoardNode.ScreenCoords(MoveFrom.Value), new Vector2(SquareNode.SquareSize, SquareNode.SquareSize)), Colors.Blue);
            }

            if (Board.LegalMoves != null)
            {
                foreach (var move in Board.LegalMoves.Where(m => m.From == MoveFrom))
                {
                    var colour = Colors.Limegreen;
                    if (Board.Board[move.To].HasValue)
                    {
                        colour = Colors.Red;
                    }
                    DrawRect(new Rect2(BoardNode.ScreenCoords(move.To), new Vector2(SquareNode.SquareSize, SquareNode.SquareSize)), colour);
                }
            }
        }
예제 #10
0
 protected Player(BoardNode board, Piece.Colour colour)
 {
     Board  = board;
     Colour = colour;
 }
예제 #11
0
 public RandomPlayer(BoardNode board, Piece.Colour colour) : base(board, colour)
 {
     Random = new Random();
 }
예제 #12
0
 public AIPlayer(BoardNode board, Piece.Colour colour) : base(board, colour)
 {
     MoveChooser = new MoveChooser(colour);
     Constants   = AIConstants.Default;
 }