Ejemplo n.º 1
0
        public void TestStatsAfterFireWeapon()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[0], ship, enemyShip);

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);

            Assert.AreEqual(100, enemyShip.Rooms[0].CurrentDurability);
            Assert.AreEqual(100, enemyShip.SpecialRooms[0].CurrentDurability);
            Assert.AreEqual(200, enemyShip.Stats.CurrentHP);
            Assert.AreEqual(100, enemyShip.Crew[0].CurrentHP);
            Assert.AreEqual(100, enemyShip.Crew[1].CurrentHP);
            Assert.AreEqual(2000, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 1000);
            Assert.AreEqual(100, enemyShip.Rooms[0].CurrentDurability);
            Assert.AreEqual(100, enemyShip.SpecialRooms[0].CurrentDurability);
            Assert.AreEqual(200, enemyShip.Stats.CurrentHP);
            Assert.AreEqual(100, enemyShip.Crew[0].CurrentHP);
            Assert.AreEqual(100, enemyShip.Crew[1].CurrentHP);
            Assert.AreEqual(1000, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 1000);
            Assert.AreEqual(90, enemyShip.Rooms[0].CurrentDurability);
            Assert.AreEqual(90, enemyShip.SpecialRooms[0].CurrentDurability);
            Assert.AreEqual(190, enemyShip.Stats.CurrentHP);
            Assert.AreEqual(90, enemyShip.Crew[0].CurrentHP);
            Assert.AreEqual(90, enemyShip.Crew[1].CurrentHP);
            Assert.AreEqual(2000, ship.Weapons[0].TimeLeftToCoolDown);
        }
Ejemplo n.º 2
0
        public void TestTargetWeaponNotToEnemy()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Neutral);

            Assert.IsTrue(ship.Weapons.All(c => c.Target == null));

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[0], ship, enemyShip);
            Assert.AreEqual(null, ship.Weapons[0].Target);
        }
Ejemplo n.º 3
0
        public void TestRetargetWeapon()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);

            Assert.IsTrue(ship.Weapons.All(c => c.Target == null));

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[0], ship, enemyShip);
            Assert.AreEqual(enemyShip.Rooms[0], ship.Weapons[0].Target);

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[1], ship, enemyShip);
            Assert.AreEqual(enemyShip.Rooms[1], ship.Weapons[0].Target);
        }
Ejemplo n.º 4
0
        public void TestSaveTargetAfterConnectAndDisconectWeapon()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);

            Assert.IsTrue(ship.Weapons.All(c => c.Target == null));
            Assert.IsTrue(ship.Weapons.All(c => c.IsOnline == false));

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[0], ship, enemyShip);
            Assert.AreEqual(enemyShip.Rooms[0], ship.Weapons[0].Target);
            Assert.AreEqual(false, ship.Weapons[0].IsOnline);

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);
            Assert.AreEqual(enemyShip.Rooms[0], ship.Weapons[0].Target);
            Assert.AreEqual(true, ship.Weapons[0].IsOnline);

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);
            Assert.AreEqual(enemyShip.Rooms[0], ship.Weapons[0].Target);
            Assert.AreEqual(false, ship.Weapons[0].IsOnline);
        }
Ejemplo n.º 5
0
        public void TestFireWithAllCoolDownWeapon()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);

            PlayerCommands.TargetWeapon(ship.Weapons[0], enemyShip.Rooms[0], ship, enemyShip);
            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);

            Assert.AreEqual(2000, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 500);
            Assert.AreEqual(1500, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 500);
            Assert.AreEqual(1000, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 500);
            Assert.AreEqual(500, ship.Weapons[0].TimeLeftToCoolDown);

            WeaponsHandler.Tick(ship, enemyShip, 500);
            Assert.AreEqual(2000, ship.Weapons[0].TimeLeftToCoolDown);
        }
Ejemplo n.º 6
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);
        }