public void CheckingCoins(PlayerState p, Card c) { if (Log(p)) Console.WriteLine("[{0}] Checking to see if we have enough coins: Cost {1} Has {2}" , _class.GetType().Name , c.getCoinCost() , p.getCoins()); }
public int calcCommerceIncome(Card playedCard, GameState gs, int playerId) { PlayerState thePlayer = gs.getPlayerNum(playerId); //System.Console.WriteLine(playedCard.getNumber()); if (!playedCard.getName().StartsWith("CO")) { return 0; } if(playedCard.GetType() != typeof(CommerceCard)) { return 0; } CommerceCard commCard = (CommerceCard)playedCard; if (commCard.getCoins() != 0) { return commCard.getCoins(); } if ((commCard.getNumber().Equals(77)) || (commCard.getNumber().Equals(78))) { return countCardType(1, thePlayer) + countCardType(1, gs.getLeftPlayer(thePlayer)) + countCardType(1, gs.getRightPlayer(thePlayer)); } if ((commCard.getNumber().Equals(80)) || (commCard.getNumber().Equals(79))) { return countCardType(2, thePlayer) + countCardType(2, gs.getLeftPlayer(thePlayer)) + countCardType(2, gs.getRightPlayer(thePlayer)); } //Haven if ((commCard.getNumber().Equals(119)) || (commCard.getNumber().Equals(120))) { return countCardType(1, thePlayer); } //LightHouse if ((commCard.getNumber().Equals(121)) || (commCard.getNumber().Equals(122))) { return countCardType(4, thePlayer); } //Chamber of Commerce if ((commCard.getNumber().Equals(123)) || (commCard.getNumber().Equals(124))) { return 2 * countCardType(2, thePlayer); } //Arena if ((commCard.getNumber().Equals(125)) || (commCard.getNumber().Equals(126)) || (commCard.getNumber().Equals(127))) { return 3 * thePlayer.getBoard().getCurrentWonderLevel(); } return 0; }
public ResourceBuying(Resources res, Card c, PlayerGameBoard p) { rc = res; card = c; board = p; you = rm.getGameState().getPlayerNum(rc.getPlayerName()[1]); InitializeComponent(); createButtons(); createValueFields(); }
public WonderBuyingWindow(Resources res, Card c, PlayerGameBoard p, GameState g) { resources = res; card = c; board = p; game = g; manager = ResourceManager.GetInstance(); you = manager.getGameState().getPlayerNum(resources.getPlayerName()[1]); InitializeComponent(); createButtons(); createValueFields(); }
public bool ValidateCard (PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //Get a list of preCards int[] preCard = c.getPreCard(); //Go through list of preCards for (int i = 0; i < preCard.Length; i++) { //Check if preCard Value is valid if (preCard[i] < 150) { //cycle through player's playedcards for (int j = 0; j < p.getPlayedCards().Count; j++) {//if the cards match then return true if (p.getPlayedCards()[j].getNumber() == preCard[i]) { return true; } } } } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return true; } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return true; } return false; } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return CheckResourceCost(p,c); } return false; }
public CardCostCheck(GameState g, PlayerState p, Card c): base (g,p) { coinTransactions = new int[3] { 0, 0, 0 }; //Getting left and right player of player P left = g.getLeftPlayer(p); right = g.getRightPlayer(p); //Initialize base resources baseResources = ResourceInitializer(p); lResources = ResourceInitializer(left); rResources = ResourceInitializer(right); //List of important resource cards SRCardLst = SRCardInitializer(p); lSRCardLst = SRCardInitializer(left); rSRCardLst = SRCardInitializer(right); }
public ResourceBuying(Resources res, Card c, PlayerGameBoard p, GameState g) { resources = res; //Console.WriteLine(resources.ToString()); card = c; board = p; game = g; manager = ResourceManager.GetInstance(); you = manager.getGameState().getPlayerNum(resources.getPlayerName()[1]); InitializeComponent(); createButtons(); createValueFields(); }
/* * Input: A Player and a Card * * * Output: True or False -> Can the player play this card for free? If they have correct pre-card -> True */ private bool preCardCheck(PlayerState p, Card c) { //Get a list of preCards int[] preCard = c.getPreCard(); //Go through list of preCards for (int i = 0; i < preCard.Length; i++) { //Check if preCard Value is valid if (preCard[i] < 150) { //cycle through player's playedcards for (int j = 0; j < p.getPlayedCards().Count; j++) {//if the cards match then return true if (p.getPlayedCards()[j].getNumber() == preCard[i]) { return true; } } } } return false; }
//preCardCheck checks if the player p has the prerequisite card for free play protected bool preCardCheck(Card c, PlayerState p) { //Get a list of preCards int[] preCard = c.getPreCard(); //Go through list of preCards console.writeline(preCard[0] + " " + preCard[1] + " " + preCard[2] + " " + preCard[3]); for (int i = 0; i < preCard.Length; i++) { //Check if preCard Value is valid if (preCard[i] > 150) { //cycle through player's playedcards for (int j = 0; j < p.getPlayedCards().Count; j++) {//if the cards match then return true if (p.getPlayedCards()[j].getNumber() == preCard[i]) { return true; } } } } //else return false return false; }
public void UpdatingPlayersResources(PlayerState p, Card c) { if (Log(p)) System.Console.WriteLine( "[{0}] Updating Resources: (Name [{1}] Type [{2}])" , _class.GetType().Name , c.GetType().Name , ((Structure)c.getType()).ToString()); }
public void DisplayResourceCost(PlayerState p, Card c) { if (Log(p)) { int[] cardsResourceCost = c.getCost(); Console.Write("[{0}] [{1}] Card [{2}] Costs: ", _class.GetType().Name, c.getName(), c.getCost()); var resources = Enum.GetValues(typeof(Resource)); foreach (var resource in resources) { int index = (int)resource; Console.Write("[{0} : {1:N2}] ", resource, cardsResourceCost[index]); } Console.WriteLine(); } }
public void CheckResourceCard(PlayerState p, Card c) { if (Log(p)) { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------"); ResourceCard card = (ResourceCard)c; int[] resources = card.getResources(); Console.WriteLine("[{0}] [Card.getResources ({1})] ", _class.GetType().Name, card.hasTradableResources()); for (int index = 0; index < resources.Count(); index++) { Console.Write("[{0} : {1}] ", ((Resource)index).ToString(), resources[index]); } Console.WriteLine(); Console.WriteLine("--------------------------------------------------------------------------------------------------------\n"); } }
/* * Input: A Player, a Card and a direction(0 = right, 1 = left) * * * Output: number of coins required to trade for resources for card with the player * at the given direction. negitive number if impossible */ public int validateTrade(PlayerState p, Card c, int direction) { int recCost = 2; int comCost = 2; //checkes to see if a player can play card with thier own resources if (ValidateCard(p, c)) { return 0; } PlayerState trader; if ((p.getBoard().getName().Equals("WB10") && (p.getBoard().getCurrentWonderLevel() >= 1))) { recCost = 1; } if (direction == 0) { trader = gameState.getRightPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 31) || (p.getPlayedCards()[i].getNumber() == 32)) { recCost = 1; break; } } } else { trader = gameState.getLeftPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 33) || (p.getPlayedCards()[i].getNumber() == 34)) { recCost = 1; break; } } } for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 35) || (p.getPlayedCards()[i].getNumber() == 36)) { comCost = 1; } } if (!baseResources.ContainsKey(trader.getName())) { return -1; } int cost = 0; List<int> traderResources = baseResources[trader.getName()]; int[] requiredResources = new int[c.getCost().Length]; for (int i = 0; i < c.getCost().Length; i++) { requiredResources[i] = c.getCost()[i]; requiredResources[i] -= baseResources[p.getName()][i];//p.getResources()[i]; if (requiredResources[i] < 0) { requiredResources[i] = 0; } if (traderResources[i] < requiredResources[i]) { return -1; } if (i < 4) { cost += requiredResources[i] * recCost; } else { cost += requiredResources[i] * comCost; } Console.WriteLine("cost " + cost + " cur rec " + requiredResources[i]); } return cost; }
//================================================================================================================= // Method to take the input card and place it in the next slot on the board private void changeCardHelper(Card c, String s, int startIndex, int lengthIndex) { Canvas g = (Canvas)parent.Children[1]; for (int i = 0; i < lengthIndex; i++) { Image img = (Image)g.Children[startIndex++]; String name = ((BitmapImage)img.Source).UriSource.ToString();//parse this to see if slot is empty String subs = name.Split(',').Last(); String last = subs.Split('/').Last(); //handle both cases of placeholder cards String empty = "EmptyCard.png"; String dark = "darkPlaceholder.png"; if (last.Equals(empty, StringComparison.Ordinal) || last.Equals(dark, StringComparison.Ordinal)) { img.BeginInit(); img.Source = new BitmapImage( new Uri(@"pack://application:,,,/Images/" + c.getName() + ".jpg", UriKind.RelativeOrAbsolute)); img.EndInit(); break; } } }
public bool CheckResourceCost(PlayerState p, Card c) { int[] totalResources = { 0, 0, 0, 0, 0, 0, 0 }; int[] cost = c.getCost(); int[] boardResources = p.getBoard().getResources(); List<int> playersResources = hashtable[p.getName()]; for (int i = 0; i < playersResources.Count(); i++) { totalResources[i] = (playersResources[i] + boardResources[i]); } var resources = Enum.GetValues(typeof(Resource)); foreach (var type in resources) { int resource = (int)type; if (cost[resource] > totalResources[resource]) return false; } return true; }
public void setWonderCards(Card c) { wonderBuildCards.Add(c); }
//Initial call to check for card validity public bool ValidateCard (PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //Check for precards if (preCardCheck(p, c)) { return true; } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return true; } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return true; } return false; } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return CheckResourceCost(p,c.getCost()); } return false; }
//================================================================================================================= // This is a filtering method to determine where in the board the card should be added public void changeCard(Card c) { if (c.getName()[0].Equals('R')) { changeCardHelper(c, "R", 0, 10); }//3-12 if (c.getName()[0].Equals('M')) { changeCardHelper(c, "M", 10, 10); }//13-22 if (c.getName()[0].Equals('S')) { changeCardHelper(c, "S", 20, 10); }//23-32 if (c.getName()[1].Equals('O')) { changeCardHelper(c, "CO", 30, 10); return; }//return to not continue if (c.getName()[0].Equals('C')) { changeCardHelper(c, "C", 40, 10); }//33-42 if (c.getName()[0].Equals('G')) { changeCardHelper(c, "G", 50, 6); }//53-57 }
public void CheckCommerceCard(PlayerState p, Card c) { if (Log(p)) { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------"); CommerceCard card = (CommerceCard)c; int totalResourceCost = c.getTotalResourceCost(); int[] costs = card.getCost(); int[] collect = card.getCollect(); int[] resourceTradable = card.getResourceTradable(); Console.WriteLine("[{0}] Commerce Card [{1}] Total Resource Cost [{2}]", _class.GetType().Name , c.getName() , totalResourceCost); var resources = Enum.GetValues(typeof(Resource)); // Get the cost and display it Console.WriteLine("[Card.getCost() ] "); foreach (var resource in resources) { int index = (int)resource; Console.Write("[{0} : {1}] ", ((Resource)index).ToString(), costs[index]); } Console.WriteLine(); //0 = none, 1 = resource card, 2 = manufactured good int resourceType = card.getResources(); Console.WriteLine("[Card.getCollect()] RT [{0}] ] ", resourceType); // resources = Enum.GetValues(typeof(Resource)); for (int index = 0; index < collect.Count(); index++) { Console.Write("[{0} : {1}] ", ((Resource)index).ToString(), collect[index]); } Console.WriteLine(); // resources = Enum.GetValues(typeof(Resource)); // Console.WriteLine("[Card.getResourceTradable ({0})] ", card.hasTradableResources()); for (int index = 0; index < resourceTradable.Count(); index++) { Console.Write("[{0} : {1}] ", ((Resource)index).ToString(), resourceTradable[index]); } Console.WriteLine(); Console.WriteLine("--------------------------------------------------------------------------------------------------------\n"); } }
/* * Input: A Player and a Card * * * Output: True or False -> Does the player have enough resources to play given card already? */ public bool ValidateCard (PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //c.toString(); //Check for duplicity for (int i = 0; i < p.getPlayedCards().Count; i++) { if (c.getCardName() == p.getPlayedCards()[i].getCardName()) { if (p.getName().Equals("P0")) { System.Console.WriteLine("!Can't play card with the same name!"); } return false; } } //Check for precards if (preCardCheck(p, c)) { return true; } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return true; } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return true; } return false; } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return CheckResourceCost(p,c.getCost()); } return false; }
public void setDiscards(Card c) { discards.Add(c); }
public void ValidatingCard(PlayerState p, Card c) { if (Log(p)) { System.Console.WriteLine("\n\n============================================================================================================="); System.Console.WriteLine("{0}:: \nValidateCard( Player [{1}] Card [{2}] Coin Cost [{3}] Resource Cost [{4}])" , _class.GetType().Name , p.getName() , c.getName() , c.getCoinCost() , c.getTotalResourceCost()); System.Console.WriteLine("============================================================================================================="); } }
private void UpdateResources(PlayerState p, Card c) { //_logger.UpdatingPlayersResources(p,c); //_logger.DisplayResourceCost(p,c); if (c is CommerceCard) { //KensUtilityfunctions k = new KensUtilityfunctions(); //int income = k.calcCommerceIncome(c, gameState, p.getSeatNumber()); //p.updateCoins(income); if (((CommerceCard)c).hasTradableResources()) { //_logger.DisplayPlayersResources(p, hashtable); //_logger.CheckCommerceCard(p,c); List<int> current = hashtable[p.getName()]; int[] tradableResources = ((CommerceCard)c).getResourceTradable(); for (int index = 0; index < tradableResources.Count(); index++) { switch (index) { case (int)Resource.Wood: current[(int)Resource.Wood] += tradableResources[index]; break; case (int)Resource.Stone: current[(int)Resource.Stone] += tradableResources[index]; break; case (int)Resource.Clay: current[(int)Resource.Clay] += tradableResources[index]; break; case (int)Resource.Ore: current[(int)Resource.Ore] += tradableResources[index]; break; } } hashtable[p.getName()] = current; //_logger.DisplayPlayersResources(p, hashtable); } return; } if (c is ResourceCard) { //_logger.CheckResourceCard(p,c); //_logger.DisplayPlayersResources(p, hashtable); List<int> current = hashtable[p.getName()]; if (((ResourceCard)c).hasTradableResources()) { int[] tradableResources = ((ResourceCard)c).getResources(); for (int index = 0; index < tradableResources.Count(); index++) { switch (index) { case (int)Resource.Wood: current[(int)Resource.Wood] += tradableResources[index]; break; case (int)Resource.Stone: current[(int)Resource.Stone] += tradableResources[index]; break; case (int)Resource.Clay: current[(int)Resource.Clay] += tradableResources[index]; break; case (int)Resource.Ore: current[(int)Resource.Ore] += tradableResources[index]; break; case (int)Resource.Glass: current[(int)Resource.Glass] += tradableResources[index]; break; case (int)Resource.Loom: current[(int)Resource.Loom] += tradableResources[index]; break; case (int)Resource.Paper: current[(int)Resource.Paper] += tradableResources[index]; break; } } hashtable[p.getName()] = current; //_logger.DisplayPlayersResources(p, hashtable); } return; } //_logger.CheckDictionary(p,hashtable); //_logger.DisplayPlayersResources(p, hashtable); }
public static WonderBuyingWindow GetInstance(Resources r, Card c, PlayerGameBoard p, GameState g) { if (_instance == null) { _instance = new WonderBuyingWindow(r, c, p, g); } else { _instance.Close(); _instance.reset(); _instance = new WonderBuyingWindow(r, c, p, g); } return _instance; }
public static ResourceBuying GetInstance(Resources r, Card c, PlayerGameBoard p) { if (_instance == null) { _instance = new ResourceBuying(r, c, p); } else { _instance.Close(); _instance = new ResourceBuying(r, c, p); } return _instance; }
public void setHand(Card c){ hand.Add(c);}
public void addPlayedCards(Card c ) { playedCards.Add(c); }
private void UpdateResources(PlayerState p, Card c) { //_logger.UpdatingPlayersResources(p,c); //_logger.DisplayResourceCost(p,c); if (c is CommerceCard) { KensUtilityfunctions k = new KensUtilityfunctions(); int income = k.calcCommerceIncome(c, gameState, p.getSeatNumber()); p.updateCoins(income); return; } if (c is ResourceCard) { //_logger.CheckResourceCard(p,c); //_logger.DisplayPlayersResources(p, hashtable); List<int> current = baseResources[p.getName()]; if (((ResourceCard)c).hasTradableResources()) { if ((((ResourceCard)c).getNumber() > 7) && (((ResourceCard)c).getNumber() < 14)) { //populate Special Resource Hashmap if the Card is a special resource List<ResourceCard> srlst = SResources[p.getName()]; srlst.Add((ResourceCard)c); SResources[p.getName()] = srlst; System.Console.WriteLine(p.getName() + " is adding Special Resource Card: {" + ((ResourceCard)c).getResources()[0] + "," + ((ResourceCard)c).getResources()[1] + "," + ((ResourceCard)c).getResources()[2] + "," + ((ResourceCard)c).getResources()[3] + "," + ((ResourceCard)c).getResources()[4] + "," + ((ResourceCard)c).getResources()[5] + "," + ((ResourceCard)c).getResources()[6] + "}"); } else { int[] tradableResources = ((ResourceCard)c).getResources(); for (int index = 0; index < tradableResources.Count(); index++) { switch (index) { case (int)Resource.Wood: current[(int)Resource.Wood] += tradableResources[index]; break; case (int)Resource.Stone: current[(int)Resource.Stone] += tradableResources[index]; break; case (int)Resource.Clay: current[(int)Resource.Clay] += tradableResources[index]; break; case (int)Resource.Ore: current[(int)Resource.Ore] += tradableResources[index]; break; case (int)Resource.Glass: current[(int)Resource.Glass] += tradableResources[index]; break; case (int)Resource.Loom: current[(int)Resource.Loom] += tradableResources[index]; break; case (int)Resource.Paper: current[(int)Resource.Paper] += tradableResources[index]; break; } } System.Console.WriteLine(p.getName() +" is adding: {" + tradableResources[0] + "," + tradableResources[1] + "," + tradableResources[2] + "," + tradableResources[3] + "," + tradableResources[4] + "," + tradableResources[5] + "," + tradableResources[6] + "}"); baseResources[p.getName()] = current; //_logger.DisplayPlayersResources(p, hashtable); } } return; } //_logger.CheckDictionary(p,hashtable); //_logger.DisplayPlayersResources(p, hashtable); }
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; }