Esempio n. 1
0
        /// <summary>
        /// Loads a new level from the given data path.
        /// </summary>
        /// <param name="sourceDirectory">The data path.</param>
        public async Task LoadLevelAsync(string sourceDirectory)
        {
            // Load the level
            m_currentLevel = await LevelData.FromDirectoryAsync(sourceDirectory);

            // Load graphics for this level
            if(m_gameScreenManager != null)
            {
                await m_gameScreenManager.ClearAsync(m_scene);
            }

            m_gameScreenManager = new GameScreenManagerLogic();

            // Build the first screen
            await m_gameScreenManager.BuildFirstScreenAsync(m_currentLevel, m_scene);

            m_camera.Position = new Vector3(0, 12f, 0f);
            m_camera.Target = new Vector3(0f, 0f, 0.1f);
            m_camera.UpdateCamera();

            m_scene.Messenger.BeginPublish(new LevelLoadedMessage(m_currentLevel));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BackgroundMusicLogic"/> class.
 /// </summary>
 public BackgroundMusicLogic(LevelData currentLevel)
 {
     m_currentLevel = currentLevel;
     m_lastMusicIndex = -1;
 }
Esempio n. 3
0
        public EndGameLogic(LevelData levelData)
        {
            levelData.EnsureNotNull("levelData");

            m_levelData = levelData;
        }
Esempio n. 4
0
 /// <summary>
 /// Loads the level from the given directory.
 /// </summary>
 /// <param name="directoryName">Name of the directory.</param>
 public static async Task<LevelData> FromDirectoryAsync(string directoryName)
 {
     LevelData result = null;
     await Task.Factory.StartNew(() => result = new LevelData(directoryName));
     return result;
 }
        /// <summary>
        /// Builds all game objects for the given level.
        /// </summary>
        /// <param name="currentLevel">The current level.</param>
        /// <param name="scene">The scene to which to add all objects.</param>
        internal async Task BuildFirstScreenAsync(LevelData currentLevel, Scene scene)
        {
            m_scene = scene;
            m_currentLevel = currentLevel;

            int tilesX = currentLevel.Tilemap.TilesX;
            int tilesY = currentLevel.Tilemap.TilesY;
            float tileDistX = Constants.TILE_DISTANCE_X;
            float tileDistY = -Constants.TILE_DISTANCE_Y;
            Vector3 midPoint = new Vector3((tilesX - 1) * tileDistX / 2f, 0f, ((tilesY - 1) * tileDistY / 2f));

            m_cardMapOnScreen = new Card[tilesX, tilesY];
            m_cardPairsOnScreen = new List<CardPairLogic>();

            ScreenData currentScreen = currentLevel.Screens[0];
            m_actScreenIndex = 0;

            await scene.ManipulateSceneAsync((manipulator) =>
            {
                // Build background and define level-wide resources
                manipulator.BuildBackground(currentLevel.MainTextures.BackgroundTextureLink);
                m_resBackgroundMaterial1 = manipulator.AddSimpleColoredMaterial(
                    currentLevel.MainTextures.Tile1TextureLink);
                m_resBackgroundMaterial2 = manipulator.AddSimpleColoredMaterial(
                    currentLevel.MainTextures.Tile2TextureLink);

                // Build the current screen
                BuildScreen(manipulator, currentScreen);

                // Add all logic components to the scene
                manipulator.Add(new PairUncoverLogic());
                manipulator.Add(new VideoPlayLogic());
                manipulator.Add(new BackgroundMusicLogic(currentLevel));
                manipulator.Add(new EndGameLogic(currentLevel));
                manipulator.Add(this);
            });

            Messenger.BeginPublish<MainMemoryScreenEnteredMessage>();
        }
        /// <summary>
        /// Searches the next free slot in the card map.
        /// </summary>
        /// <param name="currentLevel">The current leveldata.</param>
        /// <param name="cardMap">The card map.</param>
        private static Tuple<int, int> SearchFreeCardSlot(LevelData currentLevel, Card[,] cardMap)
        {
            Tuple<int, int> result = null;

            while (result == null)
            {
                int xPos = ThreadSafeRandom.Next(0, cardMap.GetLength(0));
                int yPos = ThreadSafeRandom.Next(0, cardMap.GetLength(1));

                // Check whether the tile position is allowed
                if (!currentLevel.Tilemap[xPos, yPos]) { continue; }

                // Check whether the tile position is used already
                if (cardMap[xPos, yPos] != null) { continue; }

                result = Tuple.Create(xPos, yPos);
            }

            return result;
        }
 public LevelLoadedMessage(LevelData loadedLevel)
 {
     this.LoadedLevel = loadedLevel;
 }