示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LevelData"/> class.
        /// </summary>
        /// <param name="directoryName">Name of the directory.</param>
        private LevelData(string directoryName)
        {
            m_musicFilePaths = new List<string>();

            // Search all main textures
            this.MainTextures = new MainTextureData(directoryName);

            // Handle tilemap file
            string tilemapPath = Path.Combine(directoryName, Constants.FILENAME_TILEMAP);
            if (File.Exists(tilemapPath))
            {
                this.Tilemap = TilemapData.FromFile(tilemapPath);
            }
            else
            {
                this.Tilemap = new TilemapData();
            }

            // Set reference to the main icon
            string appIconPath = Path.Combine(directoryName, Constants.FILENAME_APPICON);
            if (File.Exists(appIconPath))
            {
                this.AppIconPath = appIconPath;
            }

            // Load common level settings
            string levelSettingsPath = Path.Combine(directoryName, Constants.FILENAME_LEVELSETTINGS);
            if (File.Exists(levelSettingsPath))
            {
                this.LevelSettings = CommonTools.DeserializeFromXmlFile<LevelSettings>(levelSettingsPath);
            }
            else
            {
                this.LevelSettings = LevelSettings.Default;
            }

            // Load music folder
            string musicFolder = Path.Combine(directoryName, Constants.FOLDERNAME_MUSIC);
            if (Directory.Exists(musicFolder))
            {
                foreach (string actFileName in Directory.GetFiles(musicFolder))
                {
                    string actFileExtension = Path.GetExtension(actFileName);
                    if (!Constants.SUPPORTED_MUSIC_FORMATS.ContainsString(actFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    m_musicFilePaths.Add(actFileName);
                }
            }

            // Load ending folder
            string endingFolder = Path.Combine(directoryName, Constants.FOLDERNAME_ENDING);
            if (Directory.Exists(endingFolder))
            {
                foreach (string actFileName in Directory.GetFiles(endingFolder))
                {
                    if (Constants.SUPPORTED_VIDEO_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingVideo = actFileName;

                        using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(actFileName))
                        {
                            // Read the first frame
                            this.EndingVideoFirstFrame = videoReader.ReadFrame();
                            this.EndingVideoFirstFrame.SetAllAlphaValuesToOne_ARGB();

                            // Read the last frame
                            videoReader.SetCurrentPosition(videoReader.Duration, false);

                            this.EndingVideoLastFrame = videoReader.ReadFrame();
                            this.EndingVideoLastFrame.SetAllAlphaValuesToOne_ARGB();
                        }

                        continue;
                    }

                    if (Constants.SUPPORTED_IMAGE_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingImage = actFileName;
                        continue;
                    }

                    if (Constants.SUPPORTED_MUSIC_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingMusic = actFileName;
                        continue;
                    }
                }
            }

            // Load all screens
            IEnumerable<string> screenDirectories =
                from actScreenDirectory in Directory.GetDirectories(directoryName)
                where Path.GetFileName(actScreenDirectory).StartsWith(Constants.FOLDERPREFIX_SCREEN, StringComparison.OrdinalIgnoreCase)
                orderby Path.GetFileName(actScreenDirectory)
                select actScreenDirectory;
            this.Screens = new List<ScreenData>();
            foreach (string actScreenDirectory in screenDirectories)
            {
                ScreenData actScreen = new ScreenData(actScreenDirectory);
                if (actScreen.MemoryPairs.Count > 0)
                {
                    this.Screens.Add(actScreen);
                }
            }
        }
        /// <summary>
        /// Builds up the given screen on the given SceneManipulator.
        /// </summary>
        /// <param name="manipulator">The manipulator.</param>
        /// <param name="currentScreen">The screen to be build.</param>
        private void BuildScreen(SceneManipulator manipulator, ScreenData currentScreen)
        {
            int tilesX = m_currentLevel.Tilemap.TilesX;
            int tilesY = m_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));

            foreach (CardPairData actPairData in currentScreen.MemoryPairs)
            {
                CardPairLogic actCardPair = new CardPairLogic(actPairData);

                // Define all resources needed for a card for this pair
                var resTitleMaterial = manipulator.AddSimpleColoredMaterial(actPairData.TitleFile);
                var resGeometry1 = manipulator.AddGeometry(new CardObjectType()
                {
                    FrontMaterial = resTitleMaterial,
                    BackMaterial = m_resBackgroundMaterial1
                });
                var resGeometry2 = manipulator.AddGeometry(new CardObjectType()
                {
                    FrontMaterial = resTitleMaterial,
                    BackMaterial = m_resBackgroundMaterial2
                });

                // Create both cards for this pair
                Card cardA = new Card(resGeometry1, actCardPair);
                Card cardB = new Card(resGeometry2, actCardPair);
                Tuple<int, int> slotA = SearchFreeCardSlot(m_currentLevel, m_cardMapOnScreen);
                m_cardMapOnScreen[slotA.Item1, slotA.Item2] = cardA;
                Tuple<int, int> slotB = SearchFreeCardSlot(m_currentLevel, m_cardMapOnScreen);
                m_cardMapOnScreen[slotB.Item1, slotB.Item2] = cardB;

                // Add both cards to the scene
                cardA.Position = new Vector3(slotA.Item1 * tileDistX, 0f, slotA.Item2 * tileDistY) - midPoint;
                cardA.AccentuationFactor = 1f;
                cardB.Position = new Vector3(slotB.Item1 * tileDistX, 0f, slotB.Item2 * tileDistY) - midPoint;
                cardB.AccentuationFactor = 1f;
                manipulator.Add(cardA);
                manipulator.Add(cardB);

                // Assigns the cards to the pair object
                actCardPair.Cards = new Card[] { cardA, cardB };
                manipulator.Add(actCardPair);

                m_cardPairsOnScreen.Add(actCardPair);
            }
        }