Пример #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);
        }
Пример #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);
        }
Пример #3
0
        public TableLayoutPanel GenerateStartScreen()
        {
            var startScreen = new Panel();

            startScreen.Dock                  = DockStyle.Fill;
            startScreen.BackgroundImage       = new Bitmap("images/StartBackground.jpg");
            startScreen.BackgroundImageLayout = ImageLayout.Stretch;
            startScreen.Margin                = new Padding(0, 0, 0, 0);
            startScreen.Click                += (s, e) => DropSelection();

            var backButton = new Button();

            backButton.Text = "Назад";
            backButton.Font = new Font("Segoe UI", 14F, FontStyle.Regular,
                                       GraphicsUnit.Point, ((byte)(204)));
            backButton.Left   = 1059;
            backButton.Height = 50;
            backButton.Width  = 200;
            backButton.Top    = 5;
            backButton.Click += (e, a) => this.TransitionTo(Screen.Menu);
            startScreen.Controls.Add(backButton);

            var mapButton = new Button();

            mapButton.Text = "Старт";
            mapButton.Font = new Font("Segoe UI", 14F, FontStyle.Regular,
                                      GraphicsUnit.Point, ((byte)(204)));
            mapButton.Left   = 1059;
            mapButton.Top    = 60;
            mapButton.Height = 50;
            mapButton.Width  = 200;
            mapButton.Click += (e, a) => this.TransitionTo(Screen.Map);
            startScreen.Controls.Add(mapButton);

            var crewPanel = new CrewPanel(gameModel.PlayerShip.Crew);

            crewPanel.Top  = 5;
            crewPanel.Left = 5;
            startScreen.Controls.Add(crewPanel);

            var systemPanel = new SystemsPanel(gameModel.PlayerShip);

            systemPanel.Left = 230;
            systemPanel.Top  = 5;
            startScreen.Controls.Add(systemPanel);

            var shipControl = new ShipControl(gameModel.PlayerShip, false);

            shipControl.Left = 150;
            shipControl.Top  = 350;
            shipControl.Size = new Size(750, 300);
            startScreen.Controls.Add(shipControl);

            var weaponPanel = new WeaponPanel(gameModel.PlayerShip);

            weaponPanel.Top  = 5;
            weaponPanel.Left = 544;
            startScreen.Controls.Add(weaponPanel);

            var resourcePanel = new ResourcePanel(gameModel);

            resourcePanel.Left = 781;
            resourcePanel.Top  = 5;
            resourcePanel.Size = new Size(150, 100);
            startScreen.Controls.Add(resourcePanel);

            var ans = new TableLayoutPanel();

            ans.RowCount    = 1;
            ans.ColumnCount = 1;
            ans.Dock        = DockStyle.Fill;
            ans.Controls.Add(startScreen);
            ans.Margin = new Padding(0, 0, 0, 0);
            return(ans);
        }