public void Should_Fail_Skill_Check_Correctly() { var crisisCard = new CrisisCard { Heading = "ExampleCrisis", PositiveColors = new List<SkillCardColor> {SkillCardColor.Leadership, SkillCardColor.Tactics}, PassLevels = new List<Tuple<int, string>> { new Tuple<int, string>(12, "pass"), new Tuple<int, string>(0, "fail") } }; var playedCards = new List<SkillCard> { new SkillCard {CardPower = 5, CardColor = SkillCardColor.Leadership}, new SkillCard {CardPower = 5, CardColor = SkillCardColor.Tactics}, new SkillCard {CardPower = 3, CardColor = SkillCardColor.Engineering} }; var ret = SkillCheck.EvalSkillCheck(playedCards, crisisCard, null); Assert.AreEqual(1, ret.Count()); Assert.AreEqual("fail", ret.ElementAt(0).ConditionText); Assert.AreEqual(0, ret.ElementAt(0).Threshold); }
public PlayCrisisForm(IEnumerable<Player> players, CrisisCard crisis, IEnumerable<SkillCard> destinyCards ) { if (crisis.PassLevels.Any() == false) { DialogResult = DialogResult.Cancel; Close(); } _players = players.ToList(); _crisis = crisis; _destinyCards = destinyCards; CrisisContributions = new List<Tuple<SkillCard, string>>(); foreach (var card in _destinyCards) CrisisContributions.Add(new Tuple<SkillCard, string>(card, "Destiny")); InitializeComponent(); PlayerDropDown.DataSource = _players; _players.ToList().ForEach(x => x.Cards.Sort()); PlayerCardListBox.DataSource = _players.First().Cards; _playerCloneList = _players.ToList(); PlayerTakeCardsDropdown.DataSource = _playerCloneList; RefreshResultPane(); }
private void DrawCrisisButtonClick(object sender, EventArgs e) { crisisTextListBox.BeginUpdate(); // DeckManager.Cards.CrisisCard crisis = Program.gManager.CurrentGameState.CrisisDeck.Draw(); // TODO: This sort of stuff should really be done in the TESTS project. See my example in there. //var crisis = new DeckManager.Cards.CrisisCard // { // Activation = DeckManager.Cards.Enums.CylonActivations.Raiders, // Heading = "Test Crisis", // JumpPrep = true, // AdditionalText = "A description of the crisis", // PositiveColors = // new List<DeckManager.Cards.Enums.SkillCardColor> // { // DeckManager.Cards.Enums.SkillCardColor.Engineering, // DeckManager.Cards.Enums.SkillCardColor.Politics // } // }; DeckManager.Cards.CrisisCard crisis = Program.GManager.CurrentGameState.CrisisDeck.Draw(); crisisTextListBox.Items.Add(crisis); crisisTextListBox.EndUpdate(); }
/// <summary> /// Evaluates the skill check after all cards have been played. /// </summary> /// <returns>List of all consequences that occur as a result of the skill check's outcome.</returns> public static List<Consequence> EvalSkillCheck(IEnumerable<SkillCard> playedCards, CrisisCard crisisCard, IEnumerable<SkillCheckRule> specialRules ) { var logger = LogManager.GetLogger(typeof(SkillCheck)); var results = new List<Consequence>(); // We can be messing around with these cards a lot inside here due to the special rules, so it is prudent to edit local copies. var internalPlayedCards = playedCards == null ? new List<SkillCard>() : playedCards.ToList(); var internalCrisisCard = crisisCard ?? new CrisisCard(); try { foreach (var rule in specialRules ?? new List<SkillCheckRule>()) { switch (rule.RuleType) { case SkillCheckRuleType.ModifyCheckDifficulty: if (rule.RuleInt.HasValue == false) break; var ruleStrength = rule.RuleInt.Value; var newPassLevels = internalCrisisCard.PassLevels.Select(passLevel => new Tuple<int, string>(passLevel.Item1 + ruleStrength, passLevel.Item2)).ToList(); internalCrisisCard.PassLevels = newPassLevels; break; case SkillCheckRuleType.SkillCardColorSignChange: if (rule.RuleColor.HasValue == false || rule.RuleColor.Value == SkillCardColor.Unknown || rule.RuleFlagEnum == null) break; var ruleColor = rule.RuleColor.Value; var ruleSign = (SkillCheckCardSign)rule.RuleFlagEnum; foreach(var card in internalPlayedCards.Where(x => x.CardColor == ruleColor)) card.CardPower = ruleSign == SkillCheckCardSign.Zero ? (ruleSign == SkillCheckCardSign.Positive ? Math.Abs(card.CardPower) : Math.Abs(card.CardPower)*-1) : // implies ruleSign == SkillCheckCardSign.Negative 0; break; case SkillCheckRuleType.SkillCardStrengthChange: if (rule.RuleInt.HasValue == false) break; foreach (var card in internalPlayedCards) card.CardPower += rule.RuleInt.Value; break; case SkillCheckRuleType.SkillCardStrengthSignChange: if (rule.RuleColor.HasValue == false || rule.RuleColor.Value == SkillCardColor.Unknown || rule.RuleFlagEnum == null || rule.RuleInt.HasValue == false) break; var ruleStrengthColor = rule.RuleColor.Value; var ruleInt = rule.RuleInt.Value; var ruleStrengthSign = (SkillCheckCardSign)rule.RuleFlagEnum; foreach (var card in internalPlayedCards.Where(x => x.CardColor == ruleStrengthColor && x.CardPower == ruleInt)) card.CardPower = ruleStrengthSign == SkillCheckCardSign.Zero ? (ruleStrengthSign == SkillCheckCardSign.Positive ? Math.Abs(card.CardPower) : Math.Abs(card.CardPower) * -1) : // implies ruleSign == SkillCheckCardSign.Negative 0; break; } } var strength = 0; foreach (var card in internalPlayedCards) { if (card.CardPower > 0) { if (crisisCard.PositiveColors.Contains(card.CardColor)) strength += card.CardPower; else strength -= card.CardPower; } } if (strength < 0) strength = 0; var checkResult = crisisCard.PassLevels.OrderByDescending(x => x.Item1).First(result => strength >= result.Item1); results.Add(new Consequence(checkResult.Item1, checkResult.Item2)); } catch (Exception e) { logger.Error("Error while computing skill check.", e); throw; } return results; }
private void DrawMultipleToolStripMenuItemClick(object sender, EventArgs e) { var inputForm = new InputForm("Input the number of Crises to draw", "Draw Crises"); inputForm.ShowDialog(); if(inputForm.DialogResult == DialogResult.OK) { var numCrises = inputForm.UserInput.ParseAs<int>(); if (numCrises == 0) { MessageBox.Show(Resources.GameWindow_drawMultipleToolStripMenuItem_InputMoreThanZero); return; } var crisisCards = Program.GManager.CurrentGameState.CrisisDeck.DrawMany(numCrises).ToList(); var crisisManagementForm = new CrisisManagementForm(crisisCards); crisisManagementForm.ShowDialog(); if (crisisManagementForm.DialogResult == DialogResult.OK) { foreach (var decision in crisisManagementForm.Decisions.OrderByDescending(x => x.Order)) { switch(decision.Action) { case CrisisAction.Replace: Program.GManager.CurrentGameState.CrisisDeck.Top(decision.Crisis); break; case CrisisAction.Draw: CurrentCrisis = decision.Crisis; crisisText.Text = CurrentCrisis.Heading + Environment.NewLine + CurrentCrisis.AdditionalText; break; case CrisisAction.Bury: Program.GManager.CurrentGameState.CrisisDeck.Bury(CurrentCrisis); CurrentCrisis = null; crisisText.Text = string.Empty; break; } } } else { crisisCards.Reverse(); foreach (var crisisCard in crisisCards) { Program.GManager.CurrentGameState.CrisisDeck.Top(crisisCard); } } } }
private void BuryTopToolStripMenuItemClick(object sender, EventArgs e) { if (CurrentCrisis != null) { Program.GManager.CurrentGameState.CrisisDeck.Bury(CurrentCrisis); CurrentCrisis = null; crisisText.Text = string.Empty; } else MessageBox.Show(Resources.GameWindow_buryTopToolStripMenuItem_SelectCrisisBeforeBury); }
private void DrawCrisisToolStripMenuItemClick(object sender, EventArgs e) { CurrentCrisis = Program.GManager.CurrentGameState.CrisisDeck.Draw(); crisisText.Text = CurrentCrisis.Heading + Environment.NewLine + CurrentCrisis.AdditionalText; }