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 TestRepairMovingCrewMemberRoom()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            ship.Rooms[0].CurrentDurability = 10;

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(12, ship.Rooms[0].CurrentDurability);
            Assert.AreEqual(12, ship.SpecialRooms[0].CurrentDurability);

            PlayerCommands.MoveCrewMember(ship.Crew[0], ship.Cells[5], ship);
            Assert.AreEqual(12, ship.Rooms[0].CurrentDurability);
            Assert.AreEqual(12, ship.SpecialRooms[0].CurrentDurability);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(13, ship.Rooms[0].CurrentDurability);
            Assert.AreEqual(13, ship.SpecialRooms[0].CurrentDurability);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(14, ship.Rooms[0].CurrentDurability);
            Assert.AreEqual(14, ship.SpecialRooms[0].CurrentDurability);
        }
Ejemplo n.º 3
0
        public void TestTwoMovingCrewMembersToOneCell()
        {
            var ship = new TestShip(Alignment.Player);

            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[4], ship.Cells[2], ship);
            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[2], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[10], ship.Crew[4].Cell);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[11], ship.Crew[4].Cell);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[3], ship.Crew[4].Cell);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[4].Cell);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[4].Cell);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);
        }
Ejemplo n.º 4
0
        public void TestCorrectFullConnectWeapon()
        {
            var ship = new TestShip(Alignment.Player);

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

            PlayerCommands.TryChangeWeaponState(ship.Weapons[1], ship);
            Assert.AreEqual(true, ship.Weapons[1].IsOnline);
        }
Ejemplo n.º 5
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.º 6
0
        public void TestMoveTwoToSmbCell()
        {
            var ship = new TestShip(Alignment.Player);

            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[0], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[3], ship.Crew[2].Cell);
        }
Ejemplo n.º 7
0
        public void TestMove()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[2], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[2].Cell);
        }
Ejemplo n.º 8
0
        public void TestTooBigWeaponConnect()
        {
            var ship = new TestShip(Alignment.Player);

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

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);
            PlayerCommands.TryChangeWeaponState(ship.Weapons[1], ship);
            PlayerCommands.TryChangeWeaponState(ship.Weapons[2], ship);
            Assert.AreEqual(false, ship.Weapons[2].IsOnline);
        }
Ejemplo n.º 9
0
        public void TestFireWithNoTargetOnlineWeaponOwerflowCooldown()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);

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

            WeaponsHandler.Tick(ship, enemyShip, 3000);
            Assert.AreEqual(100, enemyShip.Rooms[0].CurrentDurability);
            Assert.AreEqual(100, enemyShip.SpecialRooms[0].CurrentDurability);
            Assert.AreEqual(200, enemyShip.Stats.CurrentHP);
            Assert.AreEqual(-1000, ship.Weapons[0].TimeLeftToCoolDown);
        }
Ejemplo n.º 10
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.º 11
0
        public void TestRoomStatesAfterMovingFromNotWorkingRoom()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            Assert.AreEqual(0, ship.SpecialRooms[1].Stat.EmptyWorkingSpaces);

            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[11], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(0, ship.SpecialRooms[1].Stat.EmptyWorkingSpaces);
        }
Ejemplo n.º 12
0
        public void TestSetNegativeEnergy()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);
            var gameModel = new GameModel(ship, "Player-Empty-100,100");

            gameModel.OtherShip = enemyShip;
            GameTick.Tick(gameModel);

            Assert.AreEqual(5, gameModel.PlayerShip.Stats.CurrentEnergy);

            PlayerCommands.TrySetRoomEnergyConsumption(gameModel.PlayerShip.SpecialRooms[0], -1, gameModel.PlayerShip);
            Assert.AreEqual(5, gameModel.PlayerShip.Stats.CurrentEnergy);
        }
Ejemplo n.º 13
0
        public void TestMoveToNotFight()
        {
            var ship = new TestShip(Alignment.Player);
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"maps\mapExample.txt");
            var map  = Map.LoadFromFile(path);

            var gameModel = new GameModel(ship, map);

            Assert.AreEqual(gameModel.Map.Nodes[0], gameModel.Map.CurrentNode);

            PlayerCommands.MoveOnMap(gameModel, gameModel.Map.Nodes[2]);
            Assert.AreEqual(gameModel.Map.Nodes[2], gameModel.Map.CurrentNode);
            Assert.IsTrue(gameModel.OtherShip is null);
        }
Ejemplo n.º 14
0
        public void TestUpgradeWhenNoMoney()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);
            var gameModel = new GameModel(ship, "Player-Empty-100,100");

            gameModel.OtherShip = enemyShip;
            GameTick.Tick(gameModel);

            Assert.AreEqual(2, gameModel.PlayerShip.SpecialRooms[0].Stat.CurrentEnergyLimit);

            PlayerCommands.UpgradeRoom(gameModel.PlayerShip.SpecialRooms[0], gameModel);
            Assert.AreEqual(2, gameModel.PlayerShip.SpecialRooms[0].Stat.CurrentEnergyLimit);
            Assert.AreEqual(0, gameModel.Money);
        }
Ejemplo n.º 15
0
        public void TestHealingOutOfLivingRoom()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.TrySetRoomEnergyConsumption(ship.SpecialRooms[2], 2, ship);
            SpecialRoomBonusCalculator.Recalculate(ship);
            foreach (var crew in ship.Crew)
            {
                crew.CurrentHP = 10;
            }
            CrewActionsHandler.TickCrew(ship);
            Assert.IsTrue(ship.Crew.All(c => c.CurrentHP == 10));
        }
Ejemplo n.º 16
0
        public void TestCrewActionsAfterMovingToNotFullWorkingRoom()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[11], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(CrewAction.Moving, ship.Crew[2].Action);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(CrewAction.Idle, ship.Crew[2].Action);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(CrewAction.Working, ship.Crew[2].Action);
        }
Ejemplo n.º 17
0
        public void TestCrewStatesAfterMoving()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[2], ship.Cells[2], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[2].Cell);
            Assert.AreEqual(CrewAction.Moving, ship.Crew[2].Action);
            Assert.AreEqual(ship.Cells[2], ship.Crew[2].Destination);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[2].Cell);
            Assert.AreEqual(null, ship.Crew[2].Destination);
        }
Ejemplo n.º 18
0
        public void TestOverHealCrewMember()
        {
            var ship = new TestShip(Alignment.Player);

            Assert.IsTrue(ship.Crew.All(c => c.Action == CrewAction.Idle));
            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[1], ship.Cells[5], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[5], ship.Crew[1].Cell);

            PlayerCommands.TrySetRoomEnergyConsumption(ship.SpecialRooms[2], 2, ship);
            SpecialRoomBonusCalculator.Recalculate(ship);
            ship.Crew[1].CurrentHP = 99;
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(100, ship.Crew[1].CurrentHP);
        }
Ejemplo n.º 19
0
        public void TestCorrectMove()
        {
            //var p = Path.GetFullPath(@"maps\mapExample.txt");
            //var s = new TestShip(Alignment.Player);
            //var m = Map.LoadFromFile(@"maps\mapExample.txt");
            ////bad test
            var ship = new TestShip(Alignment.Player);
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"maps\mapExample.txt");
            var map  = Map.LoadFromFile(path);

            var gameModel = new GameModel(ship, map);

            Assert.AreEqual(gameModel.Map.Nodes[0], gameModel.Map.CurrentNode);

            PlayerCommands.MoveOnMap(gameModel, gameModel.Map.Nodes[1]);
            Assert.AreEqual(gameModel.Map.Nodes[1], gameModel.Map.CurrentNode);
        }
Ejemplo n.º 20
0
        public void TestSetEnergyAfterUpgrade()
        {
            var ship      = new TestShip(Alignment.Player);
            var enemyShip = new TestShip(Alignment.Enemy);
            var gameModel = new GameModel(ship, "Player-Empty-100,100");

            gameModel.OtherShip = enemyShip;
            gameModel.Money     = 1000;
            GameTick.Tick(gameModel);

            Assert.AreEqual(2, gameModel.PlayerShip.SpecialRooms[0].Stat.CurrentEnergyLimit);

            PlayerCommands.UpgradeRoom(gameModel.PlayerShip.SpecialRooms[0], gameModel);
            Assert.AreEqual(3, gameModel.PlayerShip.SpecialRooms[0].Stat.CurrentEnergyLimit);

            PlayerCommands.TrySetRoomEnergyConsumption(gameModel.PlayerShip.SpecialRooms[0], 3, gameModel.PlayerShip);
            Assert.AreEqual(3, gameModel.PlayerShip.SpecialRooms[0].Stat.CurrentEnergyLimit);
        }
Ejemplo n.º 21
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.º 22
0
        public void TestConnectAndUnconnectTwoWeapons()
        {
            var ship = new TestShip(Alignment.Player);

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

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);
            Assert.AreEqual(true, ship.Weapons[0].IsOnline);
            Assert.AreEqual(false, ship.Weapons[3].IsOnline);

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

            PlayerCommands.TryChangeWeaponState(ship.Weapons[0], ship);
            Assert.AreEqual(false, ship.Weapons[0].IsOnline);
            Assert.AreEqual(true, ship.Weapons[3].IsOnline);

            PlayerCommands.TryChangeWeaponState(ship.Weapons[3], ship);
            Assert.IsTrue(ship.Weapons.All(c => c.IsOnline == false));
        }
Ejemplo n.º 23
0
        public static void ControlIsRecalculated()
        {
            var ship = new TestTitan(Alignment.Player);

            PlayerCommands.TrySetRoomEnergyConsumption(ship.SpecialRooms[1], 1, ship);

            Assert.AreEqual(1.0, ship.Stats.DamageMultiplier, 0.001);
            Assert.AreEqual(4, ship.Stats.CurrentEnergy);
            Assert.AreEqual(0, ship.Stats.Evasion);
            Assert.AreEqual(5, ship.Stats.FullEnergy);
            Assert.AreEqual(0, ship.Stats.Heal);
            Assert.AreEqual(0, ship.Stats.Radar);

            SpecialRoomBonusCalculator.Recalculate(ship);
            Assert.AreEqual(4, ship.Stats.CurrentEnergy);
            Assert.AreEqual(1.0, ship.Stats.DamageMultiplier, 0.001);
            Assert.AreEqual(5, ship.Stats.Evasion);
            Assert.AreEqual(5, ship.Stats.FullEnergy);
            Assert.AreEqual(0, ship.Stats.Heal);
            Assert.AreEqual(0, ship.Stats.Radar);
        }
Ejemplo n.º 24
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.º 25
0
        public void TestWayToDistination()
        {
            var ship = new TestShip(Alignment.Player);

            CrewActionsHandler.TickCrew(ship);

            PlayerCommands.MoveCrewMember(ship.Crew[4], ship.Cells[2], ship);
            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[10], ship.Crew[4].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[11], ship.Crew[4].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[3], ship.Crew[4].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[4].Cell);

            CrewActionsHandler.TickCrew(ship);
            Assert.AreEqual(ship.Cells[2], ship.Crew[4].Cell);
        }
Ejemplo n.º 26
0
        public static void GeneratorIsRecalculated()
        {
            var ship = new TestTitan(Alignment.Player);

            ship.SpecialRooms[3].Stat.CurrentEnergyLimit = 4;
            SpecialRoomBonusCalculator.Recalculate(ship);
            for (var i = 0; i < ship.SpecialRooms.Count; i++)
            {
                if (ship.SpecialRooms[i].Type != RoomType.Generator)
                {
                    PlayerCommands.TrySetRoomEnergyConsumption(ship.SpecialRooms[i], 2, ship);
                }
            }
            PlayerCommands.TrySetRoomEnergyConsumption(ship.SpecialRooms[2], 1, ship);
            SpecialRoomBonusCalculator.Recalculate(ship);
            var energy = 0;

            foreach (var room in ship.SpecialRooms.Where(room => room.Type != RoomType.Generator))
            {
                energy += room.Stat.CurrentEnergy;
            }
            Assert.AreEqual(ship.Stats.FullEnergy - ship.Stats.CurrentEnergy, energy);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
        public EnergyBar(SpecialRoom room, Ship ship)
        {
            InitializeComponent();
            this.ship = ship;
            if (!allBars.ContainsKey(room))
            {
                allBars[room] = new List <EnergyBar>();
            }
            allBars[room].Add(this);
            Max      = room.Stat.MaxEnergyLimit;
            Unlocked = room.Stat.CurrentEnergyLimit;
            Active   = room.Stat.CurrentEnergy;
            if (room.Type == RoomType.Generator)
            {
                Active = ship.Stats.FullEnergy - ship.Stats.CurrentEnergy;
            }
            this.room = room;
            var t = new TableLayoutPanel();

            table = t;
            //this.BackColor = Color.Transparent;
            t.ColumnCount = Max;
            for (int i = 0; i < Max; i++)
            {
                t.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)(1.0 / Max + 0.1)));
            }
            t.RowCount = 1;
            t.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            t.Dock = DockStyle.Fill;
            //this.Padding = new Padding(0, 0, 0, 0);
            //t.BackColor = Color.Transparent;
            //t.BackColor = Color.Black;
            for (int i = 0; i < Max; i++)
            {
                var cell = new EnergyCell();
                var j    = i + 1;
                cell.Click += (s, e) =>
                {
                    if (cells[j - 1].state == 2 && ((j < Max && cells[j].state != 2) || (j == Max)))
                    {
                        PlayerCommands.TrySetRoomEnergyConsumption(room, j - 1, ship);
                    }
                    else
                    {
                        PlayerCommands.TrySetRoomEnergyConsumption(room, j, ship);
                    }
                    foreach (var bar in ship.SpecialRooms.SelectMany(r => allBars[r]))
                    {
                        bar.Invalidate();
                    }
                };
                cell.Dock    = DockStyle.Fill;
                cell.Margin  = new Padding(0, 0, 0, 0);
                cell.Padding = new Padding(0, 0, 0, 0);
                cells.Add(cell);
                t.Controls.Add(cell, i, 0);
            }
            t.Margin     = new Padding(0, 0, 0, 0);
            t.Padding    = new Padding(0, 0, 0, 0);
            this.Padding = new Padding(0, 0, 0, 0);
            this.Margin  = new Padding(0, 0, 0, 0);
            Controls.Add(t);
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
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);
        }