コード例 #1
0
ファイル: Form1.cs プロジェクト: khetsothea/ChessGame
        private void ColorAvailableMovments(PictureBox clickedPicture)
        {
            TableLayoutPanelCellPosition tableLayoutPanelCellPosition = BoardLayoutPanel.GetPositionFromControl(clickedPicture);
            Piece selectedPiece = Board.GetPiece(ConverTFromCellPositionToPostion(tableLayoutPanelCellPosition));

            if (selectedPiece == null)
            {
                MessageBox.Show("this move unavailable for some reason :( .");
                return;
            }
            if (((selectedPiece.Color == PieceColor.Black) && (CurrentTurn == Turn.White)) || ((selectedPiece.Color == PieceColor.White) && (CurrentTurn == Turn.Black)))
            {
                return;
            }
            clickedPicture.BackColor = Color.Yellow;

            foreach (Position item in selectedPiece.AvailabePosisions)
            {
                TableLayoutPanelCellPosition cellPosision = ConvertFromPostionToCellPosition(item);
                PictureBox PicBox    = BoardLayoutPanel.GetControlFromPosition(cellPosision.Column, cellPosision.Row) as PictureBox;
                Piece      PieceItem = Board.GetPiece(item);
                if (PieceItem.Color != PieceColor.Unknown)
                {
                    PicBox.BackColor = Color.Red;
                }
                else
                {
                    PicBox.BackColor = Color.ForestGreen;
                }
                AvailablePiecesToMove.Add(PicBox);
            }
        }
コード例 #2
0
ファイル: BoardView1.cs プロジェクト: piotrekradomski/SE
        public void ShowPlayerGoals()
        {
            //Player p = MyGlobals.players.First();
            List <Goal> myGoals;

            if (player.colour == MessageProject.Team.blue)
            {
                myGoals = MyGlobals.goalsBlue;
            }
            else
            {
                myGoals = MyGlobals.goalsRed;
            }

            foreach (Goal g in myGoals)
            {
                if (g.getDiscoveror() == player)
                {
                    // retrieve goal and its bitmap
                    PictureBox temp;
                    temp        = new PictureBox();
                    temp.Image  = g.getDiscoveredBitmap();
                    temp.Margin = new Padding(0);

                    // only add bitmap if table cell is empty
                    Control c = BoardLayoutPanel.GetControlFromPosition(g.getPosX(), g.getPosY());
                    if (c == null)
                    {
                        BoardLayoutPanel.Controls.Add(temp, g.getPosX(), g.getPosY());
                    }
                }
            }
        }
コード例 #3
0
        public void ReadPlayers()
        {
            Player p = MyGlobals.players.First();

            test.Image  = p.getBitmap();
            test.Margin = new Padding(0);

            // if thre is already a bitmap on the cell, remove it first
            // then add the player's bitmap
            Control c = BoardLayoutPanel.GetControlFromPosition(p.getPosX(), p.getPosY());

            BoardLayoutPanel.Controls.Remove(c);
            BoardLayoutPanel.Controls.Add(test, p.getPosX(), p.getPosY());
        }
コード例 #4
0
        public void AddGoals()
        {
            for (int i = 0; i < MyGlobals.nrGoals; i++)
            {
                // retrieve goal and its bitmap (Blue)
                PictureBox temp;
                Goal       blueG = MyGlobals.goalsBlue[i];
                temp = new PictureBox();
                if (blueG.getDiscovered())
                {
                    temp.Image = blueG.getDiscoveredBitmap();
                }
                else
                {
                    temp.Image = blueG.getBitmap();
                }
                temp.Margin = new Padding(0);

                // only add bitmap if table cell is empty
                Control c = BoardLayoutPanel.GetControlFromPosition(blueG.getPosX(), blueG.getPosY());
                if (c == null)
                {
                    BoardLayoutPanel.Controls.Add(temp, blueG.getPosX(), blueG.getPosY());
                }

                // retrieve goal and its bitmap (Red)
                Goal redG = MyGlobals.goalsRed[i];
                temp = new PictureBox();
                if (redG.getDiscovered())
                {
                    temp.Image = redG.getDiscoveredBitmap();
                }
                else
                {
                    temp.Image = redG.getBitmap();
                }
                temp.Margin = new Padding(0);

                // only add bitmap if table cell is empty
                c = BoardLayoutPanel.GetControlFromPosition(redG.getPosX(), redG.getPosY());
                if (c == null)
                {
                    BoardLayoutPanel.Controls.Add(temp, redG.getPosX(), redG.getPosY());
                }
            }
        }
コード例 #5
0
ファイル: BoardView1.cs プロジェクト: piotrekradomski/SE
        public void ShowManhattanDistance()
        {
            Player p = player;

            //p.computeManDist();
            for (int i = 0; i < MyGlobals.seenDistances.GetLength(0); i++)
            {
                for (int j = smallHeight; j < MyGlobals.seenDistances.GetLength(1) - smallHeight; j++)
                {
                    Label l = new Label()
                    {
                        AutoSize  = false,
                        TextAlign = ContentAlignment.MiddleCenter,
                        Dock      = DockStyle.Fill,
                    };
                    l.Margin = new Padding(2);


                    // if no piece on the board, show nothing
                    if (MyGlobals.seenDistances[i, j] == -1)
                    {
                        l.Text = "";
                    }
                    // if a piece exists, show distance
                    else
                    {
                        l.Text = MyGlobals.seenDistances[i, j].ToString();
                    }

                    Control c = BoardLayoutPanel.GetControlFromPosition(i, j);

                    /* foreach (Player item in MyGlobals.players) {
                     *   if (item.getPosX() == i && item.getPosY() == j)
                     *   {
                     *       continue;
                     *   }
                     *   if (c != null) {
                     *       BoardLayoutPanel.Controls.Remove(c);
                     *   }
                     *   BoardLayoutPanel.Controls.Add(l, i, j);
                     * }
                     */
                }
            }
        }
コード例 #6
0
        public void AddPieces()
        {
            for (int i = 0; i < MyGlobals.nrPieces; i++)
            {
                // retrieve piece and its bitmap (Blue)
                PictureBox temp;
                Piece      pi = MyGlobals.pieces[i];
                temp        = new PictureBox();
                temp.Image  = pi.getBitmap();
                temp.Margin = new Padding(0);

                // only add bitmap if table cell is empty
                Control c = BoardLayoutPanel.GetControlFromPosition(pi.getPosX(), pi.getPosY());
                if (c == null)
                {
                    BoardLayoutPanel.Controls.Add(temp, pi.getPosX(), pi.getPosY());
                }
            }
        }
コード例 #7
0
        void MoveDown()
        {
            Player bp = MyGlobals.players.First();

            bp.MoveDown();

            //remove previous label
            Control c = BoardLayoutPanel.GetControlFromPosition(bp.getPosX(), bp.getPosY());

            BoardLayoutPanel.Controls.Remove(c);

            BoardLayoutPanel.Controls.Add(test, bp.getPosX(), bp.getPosY());
            MyGlobals.gameMasterView.ReadPlayers();
            MyGlobals.gameMasterView.AddGoals();
            MyGlobals.gameMasterView.AddPieces();
            //bp.testDistConsole(); // just for checking
            ShowManhattanDistance();
            ShowPlayerGoals();
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: khetsothea/ChessGame
 private void MovePiece(TableLayoutPanelCellPosition Position1, TableLayoutPanelCellPosition Position2)
 {
     // Move to new position and if it sucess do this :
     if (Board.MovePieceToPosition(ConverTFromCellPositionToPostion(Position1), ConverTFromCellPositionToPostion(Position2)))
     {
         (BoardLayoutPanel.GetControlFromPosition(Position2.Column, Position2.Row) as PictureBox).Image     = (BoardLayoutPanel.GetControlFromPosition(Position1.Column, Position1.Row) as PictureBox).Image;
         (BoardLayoutPanel.GetControlFromPosition(Position1.Column, Position1.Row) as PictureBox).Image     = null;
         (BoardLayoutPanel.GetControlFromPosition(Position1.Column, Position1.Row) as PictureBox).BackColor = Color.Transparent;
         foreach (PictureBox item in AvailablePiecesToMove)
         {
             item.BackColor = Color.Transparent;
         }
         AvailablePiecesToMove.Clear();
         SwitchTurns();
     }
     else
     {
         MessageBox.Show("this move unavailable for some reason :( .");
     }
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: khetsothea/ChessGame
        private void InitializeBoard()
        {
            // Black Pieces :

            (BoardLayoutPanel.GetControlFromPosition(0, 0) as PictureBox).Image = Properties.Resources.BlackRook;
            (BoardLayoutPanel.GetControlFromPosition(1, 0) as PictureBox).Image = Properties.Resources.BlackKnight;
            (BoardLayoutPanel.GetControlFromPosition(2, 0) as PictureBox).Image = Properties.Resources.BlackBishop;
            (BoardLayoutPanel.GetControlFromPosition(3, 0) as PictureBox).Image = Properties.Resources.BlackKing;
            (BoardLayoutPanel.GetControlFromPosition(4, 0) as PictureBox).Image = Properties.Resources.BlackQueen;
            (BoardLayoutPanel.GetControlFromPosition(5, 0) as PictureBox).Image = Properties.Resources.BlackBishop;
            (BoardLayoutPanel.GetControlFromPosition(6, 0) as PictureBox).Image = Properties.Resources.BlackKnight;
            (BoardLayoutPanel.GetControlFromPosition(7, 0) as PictureBox).Image = Properties.Resources.BlackRook;
            for (int column = 0; column < 8; column++)
            {
                (BoardLayoutPanel.GetControlFromPosition(column, 1) as PictureBox).Image = Properties.Resources.BlackPawn;
            }

            // Empty Pieces :
            for (int column = 0; column < 8; column++)
            {
                for (int row = 2; row < 5; row++)
                {
                    (BoardLayoutPanel.GetControlFromPosition(column, row) as PictureBox).Image = null;
                }
            }

            // White Pieces :
            (BoardLayoutPanel.GetControlFromPosition(0, 7) as PictureBox).Image = Properties.Resources.WhiteRook;
            (BoardLayoutPanel.GetControlFromPosition(1, 7) as PictureBox).Image = Properties.Resources.WhiteKinght;
            (BoardLayoutPanel.GetControlFromPosition(2, 7) as PictureBox).Image = Properties.Resources.WhiteBishop;
            (BoardLayoutPanel.GetControlFromPosition(3, 7) as PictureBox).Image = Properties.Resources.WhiteKing;
            (BoardLayoutPanel.GetControlFromPosition(4, 7) as PictureBox).Image = Properties.Resources.WhiteQueen;
            (BoardLayoutPanel.GetControlFromPosition(5, 7) as PictureBox).Image = Properties.Resources.WhiteBishop;
            (BoardLayoutPanel.GetControlFromPosition(6, 7) as PictureBox).Image = Properties.Resources.WhiteKinght;
            (BoardLayoutPanel.GetControlFromPosition(7, 7) as PictureBox).Image = Properties.Resources.WhiteRook;
            for (int column = 0; column < 8; column++)
            {
                (BoardLayoutPanel.GetControlFromPosition(column, 6) as PictureBox).Image = Properties.Resources.WhitePawn;
            }
        }