コード例 #1
0
        public ObservableBoardHistory(BoardHistory boardHistory, BoardHistory activeBoardHistory = null, Action <int> moveNumberChangedCallback = null)
        {
            _boardHistory              = boardHistory ?? throw new ArgumentNullException(nameof(boardHistory));
            _activeBoardHistory        = activeBoardHistory ?? boardHistory;
            _moveNumberChangedCallback = moveNumberChangedCallback;

            if (_activeBoardHistory.Count > _boardHistory.Count)
            {
                throw new ArgumentException("Active history has more moves than history.");
            }

            int countWidth = _boardHistory.Count.ToString().Length;

            for (int i = 0; i < _boardHistory.Count; i++)
            {
                BoardHistoryItem item = _boardHistory[i];

                string countString = (i + 1).ToString().PadLeft(countWidth) + ". ";
                string moveString  = AppVM.ViewerConfig.NotationType == NotationType.BoardSpace ? NotationUtils.NormalizeBoardSpaceMoveString(item.MoveString) : item.ToString();

                bool isActive   = i < _activeBoardHistory.Count;
                bool isLastMove = i + 1 == _activeBoardHistory.Count;

                Items.Add(new ObservableBoardHistoryItem(countString + moveString, isActive, isLastMove));
            }
        }
コード例 #2
0
        public void MoveToMoveNumber(int moveNum)
        {
            if (CurrentGameSettings.GameMode != GameMode.Review)
            {
                throw new Exception("Please switch the current game to review mode first.");
            }

            if (moveNum == 0)
            {
                MoveToStart();
            }
            else if (moveNum == ReviewBoard.BoardHistory.Count)
            {
                MoveToEnd();
            }
            else
            {
                GameBoard newGame = new GameBoard(ReviewBoard.ExpansionPieces);

                for (int i = 0; i < moveNum; i++)
                {
                    BoardHistoryItem item = ReviewBoard.BoardHistory[i];
                    newGame.TrustedPlay(item.Move, item.MoveString);
                }

                SendCommand("newgame {0}", newGame.ToGameString());
            }
        }
コード例 #3
0
ファイル: ViewerBoard.cs プロジェクト: Khaleesh/Mzinga
        public void SimulateUndo(BoardHistoryItem item)
        {
            if (!item.Move.IsPass)
            {
                Piece targetPiece = GetPiece(item.Move.PieceName);
                MovePiece(targetPiece, item.OriginalPosition);
            }

            CurrentTurn--;

            BoardUpdated();
        }
コード例 #4
0
        public void MoveForward()
        {
            if (CurrentGameSettings.GameMode != GameMode.Review)
            {
                throw new Exception("Please switch the current game to review mode first.");
            }

            int targetMoveIndex = Board.BoardHistory.Count;

            BoardHistoryItem targetItem = ReviewBoard.BoardHistory[targetMoveIndex];

            SendCommand("play {0}", targetItem.MoveString);
        }