Esempio n. 1
0
        private void GameSceneClick(object s, GameSceneZoneEventArgs e)
        {
            if (e.Button == MouseButtons.Left)                        // Левый клик
            {
                if (ButtonsSelector.IsSelected())                     // Выбрано здание
                {
                    if (_game.IsCellFree(e.HoverCellX, e.HoverCellY)) // есть здание
                    {
                        _game.Build(e.HoverCellX, e.HoverCellY, ButtonsSelector.ButtonName);
                        ButtonsSelector.Deselect();
                    }
                    else
                    {
                        MessageBox.Show("Здесь нельзя строить");
                    }
                }
                else // Наводим пустой курсор
                {
                    if (_game.IsCellFree(e.HoverCellX, e.HoverCellY) == false) // есть здание
                    {
                        CellSelector.Select(e.HoverCellX, e.HoverCellY);
                    }
                    else
                    {
                        CellSelector.Deselect();
                    }
                }
            }

            if (e.Button == MouseButtons.Right) // Правый клик
            {
                CellSelector.Deselect();
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void DrawPanel()
        {
            // Draw background
            MainForm.G.FillRectangle(new SolidBrush(MainForm.BackgroundColor), _x, _y, Width, Height);

            Font       font      = new Font("Arial", 16);
            SolidBrush fontBrush = new SolidBrush(Color.White);

            //String header = "Информация:";
            //MainForm.G.DrawString(header, font, fontBrush, _x + 10, _y + 10);


            if (CellSelector.IsCellSelected())
            {
                int selectedX        = CellSelector.X;
                int selectedY        = CellSelector.Y;
                var selectedBuilding = _game.Buildings[selectedX, selectedY];

                // Draw building name
                String header = selectedBuilding.Name;
                MainForm.G.DrawString(header, font, fontBrush, _x + 10, _y + 10);

                // Draw building (X, Y)
                String position = "X: " + selectedBuilding.X + ", Y: " + selectedBuilding.Y;
                MainForm.G.DrawString(position, font, fontBrush, _x + 155, _y + 50);


                // Draw building
                const int windowX    = _x + 16;
                const int windowY    = _y + 50;
                const int windowSize = 130;
                int       posX       = (CellPainter.CellSize * selectedX) - 31;
                int       posY       = (CellPainter.CellSize * selectedY) - 31;
                MainForm.G.DrawImage(MainForm.Btm, windowX, windowY, new Rectangle(posX, posY, windowSize, windowSize), GraphicsUnit.Pixel);

                // Draw building window
                var pen = new Pen(new SolidBrush(Color.White), 2);
                MainForm.G.DrawRectangle(pen, new Rectangle(windowX, windowY, windowSize, windowSize));
            }



            // Draw ping info
            //var text = "раз раз";
            //MainForm.G.DrawString(text, font, fontBrush, _x + 170, _y + 40);
            //_tickNumber++;
            //var distance = (_tickNumber % 100) * 2 + _tickNumber % 2;
            //MainForm.G.FillRectangle(new SolidBrush(Color.Yellow), _x + 170 + distance, _y + 40, 30, 30);
        }
Esempio n. 4
0
        public LineTensioner(MainForm form, Game game, GameSceneZone gameSceneZone)
        {
            _game           = game;
            _gameSceneZone  = gameSceneZone;
            form.MouseDown += Form_MouseDown;
            form.MouseUp   += Form_MouseUp;

            Connected += (fromX, fromY, toX, toY) =>
            {
                CellSelector.Deselect();
                if (gameSceneZone.IsMouseHover())
                {
                    var position = gameSceneZone.GetHoverCellCoordinate();
                    game.Connect(fromX, fromY, toX, toY);
                }
            };
        }
Esempio n. 5
0
        private void Form_MouseUp(object sender, MouseEventArgs e)
        {
            if (_gameSceneZone.IsMouseHover() && e.Button == MouseButtons.Left)
            {
                var position = _gameSceneZone.GetHoverCellCoordinate();
                var x        = position.Item1;
                var y        = position.Item2;

                if (X != x || Y != y)
                {
                    CellSelector.Deselect();
                }

                if (_game.IsCellFree(X, Y) == false && _game.IsCellFree(x, y) == false && (X != x || Y != y))
                {
                    Connect(X, Y, x, y);
                }
                else
                {
                    Deselect();
                }
            }
        }
Esempio n. 6
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);
                    }
                }
            }
        }