//Mouse Click for "Play Card" button
        public void playerMoveButton_Click(object sender, EventArgs e)
        {
            if (player.getPlayedACard() == false)
            {
                int numCards = player.getHand().Count;

                for (int i = 0; i < player.getHand().Count; i++)
                {
                    Card  c   = player.getHand()[i];
                    Image img = (Image)playBoard.Children[(56 + i)];

                    if (img.ActualHeight > 150)//this is the selected card
                    {
                        if (img.Source != new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Images/EmptyCard.png", UriKind.RelativeOrAbsolute));
                                PlayerGameBoard play = new PlayerGameBoard(parent, player, game);
                            }
                            else
                            {
                                ResourceManager manager = ResourceManager.GetInstance(game);
                                manager.resetResources(player);

                                ResourceBuying window = new ResourceBuying(ResourceManager.GetInstance().GetCombinedResources(player), c, this, game);
                                window.Show();
                            }
                        }
                    }
                }
            }
        }
        private void buttonPlay_Click(object sender, RoutedEventArgs e)
        {
            if (rm.ValidateCard(player, cardToPlay))
            {
                player.addPlayedCards(cardToPlay);
                this.Close();
                PlayerGameBoard play = new PlayerGameBoard(parent, player, rm.getGameState());
            }
            else
            {
                this.Close();
                ResourceManager manager = ResourceManager.GetInstance(rm.getGameState());
                manager.resetResources(player);

                ResourceBuying window = new ResourceBuying(ResourceManager.GetInstance().GetCombinedResources(player), cardToPlay, view, rm.getGameState());
                window.Show();
            }
        }
Exemple #3
0
// This button click handler finds which button you pressed and then modifies the appropriate
// Player resources as well calling methods for removing and adding money
// B[1,7] = YOU, B[8,14] = LEFT, B[15-21] = RIGHT
        private void buyButton_Click(object sender, RoutedEventArgs e)
        {
            Button b    = (Button)sender;
            string name = b.Name;//have button name will travel

            int index;

            if (name.Length > 2)
            {
                index = ((int)Char.GetNumericValue(name[1]) * 10) + (int)Char.GetNumericValue(name[2]);
            }
            else
            {
                index = (int)Char.GetNumericValue(name[1]);//know which number
            }

            if (index > 0 && index < 8)//Player clicked on YOU
            {
                manager.usingSpecialResource(you, (index - 1));
                resources = manager.GetCombinedResources(you);

                if (manager.ValidateCard(you, card)) //ok check if you can play the card now.
                {
                    you.addPlayedCards(card);        //add to the playerState
                    board.changeCard(card);          //adds to the board cards
                    you.setPlayedACard();            //set true
                    you.getHand().Remove(card);      //remove from cards in hand of player


                    manager.getGameState().incrementTurn();
                    this.Close();
                    PlayerGameBoard play = new PlayerGameBoard(board.getGrid(), you, manager.getGameState());
                }
                else
                {
                    this.Close();

                    ResourceBuying window = new ResourceBuying(resources, card, board, game);
                    window.Show();
                }
            }

            if (index > 7 && index < 15)//Player clicked on LEFT
            {
                int i = (index - 8);

                if (manager.canAfford(you))
                {
                    Canvas c = (Canvas)board.getGrid().Children[1];
                    Label  l = (Label)c.Children[90];
                    l.Content = " " + manager.getTempCoins(you);

                    Console.WriteLine("YOU current money: " + you.getCoins());
                    manager.tradeTo(you, i, 0);
                    resources = manager.GetCombinedResources(you);

                    if (manager.ValidateCard(you, card)) //ok check if you can play the card now.
                    {
                        you.addPlayedCards(card);        //add to the playerState
                        board.changeCard(card);          //adds to the board cards
                        you.setPlayedACard();            //set true
                        you.getHand().Remove(card);      //remove from cards in hand of player

                        manager.getGameState().incrementTurn();
                        this.Close();
                        PlayerGameBoard play = new PlayerGameBoard(board.getGrid(), you, manager.getGameState());
                    }
                    else
                    {
                        this.Close();
                        ResourceBuying window = new ResourceBuying(resources, card, board, game);
                        window.Show();
                    }
                }
            }

            if (index > 14 && index < 22) //Player clicked on RIGHT
            {
                int i = (index - 15);     //0-6 the resource traded

                if (manager.canAfford(you))
                {
                    Canvas c = (Canvas)board.getGrid().Children[1];
                    Label  l = (Label)c.Children[90];
                    l.Content = " " + manager.getTempCoins(you);

                    manager.tradeTo(you, i, 1);
                    resources = manager.GetCombinedResources(you);

                    if (manager.ValidateCard(you, card)) //ok check if you can play the card now.
                    {
                        you.addPlayedCards(card);        //add to the playerState
                        board.changeCard(card);          //adds to the board cards
                        you.setPlayedACard();            //set true
                        you.getHand().Remove(card);      //remove from cards in hand of player

                        manager.getGameState().incrementTurn();
                        this.Close();
                        PlayerGameBoard playt = new PlayerGameBoard(board.getGrid(), you, manager.getGameState());
                    }
                    else
                    {
                        this.Close();
                        ResourceBuying window = new ResourceBuying(resources, card, board, game);
                        window.Show();
                    }
                }
            }
        }