Esempio n. 1
0
 private void addGameHistoryMove(Move move)
 {
     gameMovesHistory.Items.Insert(0, movesDone.Count + ". " + Coords.getCoordsStr(move) + " " + (desk.getCurrentPlayer() == GameVar.PLAYER_WHITE ? playerWhiteName.Text : playerBlackName.Text));
 }
Esempio n. 2
0
        private void handlePieceClick(Object sender, EventArgs e)
        {
            if (!pieceClickListening)
            {
                return;
            }

            bool setAIButtons = false;

            cancelAIComputing(setAIButtons);    // AI computing "show best move" could be in progress

            PictureBox pieceClicked = (PictureBox)sender;

            int[] coords = Coords.getPieceCoordsFromName(pieceClicked.Name);

            if (isPieceSelectError)
            {
                tableDesk.Refresh();
                isPieceSelected    = false;
                isPieceSelectError = false;
            }

            if (wasClickedOnOwnPiece(desk.getCurrentPlayer(), coords))      // start piece of move
            {
                // clean previously highlighted pieces
                tableDesk.Refresh();
                piecesSelected.Clear();

                pieceFocused    = pieceClicked;
                isPieceSelected = true;
                if (showPossibleMoves)
                {
                    highlightPossibleMovesFromPiece(pieceFocused, piecesSelected);
                }
                else
                {
                    drawPictureBoxControl(pieceClicked, Properties.Resources.piece_control_select);
                }
            }
            else if (isPieceSelected)                                          // following pieces of move
            {
                if (isPartialMove(pieceFocused, pieceClicked, piecesSelected)) // move cannot be made yet, clicked piece is not end piece
                {
                    piecesSelected.Add(pieceClicked);
                    if (showPossibleMoves)
                    {
                        highlightPossibleMovesFromPiece(pieceFocused, piecesSelected);
                    }
                    else
                    {
                        drawPictureBoxControl(pieceClicked, Properties.Resources.piece_control_select);
                    }
                    return;
                }
                try
                {
                    makeHumanMove(pieceFocused, pieceClicked, piecesSelected);
                }
                catch       // selected move isn't possible
                {
                    bool      cleanOutput   = true;
                    ArrayList possibleMoves = rules.getPossibleMoves(desk, desk.getCurrentPlayer());
                    Random    r             = new Random();
                    Move      randomMove    = (Move)possibleMoves[r.Next(0, possibleMoves.Count)];
                    drawPictureBoxControl(pieceClicked, Properties.Resources.piece_control_error);
                    addGameNotice("you could play for example " + Coords.getCoordsStr(randomMove), cleanOutput);
                    addGameNotice("move " + Coords.getCoordsStr(pieceFocused) + " " + Coords.getCoordsStr(pieceClicked) + " is not possible");
                }
                isPieceSelectError = true;
            }
            else    // clicked on some piece without possibility of making move
            {
                tableDesk.Refresh();
                isPieceSelected = false;
            }
        }