Пример #1
0
        /// <summary>
        /// Constructor for tiles not using a picture
        /// </summary>
        /// <param name="height">The height of the button</param>
        /// <param name="width">The width of the button</param>
        /// <param name="top">The tile's distance from the top of the form</param>
        /// <param name="left">The tile's distance from the left side of the form</param>
        /// <param name="text">The text to be displayed in the tile</param>
        /// <param name="row">The tile's row in the grid</param>
        /// <param name="col">The tile's column in the grid</param>
        /// <param name="game">The game form</param>
        public Tile(int height,
            int width,
            int top,
            int left,
            string text,
            int row,
            int col,
            FifteenPuzzle game)
        {
            this.Height = height;
            this.Width = width;
            this.Top = top;
            this.Left = left;
            this.Text = text;
            this.Click += Tile_Click;

            this.row = row;
            this.col = col;
            this.game = game;
        }
Пример #2
0
        /// <summary>
        /// Constructor for tiles using a picture
        /// </summary>
        /// <param name="height">The height of the button</param>
        /// <param name="width">The width of the button</param>
        /// <param name="top">The tile's distance from the top of the form</param>
        /// <param name="left">The tile's distance from the left side of the form</param>
        /// <param name="text">The text to be displayed in the tile</param>
        /// <param name="row">The tile's row in the grid</param>
        /// <param name="col">The tile's column in the grid</param>
        /// <param name="usePicture">Whether or not to use a picture</param>
        /// <param name="game">The game form</param>
        public Tile(int height,
            int width,
            int top,
            int left,
            string text,
            int row,
            int col,
            bool usePicture,
            FifteenPuzzle game)
        {
            this.Height = height;
            this.Width = width;
            this.Top = top;
            this.Left = left;
            this.Text = text;
            this.ForeColor = Color.Transparent;
            this.Click += Tile_Click;

            Bitmap b = new Bitmap(Properties.Resources.flowers,new Size(width *game.Num_rows, width * game.Num_columns));

            //get correct row and column based on square's number
            int x = (int.Parse(text) - 1) % game.Num_columns * width;
            int y = (int.Parse(text) -1) / game.Num_columns * height;

            //crop button's image to correct portion of original image
            Rectangle r = new Rectangle(x, y, width, height);
            Bitmap b1 = b.Clone(r, b.PixelFormat);
            this.Image = b1;

            this.row = row;
            this.col = col;
            this.game = game;

            //format tile's appearance
            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderSize = 0;
        }