Example #1
0
        private Button ButtonsInitialization(Timer timer, String capture, int x, int y)
        {
            const int buttonSize     = 100;
            Building  buttonBuilding = new Building(capture);
            const int buildingIndent = (buttonSize - CellPainter.CellSize) / 2 + 2;

            Button.Draw drawNormal = (buttonX, buttonY, width, height) =>
            {
                var color = CellPainter.NormalCellColor;
                MainForm.G.FillRectangle(new SolidBrush(color), buttonX - 1, buttonY - 1, width + 2, height + 2);
                BuildingPainter.Draw(buttonBuilding, buttonX + buildingIndent, buttonY + buildingIndent);
            };

            Button.Draw drawHover = (buttonX, buttonY, width, height) =>
            {
                var color = CellPainter.HoverCellColor;
                MainForm.G.FillRectangle(new SolidBrush(color), buttonX, buttonY, width, height);
                BuildingPainter.Draw(buttonBuilding, buttonX + buildingIndent, buttonY + buildingIndent);
            };

            Button.Draw drawActive = (buttonX, buttonY, width, height) =>
            {
                var color = CellPainter.GreenColor;
                MainForm.G.FillRectangle(new SolidBrush(color), buttonX, buttonY, width, height);
                BuildingPainter.Draw(buttonBuilding, buttonX + buildingIndent, buttonY + buildingIndent);
            };

            var button = new Button(_mainForm, timer, X + x, Y + y, buttonSize, buttonSize, drawNormal, drawHover, drawActive);


            button.Click += (s, e) =>
            {
                CellSelector.Deselect();
                ButtonsSelector.Select(capture);
            };

            _mainForm.MouseClick += (s, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    ButtonsSelector.Deselect();
                }
            };

            ButtonsSelector.Deselected += () =>
            {
                button.Deactivate();
            };

            ButtonsSelector.Selected += (buttonName) =>
            {
                if (capture != buttonName)
                {
                    button.Deactivate();
                }
            };

            return(button);
        }
Example #2
0
        private void DrawScene()
        {
            // Draw background
            MainForm.G.FillRectangle(new SolidBrush(MainForm.BackgroundColor), X, Y, GameScene.Width, GameScene.Height);

            // Draw normal cells
            for (int y = 0; y < Game.SceneHeight; y++)
            {
                for (int x = 0; x < Game.SceneWidth; x++)
                {
                    CellPainter.DrawOnGrid(CellPainter.NormalCellColor, x, y);
                }
            }

            // Draw hover cell
            if (_gameSceneZone.IsMouseHover())
            {
                var coordinates = _gameSceneZone.GetHoverCellCoordinate();
                int hoverCellX  = coordinates.Item1;
                int hoverCellY  = coordinates.Item2;

                if (_game.IsCellFree(hoverCellX, hoverCellY) == false && ButtonsSelector.IsSelected() == false)
                {
                    CellPainter.DrawOnGrid(CellPainter.HoverCellColor, hoverCellX, hoverCellY);
                }

                if (ButtonsSelector.IsSelected())
                {
                    if (_game.IsCellFree(hoverCellX, hoverCellY))
                    {
                        CellPainter.DrawOnGrid(CellPainter.GreenColor, hoverCellX, hoverCellY);
                        BuildingPainter.DrawOnGrid(new Building(ButtonsSelector.ButtonName), hoverCellX, hoverCellY);
                    }
                    else
                    {
                        CellPainter.DrawOnGrid(CellPainter.RedColor, hoverCellX, hoverCellY);
                    }
                }
            }

            // Draw selected cell
            if (CellSelector.IsCellSelected())
            {
                CellPainter.DrawOnGrid(CellPainter.SelectedCellColor, CellSelector.X, CellSelector.Y);
            }

            // Draw tensioning line
            if (_gameSceneZone.IsMouseHover() && _lineTensioner.IsSelected())
            {
                var position = _gameSceneZone.GetHoverCellCoordinate();
                var x        = position.Item1;
                var y        = position.Item2;

                if (_game.IsCellFree(_lineTensioner.X, _lineTensioner.Y) == false && (x != _lineTensioner.X || y != _lineTensioner.Y))
                {
                    CellPainter.DrawOnGrid(CellPainter.GreenColor, _lineTensioner.X, _lineTensioner.Y);
                    CellPainter.DrawOnGrid(CellPainter.GreenColor, x, y);
                    LinePainter.DrawOnGrid(_lineTensioner.X, _lineTensioner.Y, x, y);
                }
            }

            // Draw Lines
            foreach (var line in _game.Lines)
            {
                LinePainter.DrawOnGrid(line.Begin.X, line.Begin.Y, line.End.X, line.End.Y);
            }


            // Draw buildings
            for (int y = 0; y < Game.SceneHeight; y++)
            {
                for (int x = 0; x < Game.SceneWidth; x++)
                {
                    if (_game.Buildings[x, y] != null)
                    {
                        BuildingPainter.DrawOnGrid(_game.Buildings[x, y], x, y);
                    }
                }
            }
        }