Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();

            _messageHub = new MessageHub();
            _session    = new Session(_messageHub);
            _session.Init();

            var graphics = new WinFormGraphics(canvas);

            _scene = new Scene(_session, graphics);

            _mapHandler = new Editor.MapEditor(_messageHub, _session, canvas.Width / 20, canvas.Height / 20);
            // todo: replace with an OnChecked handler
            _mapHandler.ShowGrid(gridChk.Checked);
            _mapHandler.Init();

            _unitHandler = new UnitHandler(_messageHub, _session);
            _unitHandler.Init();

            // todo: is cameraHandler the responsibility of Map class?
            _cameraHandler = new CameraHandler(_messageHub, new Point(0, 0), canvas.Width, canvas.Height);
            _cameraHandler.Init();

            _input            = new Editor.EditorInput(_messageHub, _cameraHandler);
            _mouseState       = new MouseState();
            canvas.MouseMove += (sender, eventArgs) =>
            {
                _mouseState.GetState(eventArgs.Location, eventArgs.Button);
                _input.OnMouseEvent(_mouseState);
            };
            KeyPreview = true;
            KeyPress  += (sender, eventArgs) =>
            {
                _input.OnKeyboardEvent(eventArgs);
            };

            LoadTerrains();
            LoadUnits();

            var timer = new Timer();

            timer.Tick    += Update;
            timer.Interval = 100; // in miliseconds
            timer.Start();
        }