Пример #1
0
        /// <summary>
        /// Function called when a key is pressed
        /// </summary>
        static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            if (e.Code == Keyboard.Key.Escape)
            {
                m_Window.Close();
            }

            if (e.Code == Keyboard.Key.F12)
            {
                Image img = m_Window.Capture();
                if (img.Pixels == null)
                {
                    MessageBox.Show("Failed to capture window");
                }
                string path = String.Format("screenshot-{0:D2}{1:D2}{2:D2}.png", DateTime.Now.Hour, DateTime.Now.Minute,
                                            DateTime.Now.Second);
                if (!img.SaveToFile(path))
                {
                    MessageBox.Show(path, "Failed to save screenshot");
                }
                img.Dispose();
            }
            else
            {
                m_Input.ProcessMessage(new Input.SFMLKeyEventArgs(e, true));
            }
        }
Пример #2
0
        private void TrackOnFinishLineCrossed(int id)
        {
            PauseSimulation();

            // render a zoomed in view of the winning car
            const float width      = 8;
            var         ratio      = m_drawingView.Size.Y / m_drawingView.Size.X;
            View        winnerView = new View
            {
                Center   = m_population.Leader.Position.ToVector2f().InvertY(),
                Size     = new Vector2f(width, width * ratio),
                Viewport = new FloatRect(0, 0, 1, 1)
            };

            m_drawingWindow.SetView(winnerView);
            m_drawingWindow.Clear(Color.White);
            m_track.Draw(m_drawingWindow);
            m_population.Draw(m_drawingWindow);
            m_drawingWindow.Display();

            // save a screenshot
            var filename = string.Format(
                "pid{3}_gen{0}_car{1}_{2:yyyy-MM-dd_HH-mm-ss}.png",
                m_population.Generation, id, DateTime.Now,
                Process.GetCurrentProcess().Id);

            m_drawingWindow.Capture().SaveToFile(filename);
            Log.InfoFormat("Screenshot of winner saved to {0}", filename);

            var message = string.Format(
                "Track defeated in generation {0} by car {1}.\n" +
                "Click Yes to generate a new world with a new seed, or No to exit.",
                m_population.Generation, id
                );
            var result = MessageBox.Show(message, "Great Success",
                                         MessageBoxButtons.YesNo, MessageBoxIcon.None);

            if (result == DialogResult.Yes)
            {
                m_newWorld = true;
            }
            else
            {
                m_exit = true;
            }

            ResumeSimulation();
        }
Пример #3
0
        private void DrawInSFML()
        {
            window.SetActive();
            window.Clear();
            for (int y = 0; y < map.map.GetLength(0); y++)
            {
                for (int x = 0; x < map.map.GetLength(1); x++)
                {
                    var rect = new RectangleShape(new Vector2f(NeatConsts.TileSize, NeatConsts.TileSize));
                    rect.FillColor = new Color(255, 255, 255);
                    rect.Position  = new Vector2f(NeatConsts.TileSize * x, NeatConsts.TileSize * y);
                    if (player.position.x == x && player.position.y == y)
                    {
                        rect.FillColor = new Color(255, 175, 0);
                        window.Draw(rect);
                        continue;
                    }

                    switch (map.map[y, x])
                    {
                    case 0:
                        rect.FillColor = new Color(255, 255, 255);
                        break;

                    case 1:
                        rect.FillColor = new Color(0, 0, 0);
                        break;

                    case 2:
                        rect.FillColor = new Color(255, 0, 0);
                        break;

                    case 3:
                        rect.FillColor = new Color(0, 255, 0);
                        break;
                    }
                    window.Draw(rect);
                }
            }
            window.DispatchEvents();
            window.Display();
            if (NeatConsts.RecordPlay)
            {
                window.Capture().SaveToFile($"{NeatConsts.experimentName}/step{player.position.x}.png");
            }
        }
Пример #4
0
        private void Keyboard_F12Pressed(object sender, EventArgs e)
        {
            window.Clear(Color.Black);
            Draw();

            Image tmp = window.Capture();

            System.IO.Directory.CreateDirectory("screenshots");
            tmp.SaveToFile("screenshots/" +
                           DateTime.Now.Hour + "_" +
                           DateTime.Now.Minute + "_" +
                           DateTime.Now.Second + "-" +
                           DateTime.Now.Day + "_" +
                           DateTime.Now.Month + "_" +
                           DateTime.Now.Year +
                           ".png");

            window.Clear(Color.Black);

            Console.WriteLine("screenshot");
        }