public void NewGame(IGameDefinition definition, string code = null)
        {
            _definition       = definition;
            _remainingGuesses = _definition.AllowedGuesses;

            // Allow the caller to specify the code if they wish
            _code = string.Empty;
            if (!string.IsNullOrEmpty(code))
            {
                if (!_definition.ValidateInputFormat(code, out string message))
                {
                    throw new Exception($"Specified code passed is not consistent with game definition:{message}");
                }
                _code = code;
            }
            else
            {
                // Generate a random code
                for (var digit = 0; digit < _definition.GuessLength; digit++)
                {
                    Random random = new Random();
                    _code += random.Next(_definition.DigitMinVal, _definition.DigitMaxVal).ToString();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Detect the language for the current installation
        /// </summary>
        /// <param name="gameDefinition"></param>
        /// <param name="rootDirectory"></param>
        /// <returns>language as string</returns>
        public static string ReadCurrentLanguage(IGameDefinition gameDefinition, FileSystem fileSystem)
        {
            if (PlatformUtility.IsWindowsPlatform())
            {
                if (gameDefinition.LanguageRegistryKeys != null && gameDefinition.LanguageRegistryKeys.Any())
                {
                    if (ReadFromRegistry(gameDefinition.LanguageRegistryKeys, out var language))
                    {
                        return(language);
                    }
                }
            }

            switch (gameDefinition.Game)
            {
            case SageGame.CncGenerals:
                return(DetectFromFileSystem(fileSystem, "", "Audio", ".big"));

            case SageGame.CncGeneralsZeroHour:
                return(DetectFromFileSystem(fileSystem, "", "Audio", "ZH.big"));

            case SageGame.Bfme:
            case SageGame.Bfme2:
            case SageGame.Bfme2Rotwk:
                return(DetectFromFileSystem(fileSystem, "lang", "", "Audio.big"));

            case SageGame.Ra3Uprising:
            case SageGame.Ra3:
                return(DetectFromFileSystem(fileSystem, "Data", "", "Audio.big"));
            }

            return(DefaultLanguage);
        }
示例#3
0
 public static bool TryGetByName(string name, out IGameDefinition definition)
 {
     // TODO: Use a short identifier defined in IGameDefinition instead of stringified SageGame
     definition = All.FirstOrDefault(def =>
                                     string.Equals(def.Game.ToString(), name, StringComparison.InvariantCultureIgnoreCase));
     return(definition != null);
 }
示例#4
0
        public ConfiguredSubsystemLoader(IGameDefinition gameDefinition, FileSystem fileSystem, IniDataContext iniDataContext)
        {
            _gameDefinition = gameDefinition;
            _iniDataContext = iniDataContext;
            _fileSystem     = fileSystem;

            _iniDataContext.LoadIniFile(@"Data\INI\Default\subsystemlegend.ini");
            _subsystems = _iniDataContext.Subsystems.ToDictionary(subsystem => subsystem.Name);
        }
示例#5
0
        public ConfiguredSubsystemLoader(IGameDefinition gameDefinition, FileSystem fileSystem, Game game, ContentManager contentManager)
        {
            _gameDefinition = gameDefinition;
            _contentManager = contentManager;
            _game           = game;
            _fileSystem     = fileSystem;

            _contentManager.LoadIniFile(@"Data\INI\Default\subsystemlegend.ini");
            _subsystems = game.AssetStore.Subsystems;
        }
示例#6
0
        public static ISubsystemLoader Create(IGameDefinition gameDefinition, FileSystem fileSystem, IniDataContext iniDataContext)
        {
            switch (gameDefinition.Game)
            {
            case SageGame.CncGenerals:
            case SageGame.CncGeneralsZeroHour: return(new GeneralsSubsystemLoader(iniDataContext));

            // TODO: Do all the other games use configured subsystems?
            default: return(new ConfiguredSubsystemLoader(gameDefinition, fileSystem, iniDataContext));
            }
        }
示例#7
0
        public static Game CreateGame(IGameDefinition definition,
                                      IInstallationLocator installationLocator,
                                      Func <GameWindow> createWindow)
        {
            var installation = installationLocator
                               .FindInstallations(definition)
                               .FirstOrDefault();

            if (installation == null)
            {
                throw new Exception($"No installations for {definition.Game} could be found.");
            }

            return(CreateGame(installation, installation.CreateFileSystem(), createWindow));
        }
示例#8
0
        public IEnumerable <GameInstallation> FindInstallations(IGameDefinition game)
        {
            String path = Environment.GetEnvironmentVariable(game.Identifier.ToUpperInvariant() + "_PATH");

            if (path == null)
            {
                return new GameInstallation[] {}
            }
            ;

            var installations = new GameInstallation[] { new GameInstallation(game, path) };

            return(installations);
        }
    }
示例#9
0
        public IEnumerable <GameInstallation> FindInstallations(IGameDefinition game)
        {
            var identifier = game.Identifier.ToUpperInvariant() + "_PATH";
            var path       = Environment.GetEnvironmentVariable(identifier);

            if (path == null)
            {
                path = Environment.GetEnvironmentVariable(identifier, EnvironmentVariableTarget.User);
            }
            if (path == null || !Directory.Exists(path))
            {
                return(new GameInstallation[] {});
            }

            var installations = new GameInstallation[] { new GameInstallation(game, path) };

            return(installations);
        }
示例#10
0
        public static IEnumerable <GameInstallation> FindAllInstallations(IGameDefinition game)
        {
            var locators = GetAllForPlatform();
            var result   = new List <GameInstallation>();

            foreach (var locator in locators)
            {
                var installations = locator.FindInstallations(game);
                foreach (var installation in installations)
                {
                    if (!result.Contains(installation))
                    {
                        result.Add(installation);
                    }
                }
            }
            return(result);
        }
示例#11
0
        public static Game CreateGame(
            IGameDefinition definition,
            GameWindow window)
        {
            var installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();

            if (installation == null)
            {
                throw new Exception($"No installations for {definition.Game} could be found.");
            }

            return(CreateGame(
                       installation,
                       installation.CreateFileSystem(),
                       window));
        }
        public void Initialize()
        {
            var testSessionPlayerFactory = Mock.Of<ISessionPlayerFactory>();
            var moveProcessor = Mock.Of<IMoveProcessor<TestMoveObject, TestResponseObject>>();
            var sessionPlayerSetup = Mock.Of<ISessionPlayerSetup>();
            var gameInviteDecorator = Mock.Of<IGameInviteDecorator>();
            var moveFactory = Mock.Of<IMoveFactory<TestMoveObject>>();
            var moveResultNotificationFactory = Mock.Of<IMoveResultNotificationFactory>();
            var playerHistoryItemFactory = Mock.Of<IPlayerHistoryItemFactory<TestMoveObject, TestResponseObject>>();
            var gameDefinitionMock = new Mock<GameDefinition<TestMoveObject, TestResponseObject>>();

            gameDefinitionMock
                .Setup(d => d.GetSessionPlayerFactory())
                .Returns(testSessionPlayerFactory)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetMoveProcessor())
                .Returns(moveProcessor)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetSessionPlayerSetup())
                .Returns(sessionPlayerSetup)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetGameInviteDecorator())
                .Returns(gameInviteDecorator)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetMoveFactory())
                .Returns(moveFactory)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetMoveResultNotificationFactory())
                .Returns(moveResultNotificationFactory)
                .Verifiable();
            gameDefinitionMock
                .Setup(d => d.GetPlayerHistoryItemfactory())
                .Returns(playerHistoryItemFactory)
                .Verifiable();

            this.gameDefinition = gameDefinitionMock.Object;
        }
示例#13
0
        public static ISubsystemLoader Create(IGameDefinition gameDefinition, FileSystem fileSystem, IniDataContext iniDataContext)
        {
            switch (gameDefinition.Game)
            {
            case SageGame.CncGenerals:
            case SageGame.CncGeneralsZeroHour:
                return(new GeneralsSubsystemLoader(iniDataContext));

            case SageGame.Bfme:
            case SageGame.Bfme2:
            case SageGame.Bfme2Rotwk:
            case SageGame.Cnc3:
            case SageGame.Cnc3KanesWrath:
                return(new ConfiguredSubsystemLoader(gameDefinition, fileSystem, iniDataContext));

            default:
                // TODO: Implement subsystem loader for new XML-based format used in RA3 and beyond.
                return(null);
            }
        }
示例#14
0
        /// <summary>
        /// Detect the language for the current installation
        /// </summary>
        /// <param name="gameDefinition"></param>
        /// <param name="rootDirectory"></param>
        /// <returns>language as string</returns>
        public static string ReadCurrentLanguage(IGameDefinition gameDefinition, string rootDirectory)
        {
            if (PlatformUtility.IsWindowsPlatform())
            {
                if (gameDefinition.LanguageRegistryKeys != null && gameDefinition.LanguageRegistryKeys.Any())
                {
                    return(ReadFromRegistry(gameDefinition.LanguageRegistryKeys));
                }
            }

            switch (gameDefinition.Game)
            {
            case SageGame.CncGenerals:
                return(DetectFromFileSystem(rootDirectory, "Audio", ".big"));

            case SageGame.CncGeneralsZeroHour:
                return(DetectFromFileSystem(rootDirectory, "Audio", "ZH.big"));
            }

            return(DefaultLanguage);
        }
示例#15
0
        public SubsystemLoader(IGameDefinition gameDefinition, FileSystem fileSystem, Game game, ContentManager contentManager)
        {
            _gameDefinition = gameDefinition;
            _contentManager = contentManager;
            _fileSystem     = fileSystem;

            switch (gameDefinition.Game)
            {
            case SageGame.CncGenerals:
            case SageGame.CncGeneralsZeroHour:
                // These games didn't use subsystemlegend.ini so we use our own retro-fitted one.
                _contentManager.LoadIniFile(new FileSystemEntry(fileSystem, "subsystemlegend.ini", 0, () => new MemoryStream(Encoding.ASCII.GetBytes(GeneralsSubsystemLegendIni))));
                break;

            default:
                _contentManager.LoadIniFile(@"Data\INI\Default\subsystemlegend.ini");
                break;
            }


            _subsystems = game.AssetStore.Subsystems;
        }
示例#16
0
        public IEnumerable <GameInstallation> FindInstallations(IGameDefinition game)
        {
            GameInstallation baseGameInstallation = null;

            if (game.BaseGame != null)
            {
                // TODO: Allow selecting one of these?
                baseGameInstallation = FindInstallations(game.BaseGame).FirstOrDefault();

                if (baseGameInstallation == null)
                {
                    logger.Warn("No game installations found");
                    return(Enumerable.Empty <GameInstallation>());
                }
            }

            var paths = game.RegistryKeys.Select(RegistryUtility.GetRegistryValue);

            var installations = GetValidPaths(paths)
                                .Select(p => new GameInstallation(game, p, baseGameInstallation))
                                .ToList();

            return(installations);
        }
示例#17
0
 public GameInstallation(IGameDefinition game, string path, GameInstallation baseGame = null)
 {
     Game = game;
     Path = path;
     _baseGameInstallation = baseGame;
 }
 public GameDefinitionBuildInfo(IGameDefinition gameDefinition, string directory)
 {
     this.gameDefinition = gameDefinition;
     this.directory      = directory;
 }