public override void Ended(GameRuleConfiguration _)
    {
        _deadCheckTimer = null;
        _restartTimer   = null;

        _playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
    }
示例#2
0
        public static TankMovementResolver Resolve(ref bool[,] isAWall, Unit[] tanks,
                                                   Bullet[] bullets = null, GameRuleConfiguration ruleConfig = null)
        {
            if (ruleConfig == null)
            {
                ruleConfig = new GameRuleConfiguration();
            }
            TankMovementResolver resolver = new TankMovementResolver(isAWall, tanks, bullets, ruleConfig);

            resolver.ResolveMoves();
            return(resolver);
        }
示例#3
0
    private void OnGameRuleAdded(GameRuleAddedEvent ev)
    {
        if (ev.Rule.Configuration.Id != Prototype)
        {
            return;
        }

        Configuration = ev.Rule.Configuration;
        RuleAdded     = true;

        Added();
    }
示例#4
0
        public static void DisplayBoardResolveAndCheckExpectations(string imageFileName, ref bool[,] isAWall, MoveStatus[] expectedMoveStatuses,
                                                                   Unit[] tanks, Bullet[] bullets = null, Base[] bases = null, GameRuleConfiguration ruleConfig = null, string imageFolderPath = null)
        {
            ImageGenerator imgGen = new ImageGenerator
            {
                Magnification         = 5,
                IsBackgroundChequered = false
            };

            try
            {
                string indentation = new string(' ', isAWall.GetLength(1) / 2 - 2);
                System.Console.WriteLine("{0}BOARD BEFORE:", indentation);
                System.Console.WriteLine();

                DisplayBoard(ref isAWall, tanks, bullets);
                if (!String.IsNullOrEmpty(imageFolderPath))
                {
                    string imagePath  = Path.Combine(imageFolderPath, String.Format("{0}_BEFORE.bmp", imageFileName));
                    Bitmap boardImage = imgGen.GenerateBoardImage(ref isAWall, ref tanks, ref bullets, ref bases);
                    boardImage.Save(imagePath, ImageFormat.Bmp);
                }

                if (PromptToRunTest())
                {
                    TankMovementResolver resolver = Resolve(ref isAWall, tanks, bullets, ruleConfig);
                    ReportDeviationsFromExpectedResults(resolver, expectedMoveStatuses);
                    ReportResolutionDuration(resolver);

                    System.Console.WriteLine();
                    System.Console.WriteLine("{0}BOARD AFTER:", indentation);
                    System.Console.WriteLine();

                    resolver.ApplyMoves();
                    DisplayBoard(ref isAWall, tanks, bullets, foregroundColor: ConsoleColor.Yellow);

                    if (!String.IsNullOrEmpty(imageFolderPath))
                    {
                        string imagePath  = Path.Combine(imageFolderPath, String.Format("{0}_AFTER.bmp", imageFileName));
                        Bitmap boardImage = imgGen.GenerateBoardImage(ref isAWall, ref tanks, ref bullets, ref bases);
                        boardImage.Save(imagePath, ImageFormat.Bmp);
                    }

                    PromptToRunNextTest();
                }
            }
            catch (Exception exc)
            {
                ConsoleColor oldFGColor = System.Console.ForegroundColor;
                System.Console.ForegroundColor = ConsoleColor.Red;
                try
                {
                    // TODO: We should write to the error stream instead.
                    System.Console.WriteLine("An error occurred while running the tests: ");
                    System.Console.WriteLine(exc);
                }
                finally
                {
                    System.Console.ForegroundColor = oldFGColor;
                }
            }
        }
    public override void Started(GameRuleConfiguration _)
    {
        _chatManager.DispatchServerAnnouncement(Loc.GetString("rule-death-match-added-announcement"));

        _playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
    }
示例#6
0
 /// <summary>
 ///     Called when the game rule has ended..
 /// </summary>
 public abstract void Ended(GameRuleConfiguration configuration);
示例#7
0
        private static void TestTwoTanksInCorridorBetweenOtherTwoTanksWithOptionalBulletAndRule(string imageFileName,
                                                                                                string testTitle, bool includeBullet, bool canATankMoveIntoTheSpaceLeftByATankThatJustMovedIntoABullet = true)
        {
            TestHelper.DisplayTestTitle(testTitle);

            bool[,] isAWall = new bool[25, 25];
            Unit[] tanks = new Unit[Constants.TANK_COUNT];

            Unit leftUnit = new Unit
            {
                X         = 5,
                Y         = 6,
                Direction = Direction.RIGHT,
                Action    = Core.Action.RIGHT
            };
            Unit topUnit = new Unit
            {
                X         = 10,
                Y         = 10,
                Direction = Direction.DOWN,
                Action    = Core.Action.DOWN
            };
            Unit rightUnit = new Unit
            {
                X         = 15,
                Y         = 15,
                Direction = Direction.LEFT,
                Action    = Core.Action.LEFT
            };
            Unit bottomUnit = new Unit
            {
                X         = 10,
                Y         = 18,
                Direction = Direction.UP,
                Action    = Core.Action.UP
            };

            tanks[0] = leftUnit;
            tanks[1] = topUnit;
            tanks[2] = rightUnit;
            tanks[3] = bottomUnit;

            MoveStatus[] expectedStatuses = { MoveStatus.Approved, MoveStatus.Approved, MoveStatus.Cancelled, MoveStatus.Approved };

            Bullet[] bullets = new Bullet[Constants.TANK_COUNT];
            if (includeBullet)
            {
                expectedStatuses[3] = MoveStatus.Destroyed;

                Bullet bullet = new Bullet
                {
                    X         = 10,
                    Y         = 15,
                    Direction = Direction.LEFT
                };
                bullets[2] = bullet;

                if (canATankMoveIntoTheSpaceLeftByATankThatJustMovedIntoABullet)
                {
                    expectedStatuses[1] = MoveStatus.Cancelled;  // tank 2 is now conflicting with 1 not 3, but that causes 1's move to be cancelled
                    expectedStatuses[0] = MoveStatus.Cancelled;
                }
                // Otherwise there is no difference to tank 2, because it is being blocked by the destruction of tank 3, not by its presence
            }
            GameRuleConfiguration ruleConfig = new GameRuleConfiguration
            {
                CanATankMoveIntoTheSpaceLeftByATankThatJustMovedIntoABullet = canATankMoveIntoTheSpaceLeftByATankThatJustMovedIntoABullet
            };

            TestHelper.DisplayBoardResolveAndCheckExpectations(imageFileName, ref isAWall, expectedStatuses, tanks, bullets, bases: null,
                                                               ruleConfig: ruleConfig, imageFolderPath: ImageFolderPath);
        }
示例#8
0
 /// <summary>
 ///     Called when the game rule has been started..
 /// </summary>
 public abstract void Started(GameRuleConfiguration configuration);
 public override void Ended(GameRuleConfiguration _)
 {
     // noop
     // Preset should already handle it.
     return;
 }
 public override void Started(GameRuleConfiguration _)
 {
     PickRule();
 }
 public override void Ended(GameRuleConfiguration _)
 {
     _sandbox.IsSandboxEnabled = false;
 }
 public override void Started(GameRuleConfiguration _)
 {
     _sandbox.IsSandboxEnabled = true;
 }