예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceLoader"/> class.
        /// </summary>
        /// <param name="gameContainer">Game container.</param>
        /// <param name="gameId">Game id.</param>
        /// <param name="platform">Game platform.</param>
        /// <param name="version">Interpreter version.</param>
        public ResourceLoader(IGameContainer gameContainer, string gameId, Platform platform, InterpreterVersion version)
        {
            if (gameContainer == null)
            {
                throw new ArgumentNullException(nameof(gameContainer));
            }

            if (gameId == null)
            {
                throw new ArgumentNullException(nameof(gameId));
            }

            if (!IsGameFolder(gameContainer))
            {
                throw new GameNotFoundException();
            }

            this.gameContainer   = gameContainer;
            this.platform        = platform;
            this.version         = version;
            this.inventoryPadded = platform == Platform.Amiga;
            if (this.IsVersion2())
            {
                this.volumeDecoder   = new VolumeDecoderV2();
                this.gameCompression = false;
            }
            else if (this.IsVersion3())
            {
                this.volumeDecoder   = new VolumeDecoderV3(gameId, platform);
                this.gameCompression = true;
            }

            this.resourceMap = this.volumeDecoder.LoadResourceMap(gameContainer);
        }
예제 #2
0
        /// <summary>
        /// Extract the resource from the volume.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <param name="fileName">Volume file name.</param>
        /// <param name="dirEntry">Resource map entry for the resource to extract.</param>
        /// <param name="wasCompressed">Resource was compressed in the volume, so it was decompressed.</param>
        /// <returns>Binary data for the resource.  This is always uncompressed.  If the data is compressed in the volume, the volume decoder must decompress it.</returns>
        byte[] IVolumeDecoder.ExtractResource(IGameContainer container, string fileName, VolumeResourceMapEntry dirEntry, out bool wasCompressed)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (fileName.Length == 0)
            {
                throw new ArgumentException(Errors.FilePathEmpty, nameof(fileName));
            }

            if (dirEntry == null)
            {
                throw new ArgumentNullException(nameof(dirEntry));
            }

            byte[] volumeData = container.Read(fileName);

            if (dirEntry.Offset >= volumeData.Length)
            {
                throw new VolumeDecoderInvalidResourceOffsetException();
            }

            return(VolumeDecoderV3.ExtractResource(volumeData, dirEntry.Offset, out wasCompressed));
        }
 public LudoController(IGameContainer game, IStatsContainter stats)
 {
     _game        = game;
     _activeGames = game.Gamesloader();
     _stats       = stats;
     _gameStats   = stats.StatsLoader();
 }
예제 #4
0
 /// <summary>
 /// This is method is invoked with GameManagers container property is first invoked to setup the bare essential uFrame necessities.
 /// </summary>
 /// <param name="manager">The game manager instance.</param>
 /// <param name="container"></param>
 public static void Configure(GameManager manager, IGameContainer container)
 {
     // The view resolver is the class that will find a view-prefab from a view-model
     container.RegisterInstance <IViewResolver>(new ViewResolver());
     // The game manager is the default command dispatcher
     container.RegisterInstance <ICommandDispatcher>(manager);
 }
예제 #5
0
        /// <summary>
        /// Load the resource map located in the specified folder.
        /// </summary>
        /// <param name="container">Game container where the resource map file(s) are located.</param>
        /// <returns>Resource map.</returns>
        VolumeResourceMap IVolumeDecoder.LoadResourceMap(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            return(VolumeDecoderV3.ReadResourceMap(container.Read(this.GetResourceMapFile())));
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameStartInfo"/> class.
 /// </summary>
 /// <param name="container">Game container.</param>
 /// <param name="id">Game id (may be empty for a version 2 game).</param>
 /// <param name="platform">Platform.</param>
 /// <param name="interpreter">Interpreter version.</param>
 /// <param name="name">Game name.</param>
 /// <param name="version">Game version.</param>
 public GameStartInfo(IGameContainer container, string id, Platform platform, InterpreterVersion interpreter, string name, string version)
 {
     this.GameContainer = container;
     this.Id            = id;
     this.Platform      = platform;
     this.Interpreter   = interpreter;
     this.Name          = name;
     this.Version       = version;
 }
    /// <summary>
    /// This is method is invoked with GameManagers container property is first invoked to setup the bare essential uFrame necessities.
    /// </summary>
    /// <param name="manager">The game manager instance.</param>
    /// <param name="container"></param>
    public static void Configure(GameManager manager, IGameContainer container)
    {
        // The view resolver is the class that will find a view-prefab from a view-model
        container.RegisterInstance<IViewResolver>(new ViewResolver());
        // The game manager is the default command dispatcher
        container.RegisterInstance<ICommandDispatcher>(manager);


    }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenManager"/> class.
        /// </summary>
        /// <param name="game">The <see cref="IGameContainer"/>.</param>
        /// <param name="skinManager">The <see cref="ISkinManager"/> used to manage all the general skinning
        /// between all screens.</param>
        /// <param name="defaultFontName">The asset name of the default font.</param>
        /// <param name="defaultFontSize">The size of the default font.</param>
        /// <exception cref="ArgumentNullException"><paramref name="game"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="skinManager"/> is null.</exception>
        public ScreenManager(IGameContainer game, ISkinManager skinManager, string defaultFontName, int defaultFontSize)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }
            if (skinManager == null)
            {
                throw new ArgumentNullException("skinManager");
            }

            _game = game;

            _game.RenderWindowChanged -= _game_RenderWindowChanged;
            _game.RenderWindowChanged += _game_RenderWindowChanged;

            _skinManager = skinManager;

            _content        = ContentManager.Create();
            _drawingManager = new DrawingManager(_game.RenderWindow);

            _audioManager = Audio.AudioManager.GetInstance(_content);

            // Add event listeners to the input-related events
            _game.KeyPressed -= _game_KeyPressed;
            _game.KeyPressed += _game_KeyPressed;

            _game.KeyReleased -= _game_KeyReleased;
            _game.KeyReleased += _game_KeyReleased;

            _game.TextEntered -= _game_TextEntered;
            _game.TextEntered += _game_TextEntered;

            _game.MouseButtonPressed -= _game_MouseButtonPressed;
            _game.MouseButtonPressed += _game_MouseButtonPressed;

            _game.MouseButtonReleased -= _game_MouseButtonReleased;
            _game.MouseButtonReleased += _game_MouseButtonReleased;

            _game.MouseMoved -= _game_MouseMoved;
            _game.MouseMoved += _game_MouseMoved;

            _game.GainedFocus -= _game_GainedFocus;
            _game.GainedFocus += _game_GainedFocus;

            _game.LostFocus -= _game_LostFocus;
            _game.LostFocus += _game_LostFocus;

            // Load the global content used between screens
            _defaultFont = _content.LoadFont(defaultFontName, defaultFontSize, ContentLevel.Global);

            // Tell the other screens to load their content, too
            foreach (var screen in _screens.Values)
            {
                screen.LoadContent();
            }
        }
예제 #9
0
        /// <summary>
        /// Get the game id by looking for a volume 0 file in the specified game container.
        /// </summary>
        /// <param name="gameContainer">Game container.</param>
        /// <returns>Game id.</returns>
        public static string GetGameId(IGameContainer gameContainer)
        {
            if (gameContainer == null)
            {
                throw new ArgumentNullException(nameof(gameContainer));
            }

            return(gameContainer.GetGameId());
        }
예제 #10
0
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            var files = container.GetGameFiles();
            var id    = container.GetGameId();

            bool inventoryFound  = false;
            bool vocabularyFound = false;
            bool volumeFound     = false;
            bool amigaMapFound   = false;

            foreach (string file in files)
            {
                if (string.Compare("object", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    inventoryFound = true;
                    continue;
                }

                if (string.Compare("words.tok", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    vocabularyFound = true;
                    continue;
                }

                if (file.ToLower(CultureInfo.InvariantCulture).EndsWith("vol.0"))
                {
                    volumeFound = true;
                    continue;
                }

                if (string.Compare("dirs", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    amigaMapFound = true;
                    continue;
                }
            }

            if (inventoryFound && vocabularyFound && volumeFound)
            {
                var name        = container.Name;
                var platform    = amigaMapFound ? Platform.Amiga : Platform.PC;
                var interpreter = id.Length > 0 ? InterpreterVersion.V3002149 : InterpreterVersion.V2936;
                var version     = string.Empty;

                result = new GameDetectorResult(name, interpreter, platform, version);
            }

            return(result);
        }
예제 #11
0
        public GameOverScreen(IGameContainer gameContainer, int score)
        {
            _gameContainer = gameContainer;
            this.TransitionOnTime = TimeSpan.FromSeconds(0.5f);
            this.TransitionOffTime = TimeSpan.FromSeconds(0.5f);
            this.FadeType = FadeType.FadeAlpha;
            this.EnabledGestures = GestureType.Tap;

            this.CreateUI(score);
        }
예제 #12
0
        /// <summary>
        /// Handles the corresponding event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ValueChangedEventArgs{T}"/> instance containing the event data.</param>
        void _game_RenderWindowChanged(IGameContainer sender, ValueChangedEventArgs <RenderWindow> e)
        {
            _drawingManager.RenderWindow = e.NewValue;

            foreach (var gs in _screens.Values)
            {
                var guiMan = gs.GUIManager;
                if (guiMan != null)
                {
                    guiMan.Window = e.NewValue;
                }
            }
        }
예제 #13
0
        private static GameStartInfo FindGame(GameDetector detector, IGameContainer container)
        {
            GameStartInfo startInfo = null;

            var result = detector.Detect(container);

            if (result.Detected)
            {
                string id = ResourceLoader.GetGameId(container);

                startInfo = new GameStartInfo(container, id, result.Platform, result.Interpreter, result.Name, result.Version);
            }

            return(startInfo);
        }
예제 #14
0
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            const string GameInfoExtension = ".agigame";

            var files = container.GetFilesByExtension(GameInfoExtension);

            if (files.Length > 0)
            {
                try
                {
                    // Example .agigame file contents:
                    //
                    // <?xml version="1.0" encoding="utf-8" ?>
                    // <game name="The Black Cauldron"
                    //  platform="PC"
                    //  date="XXXX-XX-XX"
                    //  version="2.00"
                    //  format="FLOPPY"
                    //  interpreter="2.439"
                    //  language="English"/>
                    var doc = new XmlDocument();
                    doc.Load(files[0]);

                    var node = doc.SelectSingleNode("game");
                    if (node != null)
                    {
                        var name        = node.Attributes["name"].Value;
                        var platform    = node.Attributes["platform"].Value;
                        var interpreter = node.Attributes["interpreter"].Value;
                        var version     = node.Attributes["version"].Value;

                        result = new GameDetectorResult(name, GameInfoParser.ParseInterpreterVersion(interpreter), GameInfoParser.ParsePlatform(platform), version);
                    }
                }
                catch (XmlException)
                {
                }
            }

            return(result);
        }
예제 #15
0
        /// <summary>
        /// Load the resource map located in the specified folder.
        /// </summary>
        /// <param name="container">Game container where the resource map file(s) are located.</param>
        /// <returns>Resource map.</returns>
        VolumeResourceMap IVolumeDecoder.LoadResourceMap(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var map = new VolumeResourceMap();

            VolumeDecoderV2.LoadResourceMapFile(container.Read(LogMapFile), map.LogicResources);
            VolumeDecoderV2.LoadResourceMapFile(container.Read(ViewMapFile), map.ViewResources);
            VolumeDecoderV2.LoadResourceMapFile(container.Read(PicMapFile), map.PictureResources);
            VolumeDecoderV2.LoadResourceMapFile(container.Read(SndMapFile), map.SoundResources);

            return(map);
        }
예제 #16
0
        /// <summary>
        /// Determine if a game is located in the specified folder.
        /// </summary>
        /// <param name="gameContainer">Game container.</param>
        /// <returns>True if a game is found in the folder, false otherwise.</returns>
        public static bool IsGameFolder(IGameContainer gameContainer)
        {
            if (gameContainer == null)
            {
                throw new ArgumentNullException(nameof(gameContainer));
            }

            bool result = false;

            if (gameContainer.Exists(VocabularyFile))
            {
                if (gameContainer.Exists(InventoryFile))
                {
                    result = true;
                }
            }

            return(result);
        }
예제 #17
0
        /// <summary>
        /// Search the specified folder for a game.
        /// </summary>
        /// <param name="container">Game container to search.</param>
        /// <returns>Game detection result.</returns>
        public GameDetectorResult Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            int i = 0;

            while (!result.Detected && i < this.algorithms.Length)
            {
                result = this.algorithms[i].Detect(container);
                i++;
            }

            return(result);
        }
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            var result = new GameDetectorResult();

            // Look in the current directory for all game files
            var files = Database.GetFolderGameFiles(container);

            if (files.Count > 0)
            {
                // Find a game match
                var match = this.database.FindMatch(files);
                if (match != null)
                {
                    result = new GameDetectorResult(match.Name, GameInfoParser.ParseInterpreterVersion(match.Interpreter), GameInfoParser.ParsePlatform(match.Platform), match.Version);
                }
            }

            return(result);
        }
예제 #19
0
        /// <summary>
        /// Get all the files in the specified container that are game data files and calculate
        /// the crc for them.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>List of files.</returns>
        internal static GameFileCollection GetFolderGameFiles(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            string[] gameFiles = container.GetGameFiles();

            // Calculate the checksum for each game file
            GameFileCollection crcs = new GameFileCollection();

            foreach (string file in gameFiles)
            {
                GameFile crc = GameFile.FromFile(container, file);
                crcs.Add(crc);
            }

            return(crcs);
        }
예제 #20
0
        /// <summary>
        /// Create instance of a <see cref="GameFile"/> from a specified
        /// container and file.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <param name="fileName">Game file.</param>
        /// <returns>Instance initialized with filename and checksum.</returns>
        internal static GameFile FromFile(IGameContainer container, string fileName)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var data = container.Read(fileName);

            return(new GameFile
            {
                Name = fileName,
                Sha1 = CalculateSha1(data),
            });
        }
예제 #21
0
 public static void RegisterViewModel <TViewModel>(this IGameContainer container, TViewModel viewModel, string identifier) where TViewModel : ViewModel
 {
     container.Register <TViewModel, TViewModel>();
     container.RegisterInstance <ViewModel>(viewModel, identifier);
     container.RegisterInstance(typeof(TViewModel), viewModel, identifier);
 }
예제 #22
0
 public static void RegisterViewModelController <TController, TViewModel>(this IGameContainer container, TController controller) where TController : Controller
 {
     // Nothing yet
 }
예제 #23
0
 public SceneContext(IGameContainer gameContainer)
 {
     Container = gameContainer;
 }
 public GameController(ILudoGame ludoGame, IGameContainer games)
 {
     _games    = games;
     _LudoGame = ludoGame;
 }
예제 #25
0
 public UnitTests()
 {
     _gameContainer  = new GameContainerMock();
     _ludoController = new LudoController(_gameContainer);
 }
예제 #26
0
 /// <summary>
 /// Fires when the game window gains focus
 /// </summary>
 /// <param name="sender">The sender of this event</param>
 /// <param name="e">The event arguments of the game window</param>
 void _game_GainedFocus(IGameContainer sender, EventArgs e)
 {
     _updateGameControls = true;
 }
예제 #27
0
 /// <summary>
 /// Fires when the game window loses focus
 /// </summary>
 /// <param name="sender">The sender of this event</param>
 /// <param name="e">The event arguments of the game window</param>
 void _game_LostFocus(IGameContainer sender, EventArgs e)
 {
     _updateGameControls = false;
 }
예제 #28
0
 /// <summary>
 /// GameManager Ctor
 /// </summary>
 /// <param name="container"></param>
 /// <param name="handler"></param>
 public GameManager(IGameContainer container, IGameEventHandler handler)
 {
     this.container = container;
     this.handler   = handler;
 }
 public GameController(IGameContainer gameContainer)
 {
     this.gameContainer = gameContainer;
 }
예제 #30
0
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            const string GameInfoExtension = ".wag";

            var files = container.GetFilesByExtension(GameInfoExtension);

            if (files.Length > 0)
            {
                try
                {
                    var id          = new StringBuilder();
                    var description = new StringBuilder();
                    var interpreter = new StringBuilder();
                    var version     = new StringBuilder();

                    // Last 16 bytes are not stored as properties, it's the
                    // WinAGI version string. Ex: "PMWINAGI v1.0"
                    var data  = container.Read(files[0]);
                    var index = 0;
                    while (index < (data.Length - 16))
                    {
                        byte code = data[index++];
                        index++; // type - not used
                        index++; // num - not used
                        int size = data[index++] + (data[index++] * 256);

                        switch (code)
                        {
                        case 129:
                            // game description
                            for (int i = 0; i < size; i++)
                            {
                                description.Append((char)data[index + i]);
                            }

                            break;

                        case 131:
                            // game id
                            for (int i = 0; i < size; i++)
                            {
                                id.Append((char)data[index + i]);
                            }

                            break;

                        case 132:
                            // interpreter
                            for (int i = 0; i < size; i++)
                            {
                                interpreter.Append((char)data[index + i]);
                            }

                            break;

                        case 134:
                            // game version
                            for (int i = 0; i < size; i++)
                            {
                                version.Append((char)data[index + i]);
                            }

                            break;
                        }

                        index += size;
                    }

                    var name     = description.Length > 0 ? description.ToString() : id.ToString();
                    var platform = Platform.PC;

                    result = new GameDetectorResult(name, GameInfoParser.ParseInterpreterVersion(interpreter.ToString()), platform, version.ToString());
                }
                catch (IOException)
                {
                }
                catch (ArgumentOutOfRangeException)
                {
                }
            }

            return(result);
        }
 public GameHubHandler(GameHub hub, IGameContainer games)
 {
     Hub = hub;
     Games = games;
 }
예제 #32
0
 public static void RegisterController <TController>(this IGameContainer container, TController controller) where TController : Controller
 {
     container.RegisterInstance <Controller>(controller, controller.GetType().Name, false);
     container.RegisterInstance <TController>(controller, false);
 }