// 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(); } } } }