Ejemplo n.º 1
0
        private void buttonConfirm_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            Card7Results card7Results = Card7Results.Instance;

            card7Results.pawn1MoveValue = pawn1MoveValue;
            card7Results.pawn2MoveValue = pawn2MoveValue;
            this.Close();
        }
Ejemplo n.º 2
0
        private void DrawCardButton_Click(object sender, RoutedEventArgs e)
        {
            // Draw a card from the deck
            this.sorryBoard.CurrentPlayer.AdditionalTurn = false;
            int playerCard = this.sorryBoard.CurrentPlayer.DrawCard(this.sorryBoard.CardDeck);

            this.sorryBoard.CurrentPlayer.CurrentCardNumber = playerCard;
            this.sorryBoard.CurrentPlayer.HasDrawnCard      = true;

            // The 2 card gives the player another turn whether that player has a valid move or not
            if (this.sorryBoard.CardDeck.Cards[playerCard].MoveValue == 2)
            {
                this.sorryBoard.CurrentPlayer.AdditionalTurn = true;
            }

            // Determine whether any pawn can be moved
            bool hasMoveablePawn = false;

            foreach (Pawn pawn in this.sorryBoard.CurrentPlayer.Pawns)
            {
                if (CanBeMoved(pawn))
                {
                    hasMoveablePawn = true;
                }
            }

            if (!hasMoveablePawn)
            {
                // The player can't move any of their pawns. Show which card was drawn and end the turn
                messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                              this.sorryBoard.CardDeck.Cards[playerCard].CannotMove();
                EndTurn();
            }
            else
            {
                this.sorryBoard.CurrentPlayer.HasDrawnCard = true;
                // Show which card was drawn
                messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                              this.sorryBoard.CardDeck.Cards[playerCard].CanMove();

                if (11 == sorryBoard.CardDeck.Cards[playerCard].MoveValue)
                {
                    // eleven properties
                    Window card11Window = new Card11Prompt();
                    if (!IsOpponentOnBoard())
                    {
                        Button swapButton = (Button)card11Window.FindName("swapButton");
                        swapButton.IsEnabled = false;
                    }
                    this.sorryBoard.CurrentPlayer.CardChoice = card11Window.ShowDialog();

                    if (this.sorryBoard.CurrentPlayer.CardChoice == false)
                    {
                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select a pawn to move eleven spaces";
                    }
                    else
                    {
                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select your pawn that you want to swap";
                    }
                }
                else if (10 == sorryBoard.CardDeck.Cards[playerCard].MoveValue)
                {
                    // ten properties
                    Window card10Window = new Card10Prompt();
                    this.sorryBoard.CurrentPlayer.CardChoice = card10Window.ShowDialog();

                    if (this.sorryBoard.CurrentPlayer.CardChoice == false)
                    {
                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select a pawn to move ten spaces";
                    }
                    else
                    {
                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select a pawn to move back one space";
                    }
                }
                else if (7 == sorryBoard.CardDeck.Cards[playerCard].MoveValue)
                {
                    // seven properties
                    Window card7Window = new Card7Prompt();
                    this.sorryBoard.CurrentPlayer.CardChoice = null;
                    if (HasOnePawn())
                    {
                        Button splitButton = (Button)card7Window.FindName("splitButton");
                        splitButton.IsEnabled = false;
                    }
                    this.sorryBoard.CurrentPlayer.CardChoice = card7Window.ShowDialog();

                    if (this.sorryBoard.CurrentPlayer.CardChoice == false)
                    {
                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select a pawn to move seven spaces";
                    }
                    else
                    {
                        bool?isChoiceMade;
                        do
                        {
                            Window card7Choices = new Card7Choices();
                            isChoiceMade = card7Choices.ShowDialog();
                        } while (isChoiceMade == false);
                        Card7Results card7Results = Card7Results.Instance;
                        this.sorryBoard.CurrentPlayer.Pawn1Split = card7Results.pawn1MoveValue;
                        this.sorryBoard.CurrentPlayer.Pawn2Split = card7Results.pawn2MoveValue;

                        messageCenterTextBlock.Text = this.sorryBoard.CurrentPlayer.Name +
                                                      ", select your first pawn to move " + this.sorryBoard.CurrentPlayer.Pawn1Split + " spaces";
                    }
                }

                // Disable the draw card button until the turn is over
                drawCardButton.IsEnabled = false;
            }
        }