Example #1
0
            /// <summary>
            /// Constructor for Board class objects
            /// </summary>
            /// <param name="size">Determines the size of the PlayingBoards</param>
            public Board(int size)
            {
                FreeTile             = new Panel();
                FreeTile.Size        = new Size(50, 50);
                FreeTile.AllowDrop   = true;
                FreeTile.BorderStyle = BorderStyle.Fixed3D;

                PlayingBoard = new Panel[size, size];

                Players = new Player[4];

                //If the board is 7*7
                if (size == 7)
                {
                    Tile freetile = new Tile(random);
                    freetile.DetermineTilePicture();
                    freetile.Enabled = true;
                    FreeTile.Controls.Add(freetile);
                }

                //If the board is 9*9
                else
                {
                    Tile freetile = new Tile(random);
                    freetile.DetermineTilePicture();
                    freetile.Enabled = true;
                    FreeTile.Controls.Add(freetile);
                }
                FreeTile.Location = new Point(1100, 10);

                FreeTile.DragDrop += Panel_DragDrop;
            }
Example #2
0
            /// <summary>
            /// Fills the PlayingBoard matrix with objects. Creates the FreeTile
            /// </summary>
            public void FillBoardWithTile()
            {
                for (int x = 0; x < PlayingBoard.GetLength(0); x++)
                {
                    for (int y = 0; y < PlayingBoard.GetLength(1); y++)
                    {
                        Panel panel = new Panel();
                        panel.Size        = new Size(50, 50);
                        panel.AllowDrop   = true;
                        panel.BorderStyle = BorderStyle.Fixed3D;

                        panel.DragEnter += Board_DragEnter;
                        panel.DragDrop  += Player_DragDrop;

                        PlayingBoard[x, y] = panel;

                        //Sets the properties of the fixed tiles (e.g: starting locations)
                        if (y % 2 == 0 && x % 2 == 0)
                        {
                            Tile tile = new Tile(random);

                            #region Starting Locations
                            if ((y * PlayingBoard.GetLength(0)) + (x + 1) == 1)
                            {
                                tile.PathRight = true; tile.PathDown = true;
                                tile.PathUp    = false; tile.PathLeft = false;
                            }
                            else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == PlayingBoard.GetLength(0))
                            {
                                tile.PathDown = true; tile.PathLeft = true;
                                tile.PathUp   = false; tile.PathRight = false;
                            }
                            else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == (PlayingBoard.GetLength(0) * PlayingBoard.GetLength(0)) - (PlayingBoard.GetLength(0) - 1))
                            {
                                tile.PathUp   = true; tile.PathRight = true;
                                tile.PathDown = false; tile.PathLeft = false;
                            }

                            else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == (PlayingBoard.GetLength(0) * PlayingBoard.GetLength(0)))
                            {
                                tile.PathUp    = true; tile.PathLeft = true;
                                tile.PathRight = false; tile.PathDown = false;
                            }
                            #endregion

                            #region Other Fix Tiles
                            else if (y == 0)
                            {
                                tile.PathRight = true; tile.PathDown = true; tile.PathLeft = true;
                                tile.PathUp    = false;
                            }

                            else if (y == PlayingBoard.GetLength(0) - 1)
                            {
                                tile.PathUp   = true; tile.PathRight = true; tile.PathLeft = true;
                                tile.PathDown = false;
                            }

                            else if (x == 0)
                            {
                                tile.PathUp   = true; tile.PathRight = true; tile.PathDown = true;
                                tile.PathLeft = false;
                            }

                            else if (x == PlayingBoard.GetLength(1) - 1)
                            {
                                tile.PathUp    = true; tile.PathDown = true; tile.PathLeft = true;
                                tile.PathRight = false;
                            }
                            #endregion

                            tile.Size = new Size(50, 50);
                            tile.DetermineTilePicture();

                            //PlayingBoard[x, y].Enabled = false;

                            PlayingBoard[x, y].Controls.Add(tile);
                        }
                        //Adds the non-fixed tiles to the board matrix
                        else
                        {
                            Tile tile = new Tile(random);
                            tile.Size = new Size(50, 50);

                            tile.DetermineTilePicture();

                            PlayingBoard[x, y].Controls.Add(tile);
                        }
                    }
                }
            }