Ejemplo n.º 1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Game1 game = new Game1())
     {
         game.Run();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new HighScores view
        /// </summary>
        /// <param name="game">The Game instance that will show this view</param>
        /// <param name="levelName">The name of the level which high scores this view will
        ///                         show</param>
        public HighScores(Game1 game, String levelName)
            : base(game)
        {
            level = levelName.Replace('_', ' ');
            recordHandler = new RecordHandler(level);
            recordHandler.LoadRecords();
            for (int i = 0; i < recordHandler.Records.Count; i++)
            {
                TimeSpan time = TimeSpan.FromMilliseconds(recordHandler.Records[i].Time);

                scoresList += (i + 1) + "  " + recordHandler.Records[i].Name + "  " +
                              String.Format("{0:d2}:{1:d2}:{2:d3}",
                                            time.Minutes, time.Seconds, time.Milliseconds) + "\n";
            }
            font = game.Content.Load<SpriteFont>("SpriteFont1");
            topic = game.Content.Load<Texture2D>("Images/highScores");
            topicPos = new Vector2(game.getWidth() * 0.5f - topic.Width * 0.5f, 0);
            namePos = new Vector2(game.getWidth() * 0.5f - font.MeasureString(level).X * 0.5f,
                                  topic.Height);

            closeButton = new Button("ok", new Vector2(game.getWidth() * 0.7f,
                                           game.getHeight() * 0.75f),
                                           game.Content);

            closeButton.Position = new Vector2(game.getWidth() * 0.5f - closeButton.Width * 0.5f,
                                               game.getHeight() * 0.78f);

            closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed);

            backButton = new Button("back", new Vector2(game.relativeX(10), game.relativeY(430)),
                                            game.Content,
                                            true);
            backButton.Width = 70; backButton.Height = 43;
            backButton.ButtonPressed += new Action<Button>(backButton_ButtonPressed);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new level saving view
 /// </summary>
 /// <param name="game">The Game instance that will show this view</param>
 public LevelSaver(Game1 game)
     : base(game)
 {
     nameInput = new TextInput("Enter the name of you level", new Vector2(200, 200),
                               game.Content, 400, 50);
     closeButton = new Button("ok", new Vector2(300, 350), game.Content);
     closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new view
 /// </summary>
 /// <param name="pGame">The Game instance that will show this view</param>
 public View(Game1 pGame)
 {
     game = pGame;
     destination = new Rectangle(0, 0, pGame.getWidth(), pGame.getHeight() );
     background = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
     Color[] colors = new Color[background.Width * background.Height];
     for (int i = 0; i < colors.Length; i++)
         colors[i] = new Color(0.0f, 0.0f, 0.0f, 0.4f);
     background.SetData<Color>(colors);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new info view
        /// </summary>
        /// <param name="game">The Game instance that will show this view</param>
        public InfoView(Game1 game)
            : base(game)
        {
            maxY = (int)(game.getHeight() * 0.1f);
            infoText = game.Content.Load<String>(@"infotexts");
            font = game.Content.Load<SpriteFont>("SpriteFont1");
            textHeight = font.MeasureString(infoText).Y;
            textPos = new Vector2(game.getWidth() * 0.25f, game.getHeight() * 0.1f);
            closeButton = new Button("ok", buttonPos, game.Content);
            closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed);

            buttonPos = new Vector2(game.getWidth() * 0.5f - closeButton.Width * 0.5f,
                                    textPos.Y + textHeight);
            closeButton.Position = buttonPos;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new main menu view
        /// </summary>
        /// <param name="game">The Game instance that will show this view</param>
        public Menu(Game1 game)
            : base(game)
        {
            Vector2 pos = new Vector2(game.getWidth() * 0.88f, 0);
            infoButton = new Button("info", pos, game.Content);
            infoButton.ButtonPressed += (sender => game.ShowInfo());

            if (game.paused && !game.won)
            {
                Button tmp = new Button("resume", pos, game.Content);
                tmp.ButtonPressed += (sender => game.Resume());
                buttons.Add(tmp);
            }

            Button button = new Button("newGame", pos, game.Content);
            button.ButtonPressed += (sender => game.ShowLevelSelector(true));
            buttons.Add(button);

            button = new Button("levelEditor", pos, game.Content);
            button.ButtonPressed += (sender => game.StartLevelEditor());
            buttons.Add(button);

            button = new Button("highScores", pos, game.Content);
            button.ButtonPressed += (sender => game.ShowLevelSelector(false));
            buttons.Add(button);

            button = new Button("exit", pos, game.Content);
            button.ButtonPressed += (sender => game.Exit());
            buttons.Add(button);

            int menuHeight = (buttons.Count - 1) * spacing;
            foreach (Button but in buttons)
            {
                menuHeight += but.Height;
            }

            pos.Y = game.getHeight() * 0.5f - menuHeight * 0.5f;

            for (int i = 0; i < buttons.Count; i++)
            {
                pos.X = game.getWidth() * 0.5f - buttons[i].Width * 0.5f;
                buttons[i].Position = pos;
                pos.Y += (buttons[i].Height + spacing);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new view for telling that the player has completed the level
        /// </summary>
        /// <param name="game">The Game instance that will show this view</param>
        public WinView(Game1 game)
            : base(game)
        {
            recordHandler = new RecordHandler(game.currentLevelName);
            recordHandler.LoadRecords();
            closeButton = new Button("ok", new Vector2(0, 0), game.Content);
            closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed);

            closeButton.Position = new Vector2(game.getWidth() * 0.5f -
                                                  closeButton.Width * 0.5f,
                                               game.getHeight() * 0.75f);
            textInput = new TextInput("Enter your name here",
                                      new Vector2(game.getWidth() * 0.3f, game.relativeY(200)),
                                      game.Content, (int)(game.getWidth() * 0.4f),
                                      (int)(game.getHeight() * 0.1f));
            font = game.Content.Load<SpriteFont>("SpriteFont2");
            placement = recordHandler.GetPlacement((int)(game.finishTime.TotalMilliseconds));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new level selecting view
        /// </summary>
        /// <param name="game">The Game instance that will show this view</param>
        /// <param name="pNewGame">true if the level is going to be 
        ///                        selected for the new game, false otherwise</param>
        /// <param name="myLevelsPage">true if the view is wanted to
        ///                            be opened on the custom level page</param>
        public LevelSelector(Game1 game, bool pNewGame, bool myLevelsPage)
            : base(game)
        {
            maxY = (int)(game.getHeight() * 0.1f);
            newGame = pNewGame;
            float screenXMiddle = game.getWidth() / 2;
            int spacing = 90;
            int top = 70;
            Button button = new Button("level1", Vector2.Zero, game.Content);
            button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed);

            preDefinedButtons.Add(button);
            button.Position = new Vector2(screenXMiddle - button.Width * 0.5f,
                                          spacing * (preDefinedButtons.Count-1) + top);
            button = new Button("level2", Vector2.Zero, game.Content);
            button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed);

            preDefinedButtons.Add(button);
            button.Position = new Vector2(screenXMiddle - button.Width * 0.5f,
                                          spacing * (preDefinedButtons.Count-1) + top);
            button = new Button("level3", Vector2.Zero, game.Content);
            button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed);

            preDefinedButtons.Add(button);
            button.Position = new Vector2(screenXMiddle - button.Width * 0.5f,
                                          spacing * (preDefinedButtons.Count-1) + top);
            button = new Button("myLevels", Vector2.Zero,
                                game.Content);
            button.ButtonPressed += new Action<Button>(button_ButtonPressed);

            preDefinedButtons.Add(button);
            button.Position = new Vector2(screenXMiddle - button.Width * 0.5f,
                                          spacing * (preDefinedButtons.Count-1) + top);

            IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
            String[] fileNames = savegameStorage.GetFileNames();
            for (int i = 0; i < fileNames.Length; i++)
            {
                String[] pieces = fileNames[i].Split('.');
                if (pieces.Length > 1 && pieces[1] == "lvl")
                {
                    var tmpButton = new Button(pieces[0].Replace('_', ' '), Vector2.Zero,
                                        game.Content, false);
                    tmpButton.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed);
                    tmpButton.ButtonLongPressed += new Action<Button>(tmpButton_ButtonLongPressed);
                    myButtons.Add(tmpButton);
                    tmpButton.Position = new Vector2(screenXMiddle - tmpButton.Width * 0.5f,
                                                  60 * (myButtons.Count));
                }
            }
            minY = -myButtons.Count * 60 + (int)(0.5f * game.getHeight());
            yesButton = new Button("Yes", new Vector2(game.relativeX(290), game.relativeY(280)), game.Content, false);
            yesButton.ButtonPressed += new Action<Button>(yesButton_ButtonPressed);

            noButton = new Button("No", new Vector2(game.relativeX(490), game.relativeY(280)), game.Content, false);
            noButton.ButtonPressed += new Action<Button>(noButton_ButtonPressed);

            backButton = new Button("back", new Vector2(game.relativeX(10), game.relativeY(430)), game.Content, true);
            backButton.ButtonPressed += new Action<Button>(backButton_ButtonPressed);
            backButton.Width = 70;
            backButton.Height = 43;

            if (myLevelsPage)
                buttons = myButtons;
            else
                buttons = preDefinedButtons;

            font = game.Content.Load<SpriteFont>("SpriteFont1");
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new splash screen view
 /// </summary>
 /// <param name="game">The Game instance that will show this view</param>
 public SplashScreen(Game1 game)
     : base(game)
 {
     texture = game.Content.Load<Texture2D>("Images/splash");
 }