Beispiel #1
0
        public void BindAStar()
        {
            // Made this way so it runs on the UI Thread, always.
            XNAWindow.BeginInvoke(new UIDelegate(() =>
            {
                XNAWindow.AStar = _astar;

                if (_astar != null)
                {
                    ListOpen.DataSource  = null;
                    ListOpen.DataSource  = _astar.Open;
                    ListClose.DataSource = null;
                    ListClose.DataSource = _astar.Close;
                    if (_astar.Current != null)
                    {
                        TextCurrent.Text = _astar.Current.ToString();
                    }
                    else
                    {
                        TextCurrent.Text = String.Empty;
                    }

                    this.Invalidate();
                }
            }));
        }
Beispiel #2
0
        private void Child_EnabledChanged(object sender, EventArgs e)
        {
            XNAWindow child = (XNAWindow)sender;

            if (!child.Enabled)
            {
                Hide();
            }
        }
Beispiel #3
0
        public override void Initialize()
        {
            if (initialized)
            {
                throw new InvalidOperationException("GameInProgressWindow cannot be initialized twice!");
            }

            initialized = true;

            BackgroundTexture       = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED;
            DrawBorders             = false;
            ClientRectangle         = new Rectangle(0, 0, WindowManager.RenderResolutionX, WindowManager.RenderResolutionY);

            XNAWindow window = new XNAWindow(WindowManager);

            window.Name = "GameInProgressWindow";
            window.BackgroundTexture = AssetLoader.LoadTexture("gameinprogresswindowbg.png");
            window.ClientRectangle   = new Rectangle(0, 0, 200, 100);

            XNALabel explanation = new XNALabel(WindowManager);

            explanation.Text = "A game is in progress.";

            AddChild(window);

            window.AddChild(explanation);

            base.Initialize();

            GameProcessLogic.GameProcessStarted += SharedUILogic_GameProcessStarted;
            GameProcessLogic.GameProcessExited  += SharedUILogic_GameProcessExited;

            explanation.CenterOnParent();

            window.CenterOnParent();

            Game.TargetElapsedTime = TimeSpan.FromMilliseconds(1000.0 / UserINISettings.Instance.ClientFPS);

            Visible = false;
            Enabled = false;

#if ARES
            try
            {
                if (File.Exists(ProgramConstants.GamePath + "debug/debug.log"))
                {
                    debugLogLastWriteTime = File.GetLastWriteTimeUtc(ProgramConstants.GamePath + "debug/debug.log");
                }
            }
            catch { }
#endif
        }
        public override void Initialize()
        {
            if (initialized)
            {
                throw new Exception("GameInProgressWindow cannot be initialized twice!");
            }

            initialized = true;

            BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            DrawMode          = PanelBackgroundImageDrawMode.STRETCHED;
            DrawBorders       = false;
            ClientRectangle   = new Rectangle(0, 0, WindowManager.RenderResolutionX, WindowManager.RenderResolutionY);

            XNAWindow window = new XNAWindow(WindowManager);

            window.Name = "GameInProgressWindow";
            window.BackgroundTexture = AssetLoader.LoadTexture("gameinprogresswindowbg.png");
            window.ClientRectangle   = new Rectangle(0, 0, 200, 100);

            XNALabel explanation = new XNALabel(WindowManager);

            explanation.Text = "A game is in progress.";

            AddChild(window);

            window.AddChild(explanation);

            base.Initialize();

            GameProcessLogic.GameProcessStarted += SharedUILogic_GameProcessStarted;
            GameProcessLogic.GameProcessExited  += SharedUILogic_GameProcessExited;

            explanation.CenterOnParent();

            window.CenterOnParent();

            Game.TargetElapsedTime = TimeSpan.FromMilliseconds(1000.0 / FPS);

            Visible = false;
            Enabled = false;
        }
Beispiel #5
0
        public void LoadMap()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            dialog.Filter           = "Text Files (*.txt)|*.txt";
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    using (Stream fileStream = dialog.OpenFile())
                    {
                        if (fileStream != null)
                        {
                            TextReader reader = new StreamReader(fileStream);
                            string     text   = reader.ReadToEnd();
                            string[]   split  = text.Split('\n');

                            char[,] result = new char[split[0].Length - 1, split.Length]; //Not counting \r

                            for (int i = 0; i < split.Length; i++)
                            {
                                char[] characters = split[i].TrimEnd('\r').ToCharArray();
                                for (int j = 0; j < characters.Length; j++)
                                {
                                    result[j, i] = characters[j];
                                }
                            }

                            _astar = new Algorithm.AStar(result.GetLength(0), result.GetLength(1));
                            _astar.LoadFromArray(result);

                            _astar.OnStepChanged = new StepChangedDelegate((state) =>
                            {
                                if (_stopAtStep)
                                {
                                    _semaphore.WaitOne();
                                }
                                else
                                {
                                    Thread.Sleep(_sleepInterval);
                                }

                                XNAWindow.BeginInvoke(new UIDelegate(() =>
                                {
                                    ListNextStep.SelectedIndex = (int)state;
                                    BindAStar();
                                }));
                            });

                            BindAStar();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error reading file from disk. Error: " + ex.Message);
                }
            }
        }