Exemple #1
0
        public GameView(MainWindow mainWindow, Core.Game game, BoardView boardView)
        {
            InitializeComponent();
            _mainWindow = mainWindow;
            _boardView  = boardView;
            Game        = game;

            game.PlayerDisconnectedEvent += GameOnPlayerDisconnectedEvent;

            game.StateChanged += _boardView.GameStateChanged;

            game.StateChanged += state =>
            {
                switch (state)
                {
                case BoardState.BlackCheckMate:
                    _mainWindow.ShowMessageAsync("Fin de la partie", "Le joueur noir est echec et mat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.WhiteCheckMate:
                    _mainWindow.ShowMessageAsync("Fin de la partie", "Le joueur blanc est echec et mat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.BlackPat:
                    _mainWindow.ShowMessageAsync("Match nul", "Le joueur noir est pat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.WhitePat:
                    _mainWindow.ShowMessageAsync("Match nul", "Le joueur blanc est pat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;
                }
            };

            //Création et ajout du contenu du PLS pour cette vue
            GameViewFlyout gameViewFlyout = new GameViewFlyout(this);

            _mainWindow.Flyout.Content = gameViewFlyout.Content;
            UcBoardView.Content        = boardView;

            game.Container.MoveDone += move =>
            {
                LabelPlayerTurn.Content = move.PieceColor == Color.Black ? "Blanc" : "Noir";
            };

            game.Container.MoveUndone += move =>
            {
                LabelPlayerTurn.Content = move.PieceColor == Color.Black ? "Blanc" : "Noir";
            };

            HistoryView.Content = new HistoryView(this);
        }
        public GameView(MainWindow mainWindow, Backend.Core.Game game, BoardView boardView)
        {
            InitializeComponent();

            _mainWindow = mainWindow;
            Game        = game;

            game.StateChanged += boardView.GameStateChanged;

            game.StateChanged += state =>
            {
                switch (state)
                {
                case BoardState.BlackCheckMate:
                    _mainWindow.ShowMessageAsync("Game finished", "White wins! Black is check mate.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.WhiteCheckMate:
                    _mainWindow.ShowMessageAsync("Game finished", "Black wins! White is check mate.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.BlackPat:
                    _mainWindow.ShowMessageAsync("Pat", "The player black is pat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;

                case BoardState.WhitePat:
                    _mainWindow.ShowMessageAsync("Pat", "The player white is pat.",
                                                 MessageDialogStyle.AffirmativeAndNegative);
                    break;
                }
            };

            //Création et ajout du contenu du PLS pour cette vue
            var gameViewFlyout = new GameViewFlyout(this);

            _mainWindow.Flyout.Content = gameViewFlyout.Content;
            UcBoardView.Content        = boardView;

            game.Container.MoveDone += move =>
            {
                LabelPlayerTurn.Content = move.PieceColor == Color.Black ? Color.White.ToString() : Color.Black.ToString();
            };

            game.Container.MoveUndone += move =>
            {
                LabelPlayerTurn.Content = move.PieceColor == Color.Black ? Color.White.ToString() : Color.Black.ToString();
            };

            HistoryView.Content = new HistoryView(this);
        }