Esempio n. 1
0
            /// <summary>
            /// Creates the set number of Player objects
            /// </summary>
            /// <param name="numofPlyers">Number of players</param>
            public void AddPlayersToBoard(int numofPlyers)
            {
                for (int i = 0; i < numofPlyers; i++)
                {
                    Player player;
                    switch (i)
                    {
                    case 0:
                        player = new Player(0, 0); Players[i] = player; PlayingBoard[0, 0].Controls.Add(Players[i]); player.BringToFront();
                        break;

                    case 1:
                        player = new Player(PlayingBoard.GetLength(0) - 1, 0); Players[i] = player; PlayingBoard[PlayingBoard.GetLength(0) - 1, 0].Controls.Add(Players[i]); player.BringToFront();
                        break;

                    case 2:
                        player = new Player(0, PlayingBoard.GetLength(1) - 1); Players[i] = player; PlayingBoard[0, PlayingBoard.GetLength(1) - 1].Controls.Add(Players[i]); player.BringToFront();
                        break;

                    case 3:
                        player = new Player(PlayingBoard.GetLength(0) - 1, PlayingBoard.GetLength(1) - 1); Players[i] = player; PlayingBoard[PlayingBoard.GetLength(0) - 1, PlayingBoard.GetLength(1) - 1].Controls.Add(Players[i]); player.BringToFront();
                        break;

                    default:
                        break;
                    }
                }
            }
Esempio n. 2
0
            /// <summary>
            /// Places the Tile objects from the PlayingBoard matrix
            /// </summary>
            /// <param name="control">Which control the objects should be added</param>
            public void PlaceTiles(Control control)
            {
                int y = 70, x = 70;

                for (int i = 0; i < PlayingBoard.GetLength(0); i++)
                {
                    for (int j = 0; j < PlayingBoard.GetLength(1); j++)
                    {
                        if (PlayingBoard[i, j] != null)
                        {
                            control.Controls.Add(PlayingBoard[i, j]);
                            PlayingBoard[i, j].Location = new Point(y, x);
                            x += 60;
                        }
                        else
                        {
                            x += 60;
                        }
                    }
                    x  = 70;
                    y += 60;
                }
                control.Controls.Add(FreeTile);
            }
Esempio n. 3
0
            /// <summary>
            /// Makes the specific row shift
            /// </summary>
            /// <param name="which_row"></param>
            /// <param name="left">Whether the row shift should happen from the left or the right</param>
            /// <param name="panel">Which control panel has the freetile placed in it</param>
            public void ShiftBoardRows(int which_row, bool left, Panel panel)
            {
                Control[] panel_array = new Control[1]; //Was Tile

                //Clones the tile, then sets the 'Enabled' property to false then removes the tile from the panel's control then add the edited tile
                Tile tile = (Tile)panel.Controls[0];

                tile.Enabled = false;
                panel.Controls.RemoveAt(0);
                panel.Controls.Add(tile);

                panel.Controls.CopyTo(panel_array, 0);
                List <Control[]> tiles = new List <Control[]>(); // Was Tile

                //Fills a list with the copies of the Tile objects inside the panels
                for (int i = 0; i < PlayingBoard.GetLength(0); i++)
                {
                    for (int j = 0; j < PlayingBoard.GetLength(1); j++)
                    {
                        if (i == which_row)
                        {
                            Control[] array = new Control[4]; //Was Tile
                            PlayingBoard[j, i].Controls.CopyTo(array, 0);
                            tiles.Add(array);
                        }
                    }
                }

                //If the free tile was placed in a right row control panel
                if (left)
                {
                    for (int i = 0; i < PlayingBoard.GetLength(0); i++)
                    {
                        for (int j = 1; j < PlayingBoard.GetLength(1); j++)
                        {
                            if (i == which_row)
                            {
                                PlayingBoard[j, i].Controls.Clear();
                                PlayingBoard[j, i].Controls.AddRange(tiles[j - 1]);
                            }
                        }
                    }
                    PlayingBoard[0, which_row].Controls.Clear();
                    PlayingBoard[0, which_row].Controls.AddRange(panel_array);

                    FreeTile.Controls.Clear();

                    tiles.Last().Last().Enabled = true;

                    FreeTile.Controls.AddRange(tiles.Last());

                    panel.Controls.Clear();
                }

                //If the free tile was placed in a left row control panel
                else
                {
                    for (int i = PlayingBoard.GetLength(0); i > 0; i--)
                    {
                        for (int j = PlayingBoard.GetLength(1) - 1; j > 0; j--)
                        {
                            if (i == which_row)
                            {
                                PlayingBoard[j - 1, i].Controls.Clear();
                                PlayingBoard[j - 1, i].Controls.AddRange(tiles[j]);
                            }
                        }
                    }
                    PlayingBoard[PlayingBoard.GetLength(0) - 1, which_row].Controls.Clear();
                    PlayingBoard[PlayingBoard.GetLength(0) - 1, which_row].Controls.AddRange(panel_array);

                    FreeTile.Controls.Clear();

                    tiles.First().First().Enabled = true;

                    FreeTile.Controls.AddRange(tiles.First());

                    panel.Controls.Clear();
                }
            }
Esempio n. 4
0
            /// <summary>
            /// Makes the specific columns shift
            /// </summary>
            /// <param name="which_colmun"></param>
            /// <param name="top">Whether the column shift should happen from the top or the bottom</param>
            /// <param name="panel">Which control panel has the freetile placed in it</param>
            public void ShiftBoardColumns(int which_colmun, bool top, Panel panel)
            {
                Control[] panel_array = new Control[1]; //Was Tile

                //Clones the tile, then sets the 'Enabled' property to false then removes the tile from the panel's control then add the edited tile
                Tile tile = (Tile)panel.Controls[0];

                tile.Enabled = false;
                panel.Controls.RemoveAt(0);
                panel.Controls.Add(tile);

                panel.Controls.CopyTo(panel_array, 0);


                List <Control[]> tiles = new List <Control[]>(); //Was TIle

                //Fills a list with the copies of the Tile objects inside the panels
                for (int i = 0; i < PlayingBoard.GetLength(0); i++)
                {
                    for (int j = 0; j < PlayingBoard.GetLength(1); j++)
                    {
                        if (j == which_colmun)
                        {
                            Control[] array = new Control[4]; //Was Tile
                            PlayingBoard[j, i].Controls.CopyTo(array, 0);
                            tiles.Add(array);
                        }
                    }
                }

                //If the free tile was placed in a top column control panel
                if (top)
                {
                    for (int i = 1; i < PlayingBoard.GetLength(0); i++)
                    {
                        for (int j = 0; j < PlayingBoard.GetLength(1); j++)
                        {
                            if (j == which_colmun)
                            {
                                PlayingBoard[j, i].Controls.Clear();
                                PlayingBoard[j, i].Controls.AddRange(tiles[i - 1]);
                            }
                        }
                    }
                    PlayingBoard[which_colmun, 0].Controls.Clear();
                    PlayingBoard[which_colmun, 0].Controls.AddRange(panel_array);

                    FreeTile.Controls.Clear();

                    tiles.Last().First().Enabled = true;

                    FreeTile.Controls.AddRange(tiles.Last());

                    panel.Controls.Clear();
                }

                //If the free tile was placed in a bottom column control panel
                else
                {
                    for (int i = PlayingBoard.GetLength(0) - 1; i > 0; i--)
                    {
                        for (int j = PlayingBoard.GetLength(1); j > 0; j--)
                        {
                            if (j == which_colmun)
                            {
                                PlayingBoard[j, i - 1].Controls.Clear();
                                PlayingBoard[j, i - 1].Controls.AddRange(tiles[i]);
                            }
                        }
                    }
                    PlayingBoard[which_colmun, PlayingBoard.GetLength(0) - 1].Controls.Clear();
                    PlayingBoard[which_colmun, PlayingBoard.GetLength(0) - 1].Controls.AddRange(panel_array);

                    FreeTile.Controls.Clear();

                    tiles.First().First().Enabled = true;

                    FreeTile.Controls.AddRange(tiles.First());

                    panel.Controls.Clear();
                }
            }
Esempio n. 5
0
            /// <summary>
            /// Places some controls needed for gameplay
            /// </summary>
            /// <param name="control">Which control the object should be added</param>
            public void PlaceGameControls(Control control)
            {
                if (PlayingBoard.GetLength(0) == 7)
                {
                    int y = 10, x = 130;

                    Panel column1_top = new Panel(), column2_top = new Panel(), column3_top = new Panel(), column1_bottom = new Panel(), column2_bottom = new Panel(), column3_bottom = new Panel();
                    ControlPanelsColumns = new Panel[] { column1_top, column2_top, column3_top, column1_bottom, column2_bottom, column3_bottom };

                    for (int i = 0; i < 2; i++)
                    {
                        int j = 0;
                        while (true)
                        {
                            if (i != 0 && j == 0)
                            {
                                j = 3;
                            }
                            ControlPanelsColumns[j].AllowDrop   = true;
                            ControlPanelsColumns[j].Size        = new Size(50, 50);
                            ControlPanelsColumns[j].BorderStyle = BorderStyle.Fixed3D;
                            ControlPanelsColumns[j].Location    = new Point(x, y);
                            ControlPanelsColumns[j].DragEnter  += Board_DragEnter;
                            ControlPanelsColumns[j].DragDrop   += Panel_DragDrop;

                            control.Controls.Add(ControlPanelsColumns[j]);

                            x += 120;
                            j++;

                            if (j % 3 == 0 && (j != 3 || i == 0))
                            {
                                break;
                            }
                        }
                        x  = 130;
                        y += 480;
                    }

                    y = 130; x = 10;

                    Panel row1_left = new Panel(), row2_left = new Panel(), row3_left = new Panel(), row1_right = new Panel(), row2_right = new Panel(), row3_right = new Panel();
                    ControlPanelsRows = new Panel[] { row1_left, row2_left, row3_left, row1_right, row2_right, row3_right };

                    for (int i = 0; i < 2; i++)
                    {
                        int j = 0;
                        while (true)
                        {
                            if (i != 0 && j == 0)
                            {
                                j = 3;
                            }
                            ControlPanelsRows[j].AllowDrop   = true;
                            ControlPanelsRows[j].Size        = new Size(50, 50);
                            ControlPanelsRows[j].BorderStyle = BorderStyle.Fixed3D;
                            ControlPanelsRows[j].Location    = new Point(x, y);
                            ControlPanelsRows[j].DragEnter  += Board_DragEnter;
                            ControlPanelsRows[j].DragDrop   += Panel_DragDrop;

                            control.Controls.Add(ControlPanelsRows[j]);

                            y += 120;
                            j++;

                            if (j % 3 == 0 && (j != 3 || i == 0))
                            {
                                break;
                            }
                        }
                        y  = 130;
                        x += 480;
                    }
                }

                else
                {
                    int y = 10, x = 130;

                    Panel column1_top = new Panel(), column2_top = new Panel(), column3_top = new Panel(), column4_top = new Panel(), column1_bottom = new Panel(), column2_bottom = new Panel(), column3_bottom = new Panel(), column4_bottom = new Panel();
                    ControlPanelsColumns = new Panel[] { column1_top, column2_top, column3_top, column4_top, column1_bottom, column2_bottom, column3_bottom, column4_bottom };

                    for (int i = 0; i < 2; i++)
                    {
                        int j = 0;
                        while (true)
                        {
                            if (i != 0 && j == 0)
                            {
                                j = 4;
                            }
                            ControlPanelsColumns[j].AllowDrop   = true;
                            ControlPanelsColumns[j].Size        = new Size(50, 50);
                            ControlPanelsColumns[j].BorderStyle = BorderStyle.Fixed3D;
                            ControlPanelsColumns[j].Location    = new Point(x, y);
                            ControlPanelsColumns[j].DragEnter  += Board_DragEnter;
                            ControlPanelsColumns[j].DragDrop   += Panel_DragDrop;

                            control.Controls.Add(ControlPanelsColumns[j]);

                            x += 120;
                            j++;

                            if (j % 4 == 0 && (j != 4 || i == 0))
                            {
                                break;
                            }
                        }
                        x  = 130;
                        y += 600;
                    }

                    y = 130; x = 10;

                    Panel row1_left = new Panel(), row2_left = new Panel(), row3_left = new Panel(), row4_left = new Panel(), row1_right = new Panel(), row2_right = new Panel(), row3_right = new Panel(), row4_right = new Panel();
                    ControlPanelsRows = new Panel[] { row1_left, row2_left, row3_left, row4_left, row1_right, row2_right, row3_right, row4_right };

                    for (int i = 0; i < 2; i++)
                    {
                        int j = 0;
                        while (true)
                        {
                            if (i != 0 && j == 0)
                            {
                                j = 4;
                            }
                            ControlPanelsRows[j].AllowDrop   = true;
                            ControlPanelsRows[j].Size        = new Size(50, 50);
                            ControlPanelsRows[j].BorderStyle = BorderStyle.Fixed3D;
                            ControlPanelsRows[j].Location    = new Point(x, y);
                            ControlPanelsRows[j].DragEnter  += Board_DragEnter;
                            ControlPanelsRows[j].DragDrop   += Panel_DragDrop;

                            control.Controls.Add(ControlPanelsRows[j]);

                            y += 120;
                            j++;

                            if (j % 4 == 0 && (j != 4 || i == 0))
                            {
                                break;
                            }
                        }
                        y  = 130;
                        x += 600;
                    }
                }

                Button button = new Button();

                button.Size     = new Size(50, 50);
                button.Location = new Point(1100, 160);
                button.Text     = "OK";
                button.Click   += button_Click;

                control.Controls.Add(button);
            }
Esempio n. 6
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);
                        }
                    }
                }
            }