private static ChickenUnitLogicExecutor CreateLogicExecutor(
            GameEngine engine,
            ChickenTeamSettings teamSettings,
            GameTeam team)
        {
            #region Argument Check

            if (engine == null)
            {
                throw new ArgumentNullException("engine");
            }

            if (teamSettings == null)
            {
                throw new ArgumentNullException("teamSettings");
            }

            #endregion

            var logic = (ChickenUnitLogic)Activator.CreateInstance(teamSettings.Type).EnsureNotNull();

            var result = new ChickenUnitLogicExecutor(
                engine,
                teamSettings.UnitCount,
                team,
                engine._makeMoveEvent,
                logic);

            return(result);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="GameWindow"/> class
        ///     using the specified parameters.
        /// </summary>
        public GameWindow(
            Size nominalSize,
            ChickenTeamSettings lightTeam,
            ChickenTeamSettings darkTeam,
            PositionMode positionMode)
            : this()
        {
            Action <GamePositionEventArgs> positionCallback;

            switch (positionMode)
            {
            case PositionMode.Random:
                positionCallback = UnitPositioningHelper.PositionRandomly;
                break;

            case PositionMode.LineFight:
                positionCallback = UnitPositioningHelper.PositionForLineFight;
                break;

            default:
                throw positionMode.CreateEnumValueNotImplementedException();
            }

            var settings = new GameEngineSettings(nominalSize, lightTeam, darkTeam, this.PaintGame)
            {
                PositionCallback = positionCallback
            };

            _gameEngine            = new GameEngine(settings);
            _gameEngine.GameEnded += this.GameEngine_GameEnded;

            this.Title = string.Format(
                "{0} [{1}x{2}] [L: {3}x {4}  -vs-  D: {5}x {6}]",
                this.Title,
                nominalSize.Width,
                nominalSize.Height,
                lightTeam.UnitCount,
                lightTeam.Type.Name,
                darkTeam.UnitCount,
                darkTeam.Type.Name);
        }
Example #3
0
        private void DoPlay()
        {
            try
            {
                var lightTeam = this.CurrentGameSettings.LightTeam;
                var darkTeam  = this.CurrentGameSettings.DarkTeam;

                var validationMessage = this.CurrentGameSettings.Validate();
                if (!validationMessage.IsNullOrEmpty())
                {
                    this.ShowErrorMessage(validationMessage);
                    return;
                }

                var lightTeamRecord = new ChickenTeamSettings(lightTeam.Logic.Type, lightTeam.PlayerCount);
                var darkTeamRecord  = new ChickenTeamSettings(darkTeam.Logic.Type, darkTeam.PlayerCount);

                var gameWindow = new GameWindow(
                    this.CurrentGameSettings.NominalSize.ToSize(),
                    lightTeamRecord,
                    darkTeamRecord,
                    this.CurrentGameSettings.PositionMode)
                {
                    Owner = this
                };

                gameWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                if (ex.IsFatal())
                {
                    throw;
                }

                this.ShowErrorMessage(ex);
            }
        }