Esempio n. 1
0
        private GridButton GridButtonStyler(GridButton btn)
        {
            int x = btn.X;
            int y = btn.Y;

            buttons[x, y].Text = "";
            if (model.getBoard()[x, y] == FieldType.NO_WALL)
            {
                buttons[x, y].BackgroundImage = noWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.WALL)
            {
                buttons[x, y].BackgroundImage = WallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.CANNOT_WALL)
            {
                buttons[x, y].BackgroundImage = cannotWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.MAGNET)
            {
                Image imageBackground = noWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(magnetTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            if (model.getRobotPos().Equals(new Position(x, y)))
            {
                Image imageBackground = (model.getFieldTypeOnRobot() == FieldType.NO_WALL) ? noWallTexture : cannotWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(robotTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            btn.BackgroundImageLayout = ImageLayout.Stretch;

            return(btn);
        }
Esempio n. 2
0
        public void drawBoard(object obj, EventArgs e)
        {
            if (buttons != null)
            {
                foreach (Button button in buttons)
                {
                    boardGrid.Controls.Remove(button);
                }
            }
            buttons = new GridButton[model.getSize(), model.getSize()];

            boardGrid.RowCount    = model.getSize();;
            boardGrid.ColumnCount = model.getSize();
            for (int i = 0; i < model.getSize(); i++)
            {
                for (int j = 0; j < model.getSize(); j++)
                {
                    buttons[i, j]      = new GridButton(i, j);
                    buttons[i, j].Text = model.getBoard()[i, j].ToString();
                    GridButtonStyler(buttons[i, j]);

                    buttons[i, j].Dock     = DockStyle.Fill;
                    buttons[i, j].AutoSize = true;
                    boardGrid.Controls.Add(buttons[i, j], i, j);

                    buttons[i, j].Click += gridButtonClicked;
                }
            }
            boardGrid.RowStyles.Clear();
            boardGrid.ColumnStyles.Clear();
            for (int i = 0; i < model.getSize(); i++)
            {
                boardGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 1 / 15f));
            }
            for (int i = 0; i < model.getSize(); i++)
            {
                boardGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1 / 15f));
            }
            boardGrid.Dock = DockStyle.Fill;
        }