Beispiel #1
0
 /// <summary>
 /// Shows where a player can possibly play by anchoring his counter where he can actually play
 /// otherwise shows his counter nearly visible when mouse is on board
 /// </summary>
 /// <param name="sender">sender object</param>
 /// <param name="e">mouse event</param>
 private void BoardHover(object sender, MouseEventArgs e)
 {
     //If game has started
     if (isPlaying)
     {
         rectHover.Name = "hoverRect";
         //Getting board canvas dimensions
         double canvasHeight = canBoard.ActualHeight;
         double dH           = canvasHeight / 8.0;
         double canvasWidth  = canBoard.ActualWidth;
         double dW           = canvasWidth / 8.0;
         //Getting mouse positions
         double mouseX = e.GetPosition(canBoard).X;
         double mouseY = e.GetPosition(canBoard).Y;
         //Setting counter dimensions
         rectHover.Width  = dW;
         rectHover.Height = dH;
         //Setting counter positions
         int squareIdI = (int)(mouseX / dW);
         int squareIdJ = (int)(mouseY / dH);
         //Setting counter skin based on player turn
         if (turnToWhite)
         {
             rectHover.Fill = skinPlayer1.Clone();
         }
         else
         {
             rectHover.Fill = skinPlayer2.Clone();
         }
         //Anchoring counter if possible play
         if (board.IsPlayable(squareIdI, squareIdJ, turnToWhite))
         {
             Canvas.SetTop(rectHover, (squareIdJ * dH));
             Canvas.SetLeft(rectHover, (squareIdI * dW));
             rectHover.Fill.Opacity = 0.6;
         }
         else
         {
             Canvas.SetTop(rectHover, mouseY - dH / 2);
             Canvas.SetLeft(rectHover, mouseX - dW / 2);
             rectHover.Fill.Opacity = 0.2;
         }
         rectHover.InvalidateVisual();
         //Counter only if on board
         if (canBoard.Children.Contains(rectHover))
         {
             if (mouseX > canvasWidth || mouseX > canvasHeight || mouseX < 0 || mouseY < 0)
             {
                 canBoard.Children.Remove(rectHover);
             }
         }
         else
         {
             canBoard.Children.Add(rectHover);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Met à jour le plateau et check si un joueur doit passer son tour.
        /// </summary>
        /// <returns>True si le joueur doit passer son tour.</returns>
        private bool UpdateUIBoard()
        {
            var  tabBoard   = board.GetBoard();
            bool shouldPass = true;

            for (int c = 0; c < 8; c++)
            {
                for (int l = 0; l < 8; l++)
                {
                    if (board.IsPlayable(c, l, whiteTurn))
                    {
                        cells[c, l].IsPlayable = whiteTurn ? 0 : 1;
                        // Au moins un coup est jouable, pas besoin de passer son tour
                        shouldPass = false;
                    }
                    else
                    {
                        cells[c, l].IsPlayable = -1;
                    }

                    cells[c, l].Val = tabBoard[c, l];
                }
            }
            return(shouldPass);
        }
Beispiel #3
0
        /// <summary>
        /// Refresh the button of the grid according to the board state
        /// </summary>
        public void UpdateGridValue()
        {
            int[,] gridBoard = board.GetBoard();
            int numPlayableTiles = 0;
            int numEmptyTiles    = 0;

            for (int y = 0; y < Constants.GRID_SIZE; y++)
            {
                for (int x = 0; x < Constants.GRID_SIZE; x++)
                {
                    //Set the playable tiles
                    if (board.IsPlayable(x, y, board.GetTurn()))
                    {
                        tiles[x, y].IsPlayable = true;
                        numPlayableTiles++;
                    }
                    else
                    {
                        tiles[x, y].IsPlayable = false;
                    }

                    if (gridBoard[x, y] == -1)
                    {
                        numEmptyTiles++;
                    }

                    tiles[x, y].State = gridBoard[x, y];
                }
            }

            updateImagePlayer();
            checkGameEnd(numPlayableTiles, numEmptyTiles);
        }