private void lsEquities_SelectedIndexChanged(object sender, System.EventArgs e) { int i = lsEquities.SelectedIndex; EquitiesAbstract eq = (EquitiesAbstract)lsEquities.Items[i]; mchoice = DirectorFactory.GetBuilder(eq); this.Controls.Remove(pnl); pnl = mchoice.GetPanelResult(); setPanel(); }
protected void AddPaymentAnswers(IChoiceBuilder builder, IEnumerable <ICharacterInPlay> characters, byte numberOfResources) { if (characters.Count() < 2) { throw new ArgumentException("characters sequence must contain at least two items"); } if (numberOfResources < 2) { throw new ArgumentException("numberOfResources cannot be less than 2"); } var numberOfCharacters = (byte)characters.Count(); var paymentOptions = GetPaymentOptions(numberOfResources, numberOfCharacters); foreach (var character in characters) { if (character.Resources >= numberOfResources) { builder.Answer(string.Format("Pay the full cost ({0} resources) from '{1}'", numberOfResources, character.Title), character, (source, handle, item) => PayResourcesFromCharacter(source, handle, item, player, numberOfResources)); } } foreach (var optionList in paymentOptions.Where(x => x.Count >= 2)) { foreach (var first in characters.Where(x => x.Resources >= optionList[0])) { foreach (var second in characters.Where(x => x.Card.Id != first.Card.Id && x.Resources >= optionList[1])) { if (optionList.Count < 3) { var charactersAndPayments = new List <Tuple <ICharacterInPlay, byte> >(); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(second, optionList[1])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var third in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Resources >= optionList[2])) { if (optionList.Count < 4) { var charactersAndPayments = new List <Tuple <ICharacterInPlay, byte> >(); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(third, optionList[2])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var fourth in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Card.Id != third.Card.Id && x.Resources >= optionList[3])) { if (optionList.Count < 5) { var charactersAndPayments = new List <Tuple <ICharacterInPlay, byte> >(); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(third, optionList[2])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(fourth, optionList[3])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var fifth in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Card.Id != third.Card.Id && x.Card.Id != fourth.Card.Id && x.Resources >= optionList[4])) { var charactersAndPayments = new List <Tuple <ICharacterInPlay, byte> >(); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(third, optionList[2])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(fourth, optionList[3])); charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(fifth, optionList[4])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); } } } } } } }
protected void AddPaymentAnswers(IChoiceBuilder builder, IEnumerable<ICharacterInPlay> characters, byte numberOfResources) { if (characters.Count() < 2) throw new ArgumentException("characters sequence must contain at least two items"); if (numberOfResources < 2) throw new ArgumentException("numberOfResources cannot be less than 2"); var numberOfCharacters = (byte)characters.Count(); var paymentOptions = GetPaymentOptions(numberOfResources, numberOfCharacters); foreach (var character in characters) { if (character.Resources >= numberOfResources) { builder.Answer(string.Format("Pay the full cost ({0} resources) from '{1}'", numberOfResources, character.Title), character, (source, handle, item) => PayResourcesFromCharacter(source, handle, item, player, numberOfResources)); } } foreach (var optionList in paymentOptions.Where(x => x.Count >= 2)) { foreach (var first in characters.Where(x => x.Resources >= optionList[0])) { foreach (var second in characters.Where(x => x.Card.Id != first.Card.Id && x.Resources >= optionList[1])) { if (optionList.Count < 3) { var charactersAndPayments = new List<Tuple<ICharacterInPlay, byte>>(); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(second, optionList[1])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var third in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Resources >= optionList[2])) { if (optionList.Count < 4) { var charactersAndPayments = new List<Tuple<ICharacterInPlay, byte>>(); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(third, optionList[2])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var fourth in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Card.Id != third.Card.Id && x.Resources >= optionList[3])) { if (optionList.Count < 5) { var charactersAndPayments = new List<Tuple<ICharacterInPlay, byte>>(); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(third, optionList[2])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(fourth, optionList[3])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); break; } foreach (var fifth in characters.Where(x => x.Card.Id != first.Card.Id && x.Card.Id != second.Card.Id && x.Card.Id != third.Card.Id && x.Card.Id != fourth.Card.Id && x.Resources >= optionList[4])) { var charactersAndPayments = new List<Tuple<ICharacterInPlay, byte>>(); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(first, optionList[0])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(second, optionList[1])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(third, optionList[2])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(fourth, optionList[3])); charactersAndPayments.Add(new Tuple<ICharacterInPlay, byte>(fifth, optionList[4])); builder.Answer(string.Format("Pay {0}", GetPaymentText(charactersAndPayments)), charactersAndPayments, (source, handle, item) => PayResourcesFromCharacters(source, handle, item, player)); } } } } } } }