コード例 #1
0
        private void RearangePiecesLoad(Board curBoard)
        {
            int[,] piecePositions = curBoard.GetPiecePositions();

            int curPieceNumber = 0;

            int[] blackCaptured = new int[2] {
                1, 1
            };

            int[] whiteCaptured = new int[2] {
                1, 1
            };

            for (int i = 0; i < 8; i++)
            {
                for (int k = 0; k < 8; k++)
                {
                    curPieceNumber = piecePositions[i, k];
                    if (curPieceNumber == 0)
                    {
                        continue;
                    }
                    else
                    {
                        Button curPiece = (Button)this.FindName($"p{curPieceNumber}");  //need to check if it is in grid or in captured grid
                        Grid.SetRow(curPiece, i + 1);
                        Grid.SetColumn(curPiece, k + 1);
                    }
                }
            }

            foreach (int piece in curBoard.GetCapturedPieces())
            {
                Button curPiece = (Button)this.FindName($"p{piece}");
                if (piece < 17)
                {
                    Grid.SetRow(curPiece, whiteCaptured[0]);
                    Grid.SetColumn(curPiece, whiteCaptured[1]);
                    getGrid().Children.Remove(curPiece);
                    UIGlobal.getPlayer2Grid().Children.Add(curPiece);
                    if (whiteCaptured[1] == 2) //increments grid location
                    {
                        whiteCaptured[0]++;
                        whiteCaptured[1] = 1;
                    }
                    else
                    {
                        whiteCaptured[1]++;
                    }
                }
                else
                {
                    Grid.SetRow(curPiece, blackCaptured[0]);
                    Grid.SetColumn(curPiece, blackCaptured[1]);
                    getGrid().Children.Remove(curPiece);
                    UIGlobal.getPlayer1Grid().Children.Add(curPiece);
                    if (blackCaptured[1] == 2) //increments grid location
                    {
                        blackCaptured[0]++;
                        blackCaptured[1] = 1;
                    }
                    else
                    {
                        blackCaptured[1]++;
                    }
                }
            }
            if (chessBoard.GetTurn() == 0)                                            //turn = 0 is white, turn = 1 is black
            {
                for (int i = 1; i < 17; i++)                                          //sets all the white buttons to an opacity of 1 and enables the buttons
                {
                    Button curButton = UIGlobal.XAMLpage.FindName($"p{i}") as Button; //gets piece by name
                    if (!curButton.IsEnabled && curButton.Opacity == 1)               //checks to see if it is in the captured bank
                    {
                        continue;
                    }
                    curButton.IsEnabled = true;
                    curButton.Opacity   = 1;
                }
                for (int i = 17; i < 33; i++)                                         //sets all the black buttons to an opacity of .7 and disables the buttons
                {
                    Button curButton = UIGlobal.XAMLpage.FindName($"p{i}") as Button; //gets piece by name
                    if (!curButton.IsEnabled && curButton.Opacity == 1)               //checks to see if it is in the captured bank
                    {
                        continue;
                    }
                    curButton.IsEnabled = false;
                    curButton.Opacity   = .7;
                }
            }
            else
            {
                for (int i = 1; i < 17; i++)                                          //sets all the white buttons to an opacity of .7 and disables the buttons
                {
                    Button curButton = UIGlobal.XAMLpage.FindName($"p{i}") as Button; //gets piece by name
                    if (!curButton.IsEnabled && curButton.Opacity == 1)               //checks to see if it is in the captured bank
                    {
                        continue;
                    }
                    curButton.IsEnabled = false;
                    curButton.Opacity   = .7;
                }
                for (int i = 17; i < 33; i++)                                         //sets all the black buttons to an opacity of 1 and enables the buttons
                {
                    Button curButton = UIGlobal.XAMLpage.FindName($"p{i}") as Button; //gets piece by name
                    if (!curButton.IsEnabled && curButton.Opacity == 1)               //checks to see if it is in the captured bank
                    {
                        continue;
                    }
                    curButton.IsEnabled = true;
                    curButton.Opacity   = 1;
                }
            }
        }
コード例 #2
0
 private void RearangePieces()
 {
     for (int i = 1; i < 9; i++)
     {
         Button curPiece = (Button)this.FindName($"p{i}");
         Grid   parent   = (Grid)curPiece.Parent;
         if (parent.Name == "maingrid")
         {
             Grid.SetRow(curPiece, 1);
             Grid.SetColumn(curPiece, i);
         }
         else if (parent.Name == "player1grid")
         {
             UIGlobal.getPlayer1Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 1);
             Grid.SetColumn(curPiece, i);
         }
         else if (parent.Name == "player2grid")
         {
             UIGlobal.getPlayer2Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 1);
             Grid.SetColumn(curPiece, i);
         }
         curPiece.IsEnabled = true;
         curPiece.Opacity   = 1;
     }
     for (int i = 9, j = 1; j < 9 && i < 17; i++, j++)
     {
         Button curPiece = (Button)this.FindName($"p{i}");
         Grid   parent   = (Grid)curPiece.Parent;
         if (parent.Name == "maingrid")
         {
             Grid.SetRow(curPiece, 2);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player1grid")
         {
             UIGlobal.getPlayer1Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 2);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player2grid")
         {
             UIGlobal.getPlayer2Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 2);
             Grid.SetColumn(curPiece, j);
         }
         curPiece.IsEnabled = true;
         curPiece.Opacity   = 1;
     }
     for (int i = 17, j = 1; j < 9 && i < 25; i++, j++)
     {
         Button curPiece = (Button)this.FindName($"p{i}");
         Grid   parent   = (Grid)curPiece.Parent;
         if (parent.Name == "maingrid")
         {
             Grid.SetRow(curPiece, 7);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player1grid")
         {
             UIGlobal.getPlayer1Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 7);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player2grid")
         {
             UIGlobal.getPlayer2Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 7);
             Grid.SetColumn(curPiece, j);
         }
         curPiece.IsEnabled = false;
         curPiece.Opacity   = 0.7;
     }
     for (int i = 25, j = 1; j < 9 && i < 33; i++, j++)
     {
         Button curPiece = (Button)this.FindName($"p{i}");
         Grid   parent   = (Grid)curPiece.Parent;
         if (parent.Name == "maingrid")
         {
             Grid.SetRow(curPiece, 8);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player1grid")
         {
             UIGlobal.getPlayer1Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 8);
             Grid.SetColumn(curPiece, j);
         }
         else if (parent.Name == "player2grid")
         {
             UIGlobal.getPlayer2Grid().Children.Remove(curPiece);
             getGrid().Children.Add(curPiece);
             Grid.SetRow(curPiece, 8);
             Grid.SetColumn(curPiece, j);
         }
         curPiece.IsEnabled = false;
         curPiece.Opacity   = 0.7;
     }
 }