Example #1
0
        /// <summary>
        /// Update the board UI depends on the logical board
        /// </summary>
        private void UpdateBoard()
        {
            int[,] board = gameController.GetBoard();

            //For the 2 Dimension LogicalBoard
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    int logicSquare = board[j, i];
                    ChessSquareControl graphicalSquare = GetChessControlFromIndex(i, j);

                    //Update board values
                    if (logicSquare == (int)LogicalBoard.PawnState.White)
                    {
                        graphicalSquare.SetWhite();
                    }
                    else if (logicSquare == (int)LogicalBoard.PawnState.Black)
                    {
                        graphicalSquare.SetBlack();
                    }
                    else
                    {
                        graphicalSquare.setEmpty();
                    }

                    //Check each cases if they are playable
                    graphicalSquare.IsEnabled = gameController.IsPlayable(j, i);
                }
            }
        }
Example #2
0
        /// <summary>
        /// initialization of the graphical board
        /// </summary>
        /// <param name="column">size x</param>
        /// <param name="line">size y</param>
        private void InitBoard(int column, int line)
        {
            graphicalBoard = Board;
            graphicalBoard.Children.Clear();

            for (int i = 0; i < column; i++)
            {
                for (int j = 0; j < line; j++)
                {
                    ChessSquareControl square = new ChessSquareControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        VerticalAlignment   = VerticalAlignment.Stretch
                    };

                    square.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnBoardClick));

                    square.x = j;
                    square.y = i;

                    graphicalBoard.Children.Add(square);
                }
            }

            UpdateBoard();
        }
Example #3
0
        /// <summary>
        /// Called when the user click on a ChessSquareControl
        /// (a case of the board)
        /// </summary>
        /// <param name="sender">the object who send the signal (ChessSquareControl)</param>
        /// <param name="e">args passed from the signal. Unused here</param>
        private void OnBoardClick(object sender, RoutedEventArgs e)
        {
            ChessSquareControl square = (ChessSquareControl)sender;

            bool gameContinue = gameController.PlayMove(square.x, square.y);

            UpdateInterface();

            if (!gameContinue)
            {
                //No one can play, game is over
                ShowEndMenu(false, false);
            }
        }