Пример #1
0
        private void ExecuteSpecialCommand(object obj)
        {
            var cmdName = obj as string;

            if (string.IsNullOrEmpty(cmdName)) return;

            var cmd =
                ((SpecialCommandsView)this._currentDialog).SpecialCommands.FirstOrDefault(x => x.Name.Equals(cmdName));

            if (cmd == null) throw new Exception("Wrong Command!!!");

            var eventResult = cmd.Execute(this._game.CurrentPlayer);

            if (eventResult != null && eventResult.OptionalCommands != null)
            {
                if (this._currentDialog != null) this._currentDialog.Close();

                var dialog = new SpecialCommandsView(eventResult.OptionalCommands);
                this._currentDialog = dialog;
                dialog.ShowDialog();
            }

            if (this._currentDialog != null)
                this._currentDialog.Close();
            this._currentDialog = null;
        }
Пример #2
0
        private void EvalPosition(IPosition newPosition)
        {
            this.CheckOpponent();

            var beforeEvalosition = newPosition;

            IEvalCardsResult cardsResult = null;
            ISpecialEventResult eventResult = null;

            try
            {
                if (newPosition.State == BoardState.Special)
                    eventResult = this._game.Rules.EvalSpecial();
                else if (newPosition.State == BoardState.Cards)
                    cardsResult = this._game.Rules.EvalCards();
                else
                {
                    cardsResult = this._game.Rules.EvalCards();
                    eventResult = this._game.Rules.EvalSpecial();
                }

                if (cardsResult != null)
                {
                    foreach (ICard card in cardsResult.Cards)
                        this.Cards.Add(new CardViewModel(card));
                }

                if (eventResult != null )
                {
                    MessageBox.Show(eventResult.Message, newPosition.Command.Name);

                    this.DiceResults.Clear();

                    foreach (int dice in eventResult.Dices)
                        this.DiceResults.Add(new DiceResult(dice));

                    if (eventResult.OptionalCommands != null)
                    {
                        //MessageBox.Show(eventResult.Message, newPosition.Command.Name);

                        var dialog = new SpecialCommandsView(eventResult.OptionalCommands);
                        this._currentDialog = dialog;
                        dialog.ShowDialog();
                    }
                }

                var afterEvalPosition = this._game.CurrentPlayer.Position;

                if (beforeEvalosition != afterEvalPosition)
                {
                    this.RemovePlayerFromPosition(this._game.CurrentPlayer, beforeEvalosition);
                    this.PutPlayerAtPosition(this._game.CurrentPlayer, afterEvalPosition);
                }

                this.CurrentPlayer.Update();
            }
            catch (PlayerHasNoLifePointsException)
            {
                MessageBox.Show(this._game.CurrentPlayer.Name + " - YOU LOST!");
                this._gameStarted = false;
            }
        }