예제 #1
0
 public void Execute()
 {
     Game1.GetInstance().gameState = new TitleScreenGameState();
     Game1.GetInstance().isTitle   = true;
 }
예제 #2
0
        public Mario Build(string fileName)
        {
            float        xCoord = 0, yCoord = 0;
            StreamReader sr;

            sr = File.OpenText(Game1.GetInstance().Content.RootDirectory + fileName);
            string line;

            while ((line = sr.ReadLine()) != null)
            {
                yCoord += spacingIncrement;
                xCoord  = 0;
                string[] words = line.Split(',');
                for (int i = 0; i < words.Length; i++)
                {
                    int events = 1;
                    if (words[i] == "M")
                    {
                        mario = new Mario(new Vector2(xCoord, yCoord));
                    }
                    if (itemDictionary.ContainsKey(words[i]))
                    {
                        ICollectable item = collectableFactory.build(itemDictionary[words[i]], new Vector2(xCoord, yCoord));
                        level.levelItems.Add(item);
                    }
                    if (backgroundDictionary.ContainsKey(words[i]))
                    {
                        if (words[i] == "exit")
                        {
                            level.exitPosition = new Vector2(xCoord, yCoord);
                        }
                        else
                        {
                            KeyValuePair <IAnimatedSprite, Vector2> item = new KeyValuePair <IAnimatedSprite,
                                                                                             Vector2>(factory.build(backgroundDictionary[words[i]]), new Vector2(xCoord, yCoord));
                            level.levelBackgroundObjects.Add(item);
                        }
                    }
                    if (blockDictionary.ContainsKey(words[i]))
                    {
                        Block block = blockFactory.build(blockDictionary[words[i]], new Vector2(xCoord, yCoord));
                        level.levelBlocks.Add(block);
                    }
                    if (enemyDictionary.ContainsKey(words[i]))
                    {
                        Enemy enemy = enemyFactory.build(enemyDictionary[words[i]], new Vector2(xCoord, yCoord));
                        level.levelEnemies.Add(enemy);
                    }
                    if (pipeDictionary.ContainsKey(words[i]))
                    {
                        Pipe pipe = pipeFactory.build(pipeDictionary[words[i]], new Vector2(xCoord, yCoord));
                        i++;
                        int exitPiX = int.Parse(words[i]);
                        i++;
                        int exitPiY = int.Parse(words[i]);
                        i++;
                        Pipe exitPipe = pipeFactory.build(pipeDictionary[words[i]], new Vector2((float)exitPiX, (float)exitPiY));
                        pipe.exitPipe = exitPipe;
                        level.levelPipes.Add(pipe);
                        level.levelPipes.Add(exitPipe);
                        events = 4;
                    }
                    if (words[i] == "V")
                    {
                        level.levelSpikes.Add(new Spike(new Vector2(xCoord, yCoord), false));
                    }
                    if (words[i] == "^")
                    {
                        level.levelSpikes.Add(new Spike(new Vector2(xCoord, yCoord), true));
                    }
                    if (words[i] == "t")
                    {
                        level.levelTrampolines.Add(new Trampoline(new Vector2(xCoord, yCoord)));
                    }
                    if (words[i] == "Ch")
                    {
                        level.checkpoint = new Vector2(xCoord, yCoord);
                    }
                    xCoord += spacingIncrement * events;
                }
            }
            return(mario);
        }