Ejemplo n.º 1
0
        public void PlayError404(bool switchCards)
        {
            BoardFieldViewModel vm1 = null;
            BoardFieldViewModel vm2 = null;

            if (_selectedField >= 0 && _selectedField < 64)
            {
                vm1 = BoardFieldList[_selectedField];
            }
            if (_secondSelectedField >= 0 && _secondSelectedField < 64)
            {
                vm2 = BoardFieldList[_secondSelectedField];
            }

            var card1     = vm1.Field.Card;
            var card2     = vm2.Field.Card;
            var playerNum = IsPlayerHost ? 1 : 2;

            _parent.CurrentMenu = MenuType.None;

            if (card1?.Owner?.PlayerNumber == playerNum && card2?.Owner?.PlayerNumber == playerNum &&
                card1 is OnlineCard && card2 is OnlineCard)
            {
                SendGameCommand(string.Format("er {0},{1},{2},{3},{4}", vm1.Field.X + 1, vm1.Field.Y + 1, vm2.Field.X + 1, vm2.Field.Y + 1, switchCards ? 1 : 0));
            }
            ClearFieldSelection();
            ClearHighlighting();
        }
Ejemplo n.º 2
0
        public GameViewModel(IMenuHolder parent)
        {
            _parent        = parent;
            BoardFieldList = new List <BoardFieldViewModel>();
            BoardFieldVm   = new BoardFieldViewModel[8, 11];
            Board          = new BoardField[8, 11];
            for (ushort y = 0; y < 11; ++y)
            {
                for (ushort x = 0; x < 8; ++x)
                {
                    Board[x, y] = new BoardField(x, y);
                }
            }

            for (int y = 0; y < 11; ++y)
            {
                for (int x = 0; x < 8; ++x)
                {
                    var model = new BoardFieldViewModel();
                    BoardFieldVm[x, y] = model;
                    BoardFieldList.Add(BoardFieldVm[x, y]);
                }
            }

            _isPlayerHost = true;
            RegisterBoardToViewModel();

            #region Set default visual states

            // Server area p1 is at index 84, p2 at 85

            BoardFieldVm[3, 0].DefaultVisualState = BoardFieldVisualState.Exit;
            BoardFieldVm[4, 0].DefaultVisualState = BoardFieldVisualState.Exit;

            BoardFieldVm[3, 7].DefaultVisualState = BoardFieldVisualState.Exit;
            BoardFieldVm[4, 7].DefaultVisualState = BoardFieldVisualState.Exit;

            // Stack
            BoardFieldVm[0, 8].DefaultVisualState = BoardFieldVisualState.Link; // 64
            BoardFieldVm[1, 8].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[2, 8].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[3, 8].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[4, 8].DefaultVisualState = BoardFieldVisualState.Virus; // 68
            BoardFieldVm[5, 8].DefaultVisualState = BoardFieldVisualState.Virus;
            BoardFieldVm[6, 8].DefaultVisualState = BoardFieldVisualState.Virus;
            BoardFieldVm[7, 8].DefaultVisualState = BoardFieldVisualState.Virus;
            BoardFieldVm[0, 9].DefaultVisualState = BoardFieldVisualState.Link; // 72
            BoardFieldVm[1, 9].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[2, 9].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[3, 9].DefaultVisualState = BoardFieldVisualState.Link;
            BoardFieldVm[4, 9].DefaultVisualState = BoardFieldVisualState.Virus; // 76
            BoardFieldVm[5, 9].DefaultVisualState = BoardFieldVisualState.Virus;
            BoardFieldVm[6, 9].DefaultVisualState = BoardFieldVisualState.Virus;
            BoardFieldVm[7, 9].DefaultVisualState = BoardFieldVisualState.Virus; // 79

            #endregion

            _players    = new PlayerState[2];
            _players[0] = new PlayerState(1);
            _players[1] = new PlayerState(2);
            _client.GameSyncReceived    += GameSyncReceived;
            _players[0].PropertyChanged += PlayerPropChanged;
            _players[1].PropertyChanged += PlayerPropChanged;

            _client.PropertyChanged += (s, a) =>
            {
                var empty = string.IsNullOrEmpty(a.PropertyName);
                if (empty || a.PropertyName == nameof(UID))
                {
                    OnPropertyChanged(nameof(UID));
                }
            };
        }