//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 bool TradeCard(PlayerState p, Card c) { int trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(true); } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(true); } return(false); }
//please the primary card for the type baes AIs public Card playPrimary(PlayerState p, List <Card> hand) { int trade; for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == strategy) { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return(hand[i]); } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return(hand[i]); } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return(hand[i]); } } } return(null); }
public Card playAnyCard(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count; i++) { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return(hand[i]); } } return(null); }
//please the primary card for the type baes AIs public Card playPrimary(PlayerState p, List<Card> hand) { int trade; for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == strategy) { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return hand[i]; } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return hand[i]; } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return hand[i]; } } } return null; }
//plays a resource or commodity public Card playSecondary(PlayerState p, List<Card> hand) { for (int i = 0; i < hand.Count; i++) { if ((hand[i].getType() == 1) && (ResourceManager.GetInstance().ValidateCard(p, hand[i]))) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return hand[i]; } } for (int i = 0; i < hand.Count; i++) { if ((hand[i].getType() == 2) && (ResourceManager.GetInstance().ValidateCard(p, hand[i]))) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return hand[i]; } } return null; }
private void buttonPlay_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 { player.addPlayedCards(cardToPlay); //add to the playerState discards.Remove(cardToPlay); //remove the card from discards rm.getGameState().incrementTurn(); this.Close(); //now redraw the window PlayerGameBoard play = new PlayerGameBoard(parent, player, rm.getGameState()); } }
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(); } }
private Card SetCivilianStrategy(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (noOfPlayers == 3 || noOfPlayers == 7) { if (hand[i].getName() == "C22" || hand[i].getName() == "C23" || hand[i].getName() == "C63" || hand[i].getName() == "C64") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 3 || noOfPlayers == 6) { if (hand[i].getName() == "C24" || hand[i].getName() == "C25" || hand[i].getName() == "C108" || hand[i].getName() == "C109") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } } int vc = 0, index = 0; for (int i = 0; i < hand.Count(); i++) { if (hand[i] is CivilianCard) { CivilianCard c = (CivilianCard)hand[i]; if (c.getVictoryPoints() > vc) { vc = c.getVictoryPoints(); index = i; } } } if (index != 0) { if (ResourceManager.GetInstance().ValidateCard(p, hand[index])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[index]); return(hand[index]); } } return(null); }
private Card SetCommerceStrategy(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getName() == "C0123" || hand[i].getName() == "C0124") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } if (noOfPlayers == 3) { if (hand[i].getName() == "C031" || hand[i].getName() == "CO33" || hand[i].getName() == "CO71" || hand[i].getName() == "CO74" || hand[i].getName() == "CO77" || hand[i].getName() == "CO121" || hand[i].getName() == "CO125") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 4) { if (hand[i].getName() == "C028" || hand[i].getName() == "CO79" || hand[i].getName() == "C0120") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 5) { if (hand[i].getName() == "C029" || hand[i].getName() == "CO75" || hand[i].getName() == "C0126") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 6) { if (hand[i].getName() == "C036" || hand[i].getName() == "CO72" || hand[i].getName() == "C076" || hand[i].getName() == "CO78" || hand[i].getName() == "C0122" || hand[i].getName() == "C0124") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 7) { if (hand[i].getName() == "C030" || hand[i].getName() == "C032" || hand[i].getName() == "C034" || hand[i].getName() == "C032" || hand[i].getName() == "C073" || hand[i].getName() == "C080" || hand[i].getName() == "C0127") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } /*if (TradeCard(p, hand[i])) * return hand[i];*/ } return(null); }
// 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(); } } } }
public Card getNextCard(PlayerState p, List <Card> hand) { List <CivilianCard> civCards = new List <CivilianCard>(); for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == 3) { System.Console.WriteLine("CivilianStrategy():: getNextCard({0})", hand[i]); civCards.Add((CivilianCard)hand[i]); } } // && (ResourceManager.GetInstance().ValidateCard(p, hand[i])) int trade; while (civCards.Count != 0) { CivilianCard bestCard = civCards[0]; for (int i = 1; i < civCards.Count; i++) { if (bestCard.getVictoryPoints() < civCards[i].getVictoryPoints()) { bestCard = civCards[i]; } } if (ResourceManager.GetInstance().ValidateCard(p, bestCard)) { p.addPlayedCards(bestCard); return(bestCard); } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(bestCard); return(bestCard); } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(bestCard); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return(bestCard); } civCards.Remove(bestCard); } Card cur = ult.playSecondary(p, hand); if (cur != null) { return(cur); } cur = ult.buildWonder(p, hand); if (cur != null) { return(cur); } return(ult.playAnyCard(p, hand)); }
public Card getNextCard(PlayerState p, List<Card> hand) { List<CivilianCard> civCards = new List<CivilianCard>(); for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == 3) { System.Console.WriteLine("CivilianStrategy():: getNextCard({0})", hand[i]); civCards.Add((CivilianCard)hand[i]); } } // && (ResourceManager.GetInstance().ValidateCard(p, hand[i])) int trade; while (civCards.Count != 0) { CivilianCard bestCard = civCards[0]; for (int i = 1; i < civCards.Count; i++) { if (bestCard.getVictoryPoints() < civCards[i].getVictoryPoints()) { bestCard = civCards[i]; } } if (ResourceManager.GetInstance().ValidateCard(p, bestCard)) { p.addPlayedCards(bestCard); return bestCard; } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(bestCard); return bestCard; } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(bestCard); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return bestCard; } civCards.Remove(bestCard); } Card cur = ult.playSecondary(p, hand); if (cur != null) { return cur; } cur = ult.buildWonder(p, hand); if (cur != null) { return cur; } return ult.playAnyCard(p, hand); }
private Card SetCivilianStrategy(PlayerState p, List<Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (noOfPlayers == 3 || noOfPlayers == 7) if (hand[i].getName() == "C22" || hand[i].getName() == "C23" || hand[i].getName() == "C63" || hand[i].getName() == "C64") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } if (noOfPlayers == 3 || noOfPlayers == 6) if (hand[i].getName() == "C24" || hand[i].getName() == "C25" || hand[i].getName() == "C108" || hand[i].getName() == "C109") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } int vc = 0, index = 0; for (int i = 0; i < hand.Count(); i++) { if (hand[i] is CivilianCard) { CivilianCard c = (CivilianCard)hand[i]; if (c.getVictoryPoints() > vc) { vc = c.getVictoryPoints(); index = i; } } } if (index != 0) if (ResourceManager.GetInstance().ValidateCard(p, hand[index])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[index]); return hand[index]; } return null; }
private bool TradeCard(PlayerState p, Card c) { int trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return true; } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(c); return true; } return false; }
private Card SetCommerceStrategy(PlayerState p, List<Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getName() == "C0123" || hand[i].getName() == "C0124") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } if (noOfPlayers == 3) { if (hand[i].getName() == "C031" || hand[i].getName() == "CO33" || hand[i].getName() == "CO71" || hand[i].getName() == "CO74" || hand[i].getName() == "CO77" || hand[i].getName() == "CO121" || hand[i].getName() == "CO125") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } if (noOfPlayers == 4) { if (hand[i].getName() == "C028" || hand[i].getName() == "CO79" || hand[i].getName() == "C0120") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } if (noOfPlayers == 5) { if (hand[i].getName() == "C029" || hand[i].getName() == "CO75" || hand[i].getName() == "C0126") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } if (noOfPlayers == 6) { if (hand[i].getName() == "C036" || hand[i].getName() == "CO72" || hand[i].getName() == "C076" || hand[i].getName() == "CO78" || hand[i].getName() == "C0122" || hand[i].getName() == "C0124") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } if (noOfPlayers == 7) { if (hand[i].getName() == "C030" || hand[i].getName() == "C032" || hand[i].getName() == "C034" || hand[i].getName() == "C032" || hand[i].getName() == "C073" || hand[i].getName() == "C080" || hand[i].getName() == "C0127") if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return hand[i]; } } if (TradeCard(p, hand[i])) return hand[i]; } return null; }
public Card getNextCard(PlayerState p, List<Card> hand) { Random random = new Random(); int randomNumber; Card c = null; if (ResourceManager.GetInstance().ValidateWonder(p)) { randomNumber = random.Next(0, 2); Console.WriteLine("attempting to play wonder " + randomNumber); if (randomNumber == 1) { Console.WriteLine("playing wonder " + randomNumber); randomNumber = random.Next(0, hand.Count - 1); c = hand[randomNumber]; p.setWonderCards(c); p.getBoard().incrementWonderLevel(p); } } List<int> availCards = new List<int>(); for (int i = 0; i < hand.Count; i++) { availCards.Add(i); } int trade; //selects a card to play for (int i = 0; i < hand.Count; i++) { randomNumber = random.Next(0, availCards.Count - 1); c = hand[availCards[randomNumber]]; if (ResourceManager.GetInstance().ValidateCard(p, c)) { p.addPlayedCards(c); return c; //Console.WriteLine("===================== CHECKED CARD ==========================="); } trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return c; } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(c); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return c; } availCards.Remove(randomNumber); //Console.Write("RANDOM STRATEGY:: AGE :: "); //Console.WriteLine(ResourceManager.GetInstance().getGameState().getAge()); } return null; }
public Card getNextCard(PlayerState p, List <Card> hand) { Random random = new Random(); int randomNumber; Card c = null; if (ResourceManager.GetInstance().ValidateWonder(p)) { randomNumber = random.Next(0, 2); Console.WriteLine("attempting to play wonder " + randomNumber); if (randomNumber == 1) { Console.WriteLine("playing wonder " + randomNumber); randomNumber = random.Next(0, hand.Count - 1); c = hand[randomNumber]; p.setWonderCards(c); p.getBoard().incrementWonderLevel(p); } } List <int> availCards = new List <int>(); for (int i = 0; i < hand.Count; i++) { availCards.Add(i); } int trade; //selects a card to play for (int i = 0; i < hand.Count; i++) { randomNumber = random.Next(0, availCards.Count - 1); c = hand[availCards[randomNumber]]; if (ResourceManager.GetInstance().ValidateCard(p, c)) { p.addPlayedCards(c); return(c); //Console.WriteLine("===================== CHECKED CARD ==========================="); } trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(c); } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(c); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return(c); } availCards.Remove(randomNumber); //Console.Write("RANDOM STRATEGY:: AGE :: "); //Console.WriteLine(ResourceManager.GetInstance().getGameState().getAge()); } return(null); }