Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="level">level data</param>
 public MapDetails(BasicLevel level)
 {
     InitializeComponent();
     creatorLabel.Content = level.Creator;
     dateLabel.Content = level.Date;
     descriptionLabel.Text = level.Description;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks for arguments on startup
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="e">list of arguments</param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // File type setup
            if (e.Args.Length == 1 && e.Args[0].Equals("setup"))
            {
                try
                {
                    // Get a path for the icon in appdata
                    string iconPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\icon.ico";

                    // Save the icon
                    FileStream iconStream = new FileStream(iconPath, FileMode.Create);
                    TowerHaven.Properties.Resources.icon.Save(iconStream);
                    iconStream.Close();

                    // Create the application reference
                    RegistryKey root = Registry.ClassesRoot;
                    RegistryKey application = root.CreateSubKey("TowerHaven");
                    application.SetValue(string.Empty, "Tower Haven Level Data");
                    application.CreateSubKey("DefaultIcon")
                        .SetValue(string.Empty, iconPath);
                    application.CreateSubKey("shell")
                        .CreateSubKey("Open")
                        .CreateSubKey("Command")
                        .SetValue(string.Empty, "\"" + Environment.CurrentDirectory + "\\" + AppDomain.CurrentDomain.FriendlyName + "\" OpenMap %1");

                    // Create the file type association
                    RegistryKey extension = root.CreateSubKey(".thld");
                    extension.SetValue(string.Empty, "TowerHaven");
                }
                catch (Exception) { /* In case someone runs the program with the argument without elevation or when it is already set up */ }
                Environment.Exit(0);
            }

            // Play level
            else if (e.Args.Length > 1 && e.Args[0].Equals("OpenMap"))
            {
                BasicLevel level = new BasicLevel();
                string path = e.Args[1];
                for (int i = 2; i < e.Args.Length; ++i)
                    path += " " + e.Args[i];
                level.LoadMap(path);
                Game game = new Game(level);
                game.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                game.ShowDialog();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts the selected level
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="e">not used</param>
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            int index = (int)cursor.Margin.Top / 20;

            if (campaign && index == 2)
            {
                EndlessMode endlessMode = new EndlessMode();
                endlessMode.Owner = this;
                Hide();
                try
                {
                    endlessMode.ShowDialog();
                }
                catch (Exception)
                {
                    endlessMode.Close();
                    MessageBox.Show("Game data has been modified during play.\nAn error has occurred due to this.\nThe level was aborted.");
                }
                Show();
                return;
            }

            Boolean goodMap = false;
            BasicLevel level = new BasicLevel();

            // Load the map
            if (campaign)
                goodMap = level.LoadCampaign(mapNames[index]);
            else
                goodMap = level.Load(mapNames[index]);

            // If successful, play the map
            if (goodMap)
            {
                Game game = new Game(level);
                game.Owner = this;
                Hide();
                try
                {
                    game.ShowDialog();
                }
                catch (Exception)
                {
                    game.Close();
                    MessageBox.Show("Game data has been modified during play.\nAn error has occurred due to this.\nThe level was aborted.");
                }
                Show();
                return;
            }

            // Remove the map due to not being valid
            grid1.Children.RemoveAt(index + 1);
            for (int i = index + 1; i < grid1.Children.Count; ++i)
            {
                Label l = grid1.Children[i] as Label;
                l.Margin = new Thickness(l.Margin.Left, l.Margin.Top - 20, 0, 0);
            }
            if (grid1.Children.Count == 1)
            {
                MessageBox.Show("There are no more maps available");
                Close();
            }
            else if (index == grid1.Children.Count - 1)
            {
                cursor.Margin = new Thickness(8, 20 * index - 16, 0, 0);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Shows the details of a map
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="e">not used</param>
        private void detailButton_Click(object sender, RoutedEventArgs e)
        {
            int index = (int)cursor.Margin.Top / 20;
            BasicLevel level = new BasicLevel();

            bool goodMap;

            // Load the map
            if (campaign)
                goodMap = level.LoadCampaign(mapNames[index]);
            else
                goodMap = level.Load(mapNames[index]);

            if (goodMap)
            {
                MapDetails detailMenu = new MapDetails(level);
                detailMenu.Owner = this;
                Hide();
                detailMenu.ShowDialog();
                Show();
            }
        }