示例#1
0
        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);
        }
示例#2
0
        public HistoryView(GameView gameView)
        {
            InitializeComponent();
            _game = gameView.Game;

            _gameView      = gameView;
            _realBoardView = gameView.UcBoardView.Content as BoardView;
            _conversation  = new HistoryViewConversation();

            foreach (var command in _game.Container.Moves)
            {
                var momand = command.Copy(_board);
                _conversation.Execute(momand);
                _moves.Add(momand);
            }

            _game.Container.Moves.CollectionChanged += (sender, args) =>
            {
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                {
                    if (args.NewItems[args.NewItems.Count - 1] is ICompensableCommand command)
                    {
                        command = command.Copy(_board);
                        _conversation.Execute(command);
                        _moves.Add(command);
                    }

                    break;
                }

                case NotifyCollectionChangedAction.Remove:
                    _moves.RemoveAt(_moves.Count - 1);
                    _conversation.Undo();
                    break;
                }
            };

            _boardView = new BoardView(new Container(_board, _moves));
            ListViewHistory.ItemsSource = _moves;
        }