コード例 #1
0
ファイル: FormMain.cs プロジェクト: Krauser123/MazeLiberator
        /// <summary>
        /// Handle the 4 types of tile (Empty, Wall, Initial and Final)
        /// </summary>
        /// <param name="btnClicked"></param>
        private void ChangebuttonState(TileButton btnClicked)
        {
            //If empty can set as Wall
            if (btnClicked.IsEmptyTitle())
            {
                //Set as wall
                btnClicked.BackgroundImage = TileBlock;
                btnClicked.SetAsWallTitle();
            }
            else if (btnClicked.IsWallTile && btnInitial == null)
            {
                //Check if exist a previous Initial Tile
                if (btnInitial != null)
                {
                    btnInitial.BackgroundImage = null;
                    btnInitial.SetAsEmptyTitle();
                }

                //Set as Initial Tile
                btnClicked.BackgroundImage = InitialTile;
                btnClicked.SetAsInitialTitle();
                btnInitial = btnClicked;
            }
            else if (btnClicked.IsInitialTile)
            {
                btnClicked.SetAsEmptyTitle();
                btnInitial = null;
            }
            else if (btnClicked.IsFinalTile)
            {
                btnClicked.SetAsEmptyTitle();
                btnFinal = null;
            }
            else if (btnClicked.IsWallTile && btnFinal == null)
            {
                //Check if exist a previous Final Tile
                if (btnFinal != null)
                {
                    btnFinal.BackgroundImage = null;
                    btnFinal.SetAsEmptyTitle();
                }

                btnClicked.BackgroundImage = EndTile;
                btnClicked.SetAsFinalTitle();
                btnFinal = btnClicked;
            }
            else
            {
                btnClicked.SetAsEmptyTitle();
            }
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: Krauser123/MazeLiberator
        /// <summary>
        /// Generate initial and final tiles
        /// </summary>
        private void GenerateInitialAndFinalButton()
        {
            //Generate initial button
            int initialButtonIndex = randomize.Next(0, TotalNumOfButtons);

            btnInitial = (TileButton)mainPanel.Controls[initialButtonIndex];
            btnInitial.BackgroundImage = InitialTile;
            btnInitial.SetAsInitialTitle();

            //Generate final button
            int finalButtonIndex;

            do
            {
                finalButtonIndex = randomize.Next(0, TotalNumOfButtons);
            }
            // We need check that we don't use the same button and also that we have a minimun difference
            while (finalButtonIndex == initialButtonIndex || Math.Abs(initialButtonIndex - finalButtonIndex) < 45);

            btnFinal = (TileButton)mainPanel.Controls[finalButtonIndex];
            btnFinal.BackgroundImage = EndTile;
            btnFinal.SetAsFinalTitle();
        }