Example #1
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            // modell létrehozása
            _model           = new GameModel(new FileDataAccess( ));
            _model.GameOver += new EventHandler <EventArgs>(Model_GameOver);
            _model.NewGame(9);

            // nézemodell létrehozása
            _viewModel                = new RobotViewModel(_model);
            _viewModel.NewGameEasy   += new EventHandler(ViewModel_NewGameEasy);
            _viewModel.NewGameMedium += new EventHandler(ViewModel_NewGameMedium);
            _viewModel.NewGameHard   += new EventHandler(ViewModel_NewGameHard);

            _viewModel.MakeNewWall += new EventHandler <RobotEventArgs>(ViewModel_MakeNewWall);

            _viewModel.LoadGame     += new EventHandler(ViewModel_LoadGame);
            _viewModel.SaveGame     += new EventHandler(ViewModel_SaveGame);
            _viewModel.PauseGame    += new EventHandler(ViewModel_PauseGame);
            _viewModel.ContinueGame += new EventHandler(ViewModel_ContinueGame);
            // nézet létrehozása
            _view             = new MainWindow( );
            _view.DataContext = _viewModel;
            _view.Show( );

            // időzítő létrehozása
            _timer          = new DispatcherTimer( );
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick    += new EventHandler(Timer_Tick);
            _timer.Start( );
        }
Example #2
0
        private void Init()
        {
            var robots = ApiHelper.Fetch_all_Robots_by_Environment(this.ProcessEnvironment);

            _robots.Clear();
            foreach (var robot in robots)
            {
                var _robot = new RobotViewModel(robot);
                Robots.Add(_robot);
            }
        }
Example #3
0
        public async Task <ActionResult <RobotViewModel> > Post([FromBody] RobotViewModel robot)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var newRobot = await _robotService.CreateRobot(robot.Name, robot.Type);

            await _notificationHub.Clients.All.SendAsync("Notify", new Notification($"{robot.Name} (Robot) created!", SeverityLevel.Success));

            return(Ok(new RobotViewModel(newRobot)));
        }
        private void Initialize(ProcessViewModel process)
        {
            var robots = ApiHelper.Fetch_all_Robots_by_Environment(process.ProcessEnvironment);

            _robots.Clear();

            foreach (var robot in robots)
            {
                var _robot = new RobotViewModel(robot);
                this.Robots.Add(_robot);
            }

            this.QueueItemForm = new QueueItemFormViewModel(process.RobotInfo.QueueItemJSON);
        }
Example #5
0
        public IHttpActionResult PlaceRobot(RobotViewModel model)
        {
            try
            {
                //do validation first here.
                if (!ModelState.IsValid)
                {
                    var message = string.Join(" | ", ModelState.Values
                                              .SelectMany(v => v.Errors)
                                              .Select(e => e.ErrorMessage));

                    var feedback = new CommandFeedback
                    {
                        IsSuccess    = false,
                        ErrorMessage = "Invalid Data:" + message
                    };
                    return(Ok(JsonConvert.SerializeObject(feedback)));
                }

                Robot robot = null;

                //check if we have robot id
                if (model.RobotId != null)
                {
                    robot = RobotService.GetRobot(model.RobotId.ToString());
                }
                //create the robot if it doesn't exist
                if (model.RobotId == null || robot == null)
                {
                    robot = RobotService.CreateRobot();
                }

                var result = _placeCommand.Impact(robot,
                                                  new Position(model.Position.X, model.Position.Y, model.Position.Direction));

                if (result.IsSuccess)
                {
                    RobotService.PersistRobot(robot);
                }

                return(Ok(JsonConvert.SerializeObject(result)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Example #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="robotViewModel"></param>
        /// <param name="columns"></param>
        /// <param name="rows"></param>
        public GameViewModel(RobotViewModel robotViewModel, int columns, int rows)
        {
            try
            {
                InitializeGameViewModel(columns, rows);

                // robot viewmodel to receive incoming rfid events
                robotViewModel.RFIDUpdateEvent += OnRFIDUpdateEvent;

                // show start message
                GameInformation = "Start scanning RFID for Start Field";
                ShowGameInformation = true;
            }
            catch (Exception ex)
            {
                this.ShowInformationOverlay(ex.Message);
            }
        }
Example #7
0
        public MainPage()
        {
            this.InitializeComponent();
            environment           = new DefaultEnvironment(new Map(1, 1)); // Did not load the map yet...
            EnvironmentTickSource = new EnvironmentTickSource(environment, SimulationCycleLengthMs);

            var robot = new LineAndWallDetectorRobot(environment);

            Brain = new WallsAndLinesDemoBrain(robot);

            new LogCollector(Brain, this.LogViewModel); // Ctor performs registrations

            this.RobotViewModel = new RobotViewModel(robot);
            RobotImage.Source   = RobotViewModel.Image;

            this.MapViewModel = new MapViewModel();

            InitButtonCommands();
        }
Example #8
0
        public MainPage()
        {
            this.InitializeComponent();
            environment = new DefaultEnvironment(new Map(1, 1)); // Did not load the map yet...
            var robot = new LineAndWallDetectorRobot(environment, wallSensorMaxDistance: 50);
            var brain = new WallsAndLinesDemoBrain(robot);

            brain.AddCommand(new GenericSingleStateCommand(new FollowingLineState(5.0)));

            this.RobotViewModel = new RobotViewModel(robot);
            RobotImage.Source   = RobotViewModel.Image;

            this.MapViewModel = new MapViewModel();

            SimulationTickTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };
            SimulationTickTimer.Tick += SimulationTickTimer_Tick;
        }
        public MainPage()
        {
            this.InitializeComponent();
            environment           = new DefaultEnvironment(new Map(1, 1)); // Did not load the map yet...
            EnvironmentTickSource = new EnvironmentTickSource(environment, SimulationCycleLengthMs);

            var robot = new LineAndWallDetectorRobot(environment);

            Brain = new WallsAndLinesDemoBrain(robot);

            var collector = new LogCollector(Brain, this.LogViewModel);

            this.RobotViewModel = new RobotViewModel(robot);
            RobotImage.Source   = RobotViewModel.Image;

            this.MapViewModel = new MapViewModel();

            FollowLineCommand      = new CommandButtonCommand(Brain, new FollowingLineState(5.0));
            FollowLeftWallCommand  = new CommandButtonCommand(Brain, new FollowingWallOnLeftState());
            FollowRightWallCommand = new CommandButtonCommand(Brain, new FollowingWallOnRightState());
        }
Example #10
0
 public MainViewModel()
 {
     RobotFace = new RobotViewModel();
     RoutesListViewModel = new RoutesListViewModel(RobotFace);
 }
 public async Task <IActionResult> UpdateRobot([FromBody] RobotViewModel vm) => Ok(await new UpdateRobot(_ctx).Do(vm));
Example #12
0
 public ErrandGenerator(RobotViewModel robotViewModel, Random random, HttpClient httpClient) : this(random, httpClient) => _robot = robotViewModel;
Example #13
0
 public GameView(RobotViewModel robotViewModel, int columns, int rows)
 {
     this.DataContext = new GameViewModel(robotViewModel, columns, rows);
     InitializeComponent();
 }