private void wonder_Click(object sender, RoutedEventArgs e)
        {
            String name = image.Source.ToString();

            String subs = name.Split(',').Last();
            String last = subs.Split('/').Last();

            if (!last.Equals("BackOfWonderCards.png"))//make sure its not the placeholder
            {
                if (player.getPlayedACard() == false && (player.getBoard().getMaxWonderLevel() > player.getWonderCards().Count))
                {
                    if (rm.ValidateWonder(player))
                    {
                        player.getHand().Remove(cardToPlay);//remove from cards in hand of player

                        player.setWonderCards(cardToPlay);
                        player.getBoard().incrementWonderLevel(player);

                        this.Close();
                        PlayerGameBoard play = new PlayerGameBoard(parent, player, rm.getGameState());
                    }
                    else
                    {
                        this.Close();
                        ResourceManager manager = ResourceManager.GetInstance(rm.getGameState());
                        manager.resetResources(player);

                        WonderBuyingWindow window = new WonderBuyingWindow(ResourceManager.GetInstance().GetCombinedResources(player), cardToPlay, view, rm.getGameState());
                        window.Show();
                    }
                }
            }
        }
Esempio n. 2
0
//Mouse Click for "Add to Wonder" Button
        public void wonderCardButton_Click(object sender, EventArgs e)
        {
            if (player.getPlayedACard() == false && (player.getBoard().getMaxWonderLevel() > player.getWonderCards().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)
                    {
                        if (img.Source != new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Images/EmptyCard.png", UriKind.RelativeOrAbsolute));

                                Image           imgl = (Image)playBoard.Children[91];
                                PlayerGameBoard play = new PlayerGameBoard(parent, player, game);
                            }
                            else
                            {
                                ResourceManager manager = ResourceManager.GetInstance(game);
                                manager.resetResources(player);

                                WonderBuyingWindow window = new WonderBuyingWindow(ResourceManager.GetInstance().GetCombinedResources(player), c, this, game);
                                window.Show();
                            }
                        }
                    }
                }
            }
        }
// 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.ValidateWonder(you)) //ok check if you can play the card now.
                {
                    you.getHand().Remove(card);  //remove from cards in hand of player
                    you.setPlayedACard();        //set true
                    you.setWonderCards(card);

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

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

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

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

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

                    if (manager.ValidateWonder(you)) //ok check if you can play the card now.
                    {
                        you.getHand().Remove(card);  //remove from cards in hand of player
                        you.setPlayedACard();        //set true
                        you.setWonderCards(card);
                        you.getBoard().incrementWonderLevel(you);
                        manager.getGameState().incrementTurn();
                        this.Close();
                        PlayerGameBoard play = new PlayerGameBoard(board.getGrid(), you, manager.getGameState());
                    }
                    else
                    {
                        this.Close();

                        WonderBuyingWindow window = new WonderBuyingWindow(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.ValidateWonder(you)) //ok check if you can play the card now.
                    {
                        you.getHand().Remove(card);  //remove from cards in hand of player
                        you.setPlayedACard();        //set true
                        you.setWonderCards(card);
                        you.getBoard().incrementWonderLevel(you);
                        manager.getGameState().incrementTurn();
                        this.Close();
                        PlayerGameBoard play = new PlayerGameBoard(board.getGrid(), you, manager.getGameState());
                    }
                    else
                    {
                        this.Close();

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