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); }
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); }