Exemplo n.º 1
0
        public TableLayoutPanel GenerateFightScreen()
        {
            //
            //gameModel.OtherShip = new Titan(Alignment.Enemy);
            //
            var t = new TableLayoutPanel {
                Dock = DockStyle.Fill, Margin = new Padding(0, 0, 0, 0)
            };
            var screen = new Panel {
                Dock = DockStyle.Fill, Margin = new Padding(0, 0, 0, 0)
            };

            screen.BackgroundImage = new Bitmap("images/BattleBackground.jpg");
            screen.Click          += (s, e) =>
            {
                if (Selected is WeaponControl)
                {
                    ((WeaponControl)Selected).Weapon.Target = null;
                }
                DropSelection();
            };
            t.Controls.Add(screen);

            var weaponPanel = new WeaponPanel(gameModel.PlayerShip)
            {
                Left = 3, Top = 507
            };

            screen.Controls.Add(weaponPanel);

            foreach (var weaponReload in GetAll(weaponPanel, typeof(WeaponReload)))
            {
                GameTick.OnTick += gm => weaponReload.Invalidate();
            }

            var systemsPanel = new SystemsPanel(gameModel.PlayerShip)
            {
                Left = 152, Top = 507
            };

            screen.Controls.Add(systemsPanel);

            var crewPanel = new CrewPanel(gameModel.PlayerShip.Crew)
            {
                Left = 460, Top = 507
            };

            screen.Controls.Add(crewPanel);

            var resourcePanel = new ResourcePanel(gameModel)
            {
                Left = 3, Top = 38, Size = new Size(150, 100)
            };

            screen.Controls.Add(resourcePanel);

            var playerShip = new ShipControl(gameModel.PlayerShip)
            {
                Width = 540, Height = 216, Top = 200, Left = 30
            };

            screen.Controls.Add(playerShip);

            //
            foreach (var w in playerShip.Ship.Weapons)
            {
                w.IsOnline = true;
            }
            //

            foreach (var cell in GetAll(playerShip, typeof(CellControl)))
            {
                cell.Click += (s, e) =>
                {
                    if (Selected is Human)
                    {
                        var h = (Human)Selected;
                        var c = (CellControl)cell;
                        PlayerCommands.MoveCrewMember(h.crewMember, c.cell, playerShip.Ship);
                        DropSelection();
                    }
                };
            }

            var playerHpBar = new HPBar(gameModel.PlayerShip)
            {
                Left = 3, Top = 3, Width = 626, Height = 30
            };

            screen.Controls.Add(playerHpBar);
            GameTick.OnTick += gm => playerHpBar.Invalidate();

            foreach (var human in crewPanel.Humans)
            {
                var humanOnBoard = new HumanOnBoard(human, playerShip);
                screen.Controls.Add(humanOnBoard);
            }

            if (gameModel.OtherShip != null)
            {
                var otherShip = new ShipControl(gameModel.OtherShip, true)
                {
                    Width = 540, Height = 216,
                    Top   = 200, Left = 694
                };
                screen.Controls.Add(otherShip);

                var enemyHPBar = new HPBar(gameModel.OtherShip)
                {
                    Width = 626, Top = 3, Height = 30, Left = 634
                };
                screen.Controls.Add(enemyHPBar);
                GameTick.OnTick += gm => enemyHPBar.Invalidate();

                foreach (var cell in GetAll(otherShip, typeof(CellControl)))
                {
                    cell.Click += (s, e) =>
                    {
                        if (Selected is WeaponControl)
                        {
                            var w    = ((WeaponControl)Selected).Weapon;
                            var c    = ((CellControl)cell).cell;
                            var room = otherShip.Ship.Rooms.First(r => r.Cells.Contains(c));
                            PlayerCommands.TargetWeapon(w, room, playerShip.Ship, otherShip.Ship);
                            DropSelection();
                        }
                    };
                }

                foreach (var human in otherShip.Ship.Crew.Select(cm => new Human(cm)))
                {
                    var humanOnBoard = new HumanOnBoard(human, otherShip);
                    humanOnBoard.Click += (s, e) =>
                    {
                        if (Selected is WeaponControl)
                        {
                            var w    = ((WeaponControl)Selected).Weapon;
                            var c    = human.crewMember.Cell;
                            var room = otherShip.Ship.Rooms.First(r => r.Cells.Contains(c));
                            PlayerCommands.TargetWeapon(w, room, playerShip.Ship, otherShip.Ship);
                            DropSelection();
                        }
                    };
                    screen.Controls.Add(humanOnBoard);
                }

                foreach (var weapon in gameModel.OtherShip.Weapons)
                {
                    weapon.IsOnline = true;
                    weapon.Target   = gameModel.PlayerShip.Rooms[random.Next(0, gameModel.PlayerShip.Rooms.Count)];
                }
            }

            var mapButton = new Button()
            {
                Top = 38, Left = 1101, Height = 50, Width = 160, Text = "На карту"
            };

            mapButton.Click += (s, e) =>
            {
                if (gameModel.OtherShip.Stats.CurrentHP > 0)
                {
                    PlayerCommands.MoveOnMap(gameModel, gameModel.Map.LastNode);
                }
                resourcePanel.Invalidate();
                TransitionTo(Screen.Map);
            };
            mapButton.Font = new Font("Segoe UI", 14F, FontStyle.Regular,
                                      GraphicsUnit.Point, ((byte)(204)));
            screen.Controls.Add(mapButton);

            GameTick.OnWin += () =>
            {
                resourcePanel.Invalidate();
                MessageBox.Show(
                    String.Format("Победа! \n +{1} Денег, +{0} Топлива", GameTick.LastFuelReward, GameTick.LastMoneyReward),
                    "", MessageBoxButtons.OK);

                gameModel.Map.CurrentNode.Alignment = Alignment.Player;
                foreach (var mapPoint in GetAll(this, typeof(MapPoint)))
                {
                    mapPoint.Invalidate();
                }
                TransitionTo(Screen.Peace);
                //Sp.Stop();
                //Sp = new SoundPlayer("music/peaceTheme.wav");
                //Sp.Play();
            };

            GameTick.OnLose += () =>
            {
                MessageBox.Show(
                    String.Format("Корабль уничтожен! Вы проиграли!"),
                    "", MessageBoxButtons.OK);
                TransitionTo(Screen.Menu);
            };

            foreach (var control in GetAll(screen, typeof(Human)))
            {
                control.Click += (s, e) =>
                {
                    var selectable = (ISelectable)control;
                    DropSelection();
                    selectable.IsSelected = true;
                    Selected = selectable;
                    selectable.Invalidate();
                }
            }
            ;
            foreach (var control in GetAll(screen, typeof(HumanOnBoard)))
            {
                var Human = ((HumanOnBoard)control).Human;
                if (Human.crewMember.Alignment != Alignment.Player)
                {
                    continue;
                }
                control.Click += (s, e) =>
                {
                    DropSelection();
                    Human.IsSelected = true;
                    Selected         = Human;
                    Human.Invalidate();
                };
            }
            foreach (var control in GetAll(screen, typeof(WeaponControl)))
            {
                control.Click += (s, e) =>
                {
                    var selectable = (ISelectable)control;
                    DropSelection();
                    selectable.IsSelected = true;
                    Selected = selectable;
                    selectable.Invalidate();
                }
            }
            ;

            return(t);
        }
Exemplo n.º 2
0
        public TableLayoutPanel GeneratePeaceScreen()
        {
            var t = new TableLayoutPanel {
                Dock = DockStyle.Fill, Margin = new Padding(0, 0, 0, 0)
            };
            var screen = new Panel {
                Dock = DockStyle.Fill, Margin = new Padding(0, 0, 0, 0)
            };

            screen.BackgroundImage = new Bitmap("images/BattleBackground.jpg");
            screen.Click          += (s, e) =>
            {
                if (Selected is WeaponControl)
                {
                    ((WeaponControl)Selected).Weapon.Target = null;
                }
                DropSelection();
            };
            t.Controls.Add(screen);

            var weaponPanel = new WeaponPanel(gameModel.PlayerShip)
            {
                Left = 3, Top = 507
            };

            screen.Controls.Add(weaponPanel);

            foreach (var weaponReload in GetAll(weaponPanel, typeof(WeaponReload)))
            {
                GameTick.OnTick += gm => weaponReload.Invalidate();
            }

            var systemsPanel = new SystemsPanel(gameModel.PlayerShip)
            {
                Left = 152, Top = 507
            };

            screen.Controls.Add(systemsPanel);

            var crewPanel = new CrewPanel(gameModel.PlayerShip.Crew)
            {
                Left = 460, Top = 507
            };

            screen.Controls.Add(crewPanel);

            var resourcePanel = new ResourcePanel(gameModel)
            {
                Left = 3, Top = 38, Size = new Size(150, 100)
            };

            screen.Controls.Add(resourcePanel);

            var playerShip = new ShipControl(gameModel.PlayerShip)
            {
                Width = 540, Height = 216, Top = 200, Left = 30
            };

            screen.Controls.Add(playerShip);

            //
            foreach (var w in playerShip.Ship.Weapons)
            {
                w.IsOnline = true;
            }
            //

            foreach (var cell in GetAll(playerShip, typeof(CellControl)))
            {
                cell.Click += (s, e) =>
                {
                    if (Selected is Human)
                    {
                        var h = (Human)Selected;
                        var c = (CellControl)cell;
                        PlayerCommands.MoveCrewMember(h.crewMember, c.cell, playerShip.Ship);
                        DropSelection();
                    }
                };
            }

            var playerHpBar = new HPBar(gameModel.PlayerShip)
            {
                Left = 3, Top = 3, Width = 626, Height = 30
            };

            screen.Controls.Add(playerHpBar);
            GameTick.OnTick += gm => playerHpBar.Invalidate();

            foreach (var human in crewPanel.Humans)
            {
                var humanOnBoard = new HumanOnBoard(human, playerShip);
                screen.Controls.Add(humanOnBoard);
            }

            ////////
            var brShip = new Panel()
            {
                Width  = 592,
                Height = 237,
                Top    = 185,
                Left   = 672
            };

            brShip.BackgroundImage = new Bitmap("images/BrokenTitan.png");
            brShip.BackColor       = Color.Transparent;
            screen.Controls.Add(brShip);
            //var otherShip = new ShipControl(gameModel.OtherShip, true) { Width = 540, Height = 216,
            // Top = 200, Left = 694 };

            var mapButton = new Button()
            {
                Top = 38, Left = 1101, Height = 50, Width = 160, Text = "На карту"
            };

            mapButton.Click += (s, e) =>
            {
                resourcePanel.Invalidate();
                TransitionTo(Screen.Map);
            };
            mapButton.Font = new Font("Segoe UI", 14F, FontStyle.Regular,
                                      GraphicsUnit.Point, ((byte)(204)));
            screen.Controls.Add(mapButton);

            foreach (var control in GetAll(screen, typeof(Human)))
            {
                control.Click += (s, e) =>
                {
                    var selectable = (ISelectable)control;
                    DropSelection();
                    selectable.IsSelected = true;
                    Selected = selectable;
                    selectable.Invalidate();
                }
            }
            ;

            foreach (var control in GetAll(screen, typeof(HumanOnBoard)))
            {
                var Human = ((HumanOnBoard)control).Human;
                if (Human.crewMember.Alignment != Alignment.Player)
                {
                    continue;
                }
                control.Click += (s, e) =>
                {
                    DropSelection();
                    Human.IsSelected = true;
                    Selected         = Human;
                    Human.Invalidate();
                };
            }
            foreach (var control in GetAll(screen, typeof(WeaponControl)))
            {
                control.Click += (s, e) =>
                {
                    var selectable = (ISelectable)control;
                    DropSelection();
                    selectable.IsSelected = true;
                    Selected = selectable;
                    selectable.Invalidate();
                }
            }
            ;

            return(t);
        }
Exemplo n.º 3
0
        public TableLayoutPanel GenerateMapScreen()
        {
            var mainMapGrid = new TableLayoutPanel();

            mainMapGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 87));
            mainMapGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 13));
            mainMapGrid.RowStyles.Add(new RowStyle(SizeType.Absolute, 35));
            mainMapGrid.RowStyles.Add(new RowStyle(SizeType.Absolute, 55));
            mainMapGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            mainMapGrid.Dock                  = DockStyle.Fill;
            mainMapGrid.BackgroundImage       = new Bitmap("images/MapBackground.png");
            mainMapGrid.BackgroundImageLayout = ImageLayout.Stretch;

            var backButton = new Button()
            {
                Height = 50, Width = 200
            };

            backButton.Text = "Назад";
            backButton.Font = new Font("Segoe UI", 12F, FontStyle.Regular,
                                       GraphicsUnit.Point, ((byte)(204)));
            //backButton.Dock = DockStyle.Fill;
            backButton.Click += (e, a) => this.TransitionTo(Screen.Fight);
            mainMapGrid.Controls.Add(backButton, 1, 1);

            var menuButton = new Button()
            {
                Height = 30, Width = 200
            };

            menuButton.Text = "В меню";
            menuButton.Font = new Font("Segoe UI", 12F, FontStyle.Regular,
                                       GraphicsUnit.Point, ((byte)(204)));
            //backButton.Dock = DockStyle.Fill;
            menuButton.Click += (e, a) => this.TransitionTo(Screen.Menu);
            mainMapGrid.Controls.Add(menuButton, 1, 0);

            var hpBar = new HPBar(gameModel.PlayerShip)
            {
                Width = 1150, Height = 30
            };

            mainMapGrid.Controls.Add(hpBar, 0, 0);

            var playGrid = new TableLayoutPanel();

            playGrid.Dock        = DockStyle.Fill;
            playGrid.ColumnCount = 1;
            playGrid.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            playGrid.RowCount = 2;
            playGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            playGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            playGrid.BackColor = Color.Transparent;
            mainMapGrid.Controls.Add(playGrid, 1, 2);

            var resorsePanel = new ResourcePanel(gameModel);

            playGrid.Controls.Add(resorsePanel, 0, 0);
            resorsePanel.BackColor = Color.White;

            var otherGrid = new TableLayoutPanel();

            otherGrid.Dock        = DockStyle.Fill;
            otherGrid.ColumnCount = 1;
            playGrid.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            //otherGrid.RowCount = 2;
            otherGrid.RowStyles.Add(new RowStyle(SizeType.Absolute, 40));
            otherGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            otherGrid.BackColor = Color.Transparent;
            mainMapGrid.Controls.Add(otherGrid, 0, 2);

            var label = new Label();

            label.Text      = "Карта уровня";
            label.Dock      = DockStyle.Fill;
            label.Height    = 35;
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.BackColor = Color.Transparent;
            label.ForeColor = Color.White;
            label.Font      = new Font("Segoe UI", 20, FontStyle.Bold,
                                       GraphicsUnit.Point, ((byte)(204)));
            otherGrid.Controls.Add(label, 0, 0);

            var mapPanel = new MapControl(gameModel);

            mapPanel.Dock = DockStyle.Fill;
            otherGrid.Controls.Add(mapPanel, 0, 1);

            foreach (var control in GetAll(mainMapGrid, typeof(MapPoint)))
            {
                var mp = (MapPoint)control;
                mp.Click += (s, e) =>
                {
                    if (mp.PointNode.Neighbors.Contains(gameModel.Map.CurrentNode))
                    {
                        if (gameModel.Fuel > 0)
                        {
                            var cnd = gameModel.Map.CurrentNode;
                            PlayerCommands.MoveOnMap(gameModel, mp.PointNode);
                            //mapPanel.Invalidate();
                            foreach (var node in mapPanel.MapNodes)
                            {
                                node.Invalidate();
                            }
                            if (gameModel.Map.CurrentNode != cnd && gameModel.Map.CurrentNode.Alignment == Alignment.Enemy)
                            {
                                TransitionTo(Screen.Fight);
                            }
                            if (gameModel.Map.CurrentNode != cnd && gameModel.Map.CurrentNode.Alignment == Alignment.Player)
                            {
                                TransitionTo(Screen.Peace);
                            }
                            resorsePanel.Invalidate();
                        }
                        else
                        {
                            MessageBox.Show(
                                String.Format("Топливо закончилось! Игра окончена!"), "", MessageBoxButtons.OK);
                            TransitionTo(Screen.Menu);
                        }
                    }
                };
            }

            return(mainMapGrid);
        }