예제 #1
0
        // Handler for when a light is clicked
        public ActionResult ClickLight(int id)
        {
            // Get the service object and call the method to set the selected light
            var lightsSrv = new LightsOutService(statefulService);

            lightsSrv.SetLight(id);

            // Redirect back to the main controller
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public void TestGridInit()
        {
            // gird is 5 by 5 as default, expect grid size to equal 25
            int expectedGridSize = 25;

            LightsOutService lightsOutService = new LightsOutService(_statefulService);

            var grid = lightsOutService.GetGrid();

            Assert.AreEqual(expectedGridSize, grid.Count());
        }
예제 #3
0
        private const int GridSize = 5; // Could be passed in from the UI

        // Main controller for the game
        public ActionResult Index()
        {
            // Create the game service
            var lightsSrv = new LightsOutService(statefulService, GridSize);

            // Create the viewmodel
            LightsOutViewModel lightsOutViewModel = new LightsOutViewModel
            {
                GridSize    = GridSize,
                LightModels = lightsSrv.GetGrid()
            };

            return(View(lightsOutViewModel));
        }
예제 #4
0
        public void TestSetLight()
        {
            // gird is 5 by 5 as default, setting light 7, expect 7, 2, 6, 8, 12 to be on

            LightsOutService lightsOutService = new LightsOutService(_statefulService, 5, 0);

            lightsOutService.SetLight(7);

            var grid = lightsOutService.GetGrid();

            var grid7  = grid.Single(gr => gr.LightModelId == 7);
            var grid2  = grid.Single(gr => gr.LightModelId == 2);
            var grid6  = grid.Single(gr => gr.LightModelId == 6);
            var grid8  = grid.Single(gr => gr.LightModelId == 8);
            var grid12 = grid.Single(gr => gr.LightModelId == 12);

            Assert.IsTrue(grid7.On);
            Assert.IsTrue(grid2.On);
            Assert.IsTrue(grid6.On);
            Assert.IsTrue(grid8.On);
            Assert.IsTrue(grid12.On);
        }