Exemplo n.º 1
0
        public DefaultApp()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var notifiableView = new NotifiableGameView();;

            this.view = notifiableView;
            var board = new SquareBoard(4);
            var game  = new Game(notifiableView, board);

            this.controller = new DefaultGameController(game);
            mainWindow      = new Window(view, controller);
            mainWindow.SetEventOnNewImageSelected(ChangePuzzleImage);

            var outputControl = FindControl(boardOutputControlName);
            var defaultImage  = Image.FromFile(defaultImagePath);
            var cellFactory   = new BoardCellFactory(controller, defaultImage);

            this.boardRenderer = new BoardRenderer(outputControl, board, cellFactory);
            view.SetEventOnCellMoved(boardRenderer.SwapCells);
            view.SetEventOnBoardChanged(boardRenderer.Render);

            boardRenderer.Render(board);
        }
Exemplo n.º 2
0
        private void ChangePuzzleImage(string path)
        {
            Image image = null;

            try
            {
                image = Image.FromFile(path);
            }
            catch (Exception e)
            {
                //do nothing if the path is invalid
                return;
            }

            var cellFactory = new BoardCellFactory(controller, image);

            boardRenderer.SetCellFactory(cellFactory);
            boardRenderer.Render();
        }
Exemplo n.º 3
0
 public void SetCellFactory(BoardCellFactory cellFactory)
 {
     this.cellFactory = cellFactory;
 }
Exemplo n.º 4
0
 public BoardRenderer(Control outputControl, SquareBoard board, BoardCellFactory cellFactory)
 {
     this.outputControl = outputControl;
     this.board         = board;
     this.cellFactory   = cellFactory;
 }