Ejemplo n.º 1
0
 private void Ship_Wrecked(object sender, WreckedSource e)
 {
     _client.CrashPlayer();
     AddPopUpMessage($"A hajó nem tud továbbmenni: {e.GetDescription()}");
 }
Ejemplo n.º 2
0
        public FlightViewModel(GTTcpClient client, PlayerListViewModel playerList, Ship ship)
        {
            ShipCash           = 0;
            _shipPartsLock     = new object();
            _playerOrderLock   = new object();
            _optionsLock       = new object();
            _popupLock         = new object();
            _client            = client;
            _playerList        = playerList;
            _ship              = ship;
            _isWaiting         = false;
            _gameOver          = false;
            CurrentAttributes  = new PlayerAttributes();
            OptionsOrSubEvents = new ObservableCollection <OptionOrSubEventViewModel>();
            ShipParts          = new ObservableCollection <FlightPartViewModel>();
            PopupMessages      = new ObservableCollection <string>();

            foreach (Part p in _ship.Parts)
            {
                ShipParts.Add(new FlightPartViewModel(p));
            }
            foreach (FlightPartViewModel part in ShipParts)
            {
                part.PartClickCommand = new DelegateCommand(param =>
                {
                    if (!_client.Crashed && part.Highlighted && !_gameOver)
                    {
                        _ship.ActivatePartAt(part.Row, part.Column);
                        foreach (FlightPartViewModel item in ShipParts)
                        {
                            if (item.Highlighted)
                            {
                                item.Part.Highlight();
                            }
                        }
                    }
                });
            }

            _client.CardPicked         += Client_CardPicked;
            _client.PlayerCrashed      += Client_PlayerCrashed;
            _client.PlayerTargeted     += Client_PlayerTargeted;
            _client.OtherTargeted      += Client_OtherTargeted;
            _client.CardOver           += Client_CardOver;
            _client.OptionRemoved      += Client_OptionRemoved;
            _client.OptionPicked       += Client_OptionPicked;
            _client.FlightEnded        += Client_FlightEnded;
            _client.GameEnded          += Client_GameEnded;
            _playerList.LostConnection += PlayerList_LostConnection;
            _ship.PartRemoved          += Ship_PartRemoved;
            _ship.Wrecked += Ship_Wrecked;
            _ship.FlightAttributesChanged += Ship_FlightAttributesChanged;
            _ship.CashChanged             += Ship_CashChanged;
            _client.PlacesChanged         += (sender, e) => RefreshTokens();

            SendAttributesCommand = new DelegateCommand(param => !_client.Crashed && RequiresAttributes && !_gameOver, param =>
            {
                RequiresAttributes = false;
                _client.UpdateAttributes(_ship.Firepower, _ship.Enginepower, _ship.CrewCount, _ship.StorageSize, _ship.Batteries);
            });

            CrashCommand = new DelegateCommand(param => !_client.Crashed && !_gameOver, param =>
            {
                MessageBoxResult result = MessageBox.Show("Biztos ki akarsz szállni?",
                                                          "Megerősítés",
                                                          MessageBoxButton.YesNo,
                                                          MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    _client.CrashPlayer();
                }
            });

            ActivatePartCommand = new DelegateCommand(param => !_client.Crashed && _ship.Batteries > 0 && !_gameOver, param =>
            {
                bool any = _ship.HighlightActivatables();
                if (!any)
                {
                    AddPopUpMessage("Nincs aktiválható elem!");
                }
            });

            ReadyCommand = new DelegateCommand(param => !_client.Crashed && _roundResolved && _client.Card.IsResolved() && !_gameOver && !_isWaiting, param =>
            {
                _client.ToggleReady(ServerStage.Flight);
                _roundResolved = false;
                _ship.ResetActivatables();
            });

            ContinueCommand = new DelegateCommand(param => !_client.Crashed && _isWaiting && !_gameOver, param =>
            {
                _isWaiting    = false;
                StatusMessage = "";
                _client.Card.ProceedCurrent();
            });

            Ship_FlightAttributesChanged(null, null);
            InitializeOrderFields();
        }