public void PlayerConstructorTest() { string name = "name"; Player target = new Player(name); Assert.AreEqual(name, target.Name); Assert.IsNull(target.Game); }
/// <summary> /// Initializes a new instance of the <see cref="SpyCard"/> class. /// </summary> /// <param name="playerShowingCard"> /// The player showing card. /// </param> /// <param name="cardSeen"> /// The card seen. /// </param> public SpyCard(Player playerShowingCard, Card cardSeen) : base(playerShowingCard) { Contract.Requires<ArgumentNullException>(playerShowingCard != null, "player"); Contract.Requires<ArgumentNullException>(cardSeen != null, "cardSeen"); this.card = cardSeen; }
/// <summary> /// Initializes a new instance of the <see cref="CannotDisprove"/> class. /// </summary> /// <param name="unablePlayer">The player that cannot disprove the suspicion.</param> /// <param name="suspicion">The suspicion.</param> public CannotDisprove(Player unablePlayer, Suspicion suspicion) : base(unablePlayer) { Contract.Requires<ArgumentNullException>(unablePlayer != null, "unablePlayer"); Contract.Requires<ArgumentNullException>(suspicion != null, "suspicion"); this.suspicion = suspicion; }
public void DisprovedConstructorWithForeignCardTest() { Player disprovingPlayer = new Player("opponent"); Suspicion suggestion = new Suspicion(new Suspect("test"), new Weapon("test"), new Place("test")); Card cardShown = new Suspect("some other suspect"); new Disproved(disprovingPlayer, suggestion, cardShown); }
protected virtual void OnPlayerClicked(Player player) { if (player == null) throw new ArgumentNullException("player"); var playerClicked = PlayerClicked; if (playerClicked != null) { playerClicked(this, new PlayerClickedEventArgs(player)); } }
public void SpyCardConstructorTest() { Player playerShowingCard = new Player("player"); Card cardSeen = new Weapon("card"); SpyCard target = new SpyCard(playerShowingCard, cardSeen); Assert.AreSame(playerShowingCard, target.Player); Assert.AreSame(cardSeen, target.Card); }
/// <summary> /// Initializes a new instance of the <see cref="Disproved"/> class. /// Creates a clue from when an opponent disproves the <see cref="Suspicion"/> /// of the interacting <see cref="Player"/>. /// </summary> /// <param name="opponent"> /// The player who disproved the <see cref="Suspicion"/>. /// </param> /// <param name="suggestion"> /// The weapon, suspect and place being suspected. /// </param> /// <param name="cardShown"> /// The card that the opponent showed to disprove the <see cref="Suspicion"/>. /// </param> public Disproved(Player opponent, Suspicion suggestion, Card cardShown) : base(opponent) { Contract.Requires<ArgumentNullException>(suggestion != null, "suggestion"); this.suspicion = suggestion; if (cardShown != null) { if (!suggestion.Cards.Contains(cardShown)) throw new ArgumentException(string.Format(Strings.DisprovingCardNotInSuspicion, "cardShown", "suggestion")); this.cardShown = cardShown; } }
public void GetContraintsMissingNodesTest() { Player playerShowingCard = new Player("test"); Card cardSeen = new Weapon("test"); Card anotherCard = new Suspect("test"); Node[] nodes = new Node[] { new Node(playerShowingCard, cardSeen), new Node(playerShowingCard, anotherCard), }; new SpyCard(playerShowingCard, cardSeen).GetConstraints(nodes.Where((n, i) => i == 1)).Count(); }
public void GetConstraintsTest() { Player playerShowingCard = new Player("test"); Card cardSeen = new Weapon("test"); Card anotherCard = new Suspect("test"); Node[] nodes = new Node[] { new Node(playerShowingCard, cardSeen), new Node(playerShowingCard, anotherCard), }; SpyCard target = new SpyCard(playerShowingCard, cardSeen); var actual = target.GetConstraints(nodes); Assert.AreEqual(1, actual.Count()); SelectionCountConstraint c = actual.First() as SelectionCountConstraint; Assert.IsNotNull(c); Assert.AreEqual(1, c.Min); Assert.AreEqual(1, c.Max); Assert.AreEqual(1, c.Nodes.Count()); Assert.AreSame(nodes[0], c.Nodes.First()); }
void setupCards(Player player, params string[] cardNames) { foreach (string cardName in cardNames) { this.game.Clues.Add(new SpyCard(player, this.find(cardName))); } }
void disproved(Player disprovingPlayer, string cardShown) { disproved(disprovingPlayer, this.find(cardShown)); }
CompositeClue newCC(Player suggestingPlayer) { return this.cc = new CompositeClue { Player = suggestingPlayer }; }
void disproved(Player disprovingPlayer) { this.disproved(disprovingPlayer, (Card)null); }
void disproved(Player disprovingPlayer, Card cardShown) { this.cc.Responses[disprovingPlayer].Disproved = true; this.cc.Responses[disprovingPlayer].Alabi = cardShown; }
public void NameTest() { Player target = new Player("a"); target.Name = "b"; Assert.AreEqual("b", target.Name); }
/// <summary> /// The load game. /// </summary> /// <returns> /// </returns> private bool? LoadGame() { bool? result = this.openGameDialog.ShowDialog(); if (result.HasValue && result.Value) { IFormatter formatter = new BinaryFormatter(); using (Stream s = this.openGameDialog.OpenFile()) { this.game = (Game)formatter.Deserialize(s); this.interactivePlayer = this.game.Players.First(p => p.Name.Equals(formatter.Deserialize(s))); this.prepareNewOrLoadedGameState(); this.game.ResumeFromLoad(); } try { this.saveGameDialog.FileName = this.openGameDialog.FileName; } catch (SecurityException) { // just a convenience that we'll ignore if we can't do it. } } this.prepareNewOrLoadedGameState(); return result; }
/// <summary> /// Sets up the players in the game. /// </summary> private void SetupPlayers() { int players = ConsoleHelper.AskNumber("How many players?"); Console.WriteLine("In clockwise order..."); for (int i = 0; i < players; i++) { string name; do { name = ConsoleHelper.AskString(string.Format("Player {0} name:", i + 1)); } while (string.IsNullOrEmpty(name)); this.game.Players.Add(new Player(name)); } while (!this.game.CardAssignmentsAcceptable) { for (int i = 0; i < players; i++) { this.game.Players[i].CardsHeldCount = ConsoleHelper.AskNumber(string.Format("How many cards is {0} holding?", this.game.Players[i].Name)); } if (!this.game.CardAssignmentsAcceptable) { Console.Error.WriteLine("ERROR: Those cards do not add up to {0}.", this.game.Cards.Count() - 3); } } this.interactivePlayer = this.ChoosePlayer("Which player are you?", false, true); }
/// <summary> /// The take turn. /// </summary> private void TakeTurn() { this.suggestingPlayer = this.ChoosePlayer("Whose turn is it?", true, true); if (this.suggestingPlayer == null) { return; } try { if (this.suggestingPlayer == this.interactivePlayer && this.game.Rules.HasSpyglass) { while (true) { var turnMenu = new Dictionary<char, string>(); turnMenu.Add('S', "Make a suggestion"); turnMenu.Add('L', "Look at someone else's card"); turnMenu.Add('E', "End turn"); switch (ConsoleHelper.Choose("What do you want to do?", turnMenu, s => s).Key) { case 'S': this.Suggestion(); break; case 'L': this.Spy(); break; case 'E': return; } } } else if (this.suggestingPlayer == this.interactivePlayer) { this.Suggestion(); } else { var turnMenu = new Dictionary<char, string>(); turnMenu.Add('S', "Make a suggestion"); turnMenu.Add('A', "Make an accusation"); turnMenu.Add('E', "End turn"); switch (ConsoleHelper.Choose("What do you want to do?", turnMenu, s => s).Key) { case 'S': this.Suggestion(); break; case 'A': this.Accusation(); break; case 'E': return; } } } finally { this.suggestingPlayer = null; } }
void spy(Player player, string cardShown) { player.Game.Clues.Add(new SpyCard(player, this.find(cardShown))); }
Suspicion suggest(Player suggestingPlayer, string place, string suspect, string weapon) { this.newCC(suggestingPlayer); return this.cc.Suspicion = new Suspicion((Suspect)this.find(suspect), (Weapon)this.find(weapon), (Place)this.find(place)); }
public override void Setup() { base.Setup(); this.game = null; this.interactivePlayer = null; }
/// <summary> /// Initializes a new instance of the <see cref="Disproved"/> class. /// Creates a clue from when an opponent disproves the <see cref="Suspicion"/> /// of another opponent (besides the interacting <see cref="Player"/>.) /// </summary> /// <param name="disprovingPlayer"> /// The player disproving the <see cref="Suspicion">suggestion</see>. /// </param> /// <param name="suggestion"> /// The weapon, suspect and place being suspected. /// </param> public Disproved(Player disprovingPlayer, Suspicion suggestion) : this(disprovingPlayer, suggestion, null) { }
public void Webbs() { this.game = this.MasterDetective; this.game.AutoAnalysis = false; // speeds up test if we call Analyze just once. Player andrew, cheryl, rebecca, dan, table; this.game.Players.AddRange(new[] { andrew = this.interactivePlayer = new Player("Andrew") { CardsHeldCount = 6 }, cheryl = new Player("Cheryl") { CardsHeldCount = 6 }, rebecca = new Player("Rebecca") { CardsHeldCount = 6 }, dan = new Player("Dan") { CardsHeldCount = 6 }, table = new Player("Table") { CardsHeldCount = 3 }, }); this.game.Start(); this.setupCards(andrew, "White", "Brunette", "Wrench", "Drawing room", "Rose", "Rope"); this.setupCards(table, "Library", "Studio", "Fountain"); this.suggest(andrew, "Courtyard", "Peacock", "Candlestick"); this.disproved(rebecca, "Peacock"); this.disproved(dan, "Courtyard"); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(rebecca, "Dining room", "Rose", "Rope"); this.cannot_disprove(dan); this.disproved(cheryl); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Trophy room", "Rose", "Rope"); this.cannot_disprove(rebecca); this.cannot_disprove(dan); this.game.Clues.Add(this.cc); this.suggest(andrew, "Gazebo", "Green", "Horseshoe"); this.disproved(rebecca, "Horseshoe"); this.cannot_disprove(dan); this.disproved(cheryl, "Gazebo"); this.game.Clues.Add(this.cc); this.suggest(dan, "Billiard room", "Grey", "Knife"); this.disproved(cheryl); this.cannot_disprove(rebecca); this.game.Clues.Add(this.cc); this.spy(rebecca, "Poison"); this.suggest(andrew, "Trophy room", "Peach", "Lead pipe"); this.disproved(rebecca, "Peach"); this.cannot_disprove(dan); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(rebecca, "Kitchen", "White", "Revolver"); this.disproved(dan); this.disproved(cheryl); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Trophy room", "Scarlet", "Wrench"); this.cannot_disprove(rebecca); this.cannot_disprove(dan); this.game.Clues.Add(this.cc); this.suggest(andrew, "Kitchen", "Mustard", "Candlestick"); this.cannot_disprove(rebecca); this.disproved(dan, "Mustard"); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(rebecca, "Drawing room", "Scarlet", "Rope"); this.disproved(cheryl); this.game.Clues.Add(this.cc); this.suggest(dan, "Courtyard", "Plum", "Wrench"); this.cannot_disprove(cheryl); this.disproved(rebecca); this.game.Clues.Add(this.cc); this.suggest(andrew, "Dining room", "Grey", "Lead pipe"); this.disproved(rebecca, "Lead pipe"); this.disproved(dan, "Grey"); this.disproved(cheryl, "Dining room"); this.game.Clues.Add(this.cc); this.game.Analyze(); foreach (Card card in this.game.Cards) { switch (card.Name) { case "Trophy room": case "Mr. Green": Assert.IsTrue(node(this.game.CaseFile, card).Value); break; case "Knife": case "Candlestick": Assert.IsFalse(node(this.game.CaseFile, card).HasValue); break; default: Assert.IsFalse(node(this.game.CaseFile, card).Value); break; } } GameTest.TestSerialize(this.TestContext, this.game); }
public PlayerClickedEventArgs(Player player) { this.player = player; }
public void Hancocks() { this.game = this.MasterDetective; this.game.AutoAnalysis = false; // speeds up test if we cal Analyze just once. Player andrew, cheryl, sarah, sheldon; this.game.Players.AddRange(new[] { andrew = this.interactivePlayer = new Player("Andrew") { CardsHeldCount = 7 }, cheryl = new Player("Cheryl") { CardsHeldCount = 7 }, sarah = new Player("Sarah") { CardsHeldCount = 6 }, sheldon = new Player("Sheldon") { CardsHeldCount = 7 }, }); this.game.Start(); setupCards(andrew, "Poison", "Lead pipe", "Horseshoe", "Conservatory", "Rose", "Grey", "Mustard"); this.suggest(andrew, "Courtyard", "Brunette", "Candlestick"); this.disproved(cheryl, "Brunette"); this.cannot_disprove(sarah); this.cannot_disprove(sheldon); this.game.Clues.Add(this.cc); this.suggest(sarah, "Trophy room", "Mustard", "Poison"); this.cannot_disprove(sheldon); this.disproved(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Courtyard", "Peach", "Horseshoe"); this.disproved(andrew); this.disproved(cheryl); this.cannot_disprove(sarah); this.game.Clues.Add(this.cc); this.suggest(sarah, "Kitchen", "Green", "Knife"); this.disproved(sheldon); this.cannot_disprove(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Gazebo", "Brunette", "Poison"); this.disproved(andrew); this.disproved(cheryl); this.cannot_disprove(sarah); this.game.Clues.Add(this.cc); this.suggest(andrew, "Kitchen", "Peach", "Candlestick"); this.disproved(cheryl, "Candlestick"); this.cannot_disprove(sarah); this.disproved(sheldon, "Kitchen"); this.game.Clues.Add(this.cc); this.suggest(sarah, "Library", "Grey", "Lead pipe"); this.cannot_disprove(sheldon); this.disproved(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.spy(cheryl, "Studio"); this.spy(cheryl, "Drawing room"); this.spy(cheryl, "Brunette"); this.spy(cheryl, "Courtyard"); this.spy(cheryl, "Scarlet"); this.spy(cheryl, "Dining room"); this.spy(cheryl, "Candlestick"); this.suggest(sheldon, "Library", "Mustard", "Lead pipe"); this.disproved(andrew); this.cannot_disprove(cheryl); this.disproved(sarah); this.game.Clues.Add(this.cc); this.spy(sarah, "Carriage House"); this.suggest(sarah, "Gazebo", "Rose", "Revolver"); this.disproved(sheldon); this.disproved(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Billiard room", "Peach", "Revolver"); this.cannot_disprove(andrew); this.cannot_disprove(cheryl); this.disproved(sarah); this.game.Clues.Add(this.cc); this.spy(sheldon, "Peach"); this.suggest(andrew, "Trophy room", "White", "Rope"); this.cannot_disprove(cheryl); this.disproved(sarah, "Rope"); this.cannot_disprove(sheldon); this.game.Clues.Add(this.cc); this.suggest(sarah, "Trophy room", "Peach", "Poison"); this.disproved(sheldon); this.disproved(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Library", "Peach", "Revolver"); this.cannot_disprove(andrew); this.cannot_disprove(cheryl); this.disproved(sarah); this.game.Clues.Add(this.cc); this.suggest(andrew, "Fountain", "Plum", "Wrench"); this.cannot_disprove(cheryl); this.disproved(sarah, "Fountain"); this.disproved(sheldon, "Plum"); this.game.Clues.Add(this.cc); this.spy(sheldon, "Knife"); this.suggest(sarah, "Conservatory", "Green", "Horseshoe"); this.cannot_disprove(sheldon); this.disproved(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Courtyard", "Rose", "Lead pipe"); this.disproved(andrew); this.disproved(cheryl); this.cannot_disprove(sarah); this.game.Clues.Add(this.cc); this.suggest(sarah, "Trophy room", "Plum", "Wrench"); this.disproved(sheldon); this.cannot_disprove(andrew); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(sheldon, "Trophy room", "Green", "Revolver"); this.cannot_disprove(andrew); this.cannot_disprove(cheryl); this.cannot_disprove(sarah); this.game.Clues.Add(this.cc); this.game.Analyze(); foreach (Card card in this.game.Cards) { switch (card.Name) { case "Mr. Green": case "Trophy room": Assert.IsTrue(node(this.game.CaseFile, card).Value); break; case "Revolver": case "Wrench": Assert.IsFalse(node(this.game.CaseFile, card).HasValue); break; default: Assert.IsFalse(node(this.game.CaseFile, card).Value); break; } } GameTest.TestSerialize(this.TestContext, this.game); }
public DisprovedAnyCards(Player player, params Card[] cards) : base(player) { this.cards = cards; }
public void Wrigleys() { this.game = this.Simpsons; this.game.AutoAnalysis = false; Player andrew, cheryl, jeff, julia; this.game.Players.AddRange(new[] { andrew = this.interactivePlayer = new Player("Andrew") { CardsHeldCount = 4 }, cheryl = new Player("Cheryl") { CardsHeldCount = 5 }, jeff = new Player("Jeff") { CardsHeldCount = 4 }, julia = new Player("Julia") { CardsHeldCount = 5 }, }); this.game.Start(); this.setupCards("Extend-o-glove", "Plum", "Kwik e mart", "Mustard"); this.suggest(jeff, "Springfield retirement castle", "Peacock", "Extend-o-glove"); this.disproved(julia); this.game.Clues.Add(this.cc); this.suggest(julia, "Androids dungeon", "Peacock", "Necklace"); this.disproved(cheryl); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Kwik e mart", "Mustard", "Necklace"); this.cannot_disprove(jeff); this.disproved(julia); this.game.Clues.Add(this.cc); this.suggest(andrew, "Androids dungeon", "White", "Slingshot"); this.disproved(cheryl, "Androids dungeon"); this.game.Clues.Add(this.cc); this.suggest(andrew, "Kwik e mart", "Scarlet", "Slingshot"); this.disproved(jeff, "Slingshot"); this.game.Clues.Add(this.cc); this.suggest(jeff, "Simpson house", "Scarlet", "Plutonium rod"); this.disproved(julia); this.game.Clues.Add(this.cc); this.suggest(andrew, "Krusty loo studios", "Green", "Poison donut"); this.cannot_disprove(cheryl); this.disproved(jeff, "Krusty loo studios"); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Kwik e mart", "White", "Plutonium rod"); this.cannot_disprove(jeff); this.cannot_disprove(julia); this.game.Clues.Add(this.cc); this.suggest(jeff, "Krusty loo studios", "Scarlet", "Plutonium rod"); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(andrew, "Barneys Bowl o rama", "Green", "Saxophone"); this.cannot_disprove(cheryl); this.disproved(jeff, "Saxophone"); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Nuclear power plant", "Mustard", "Plutonium rod"); this.cannot_disprove(julia); this.game.Clues.Add(this.cc); this.suggest(jeff, "Nuclear power plant", "Scarlet", "Plutonium rod"); this.disproved(cheryl); this.game.Clues.Add(this.cc); this.suggest(julia, "Springfield retirement castle", "White", "Slingshot"); this.cannot_disprove(cheryl); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Barneys Bowl o rama", "Plum", "Saxophone"); this.cannot_disprove(julia); this.game.Clues.Add(this.cc); this.suggest(andrew, "Burns manor", "Green", "Poison donut"); this.disproved(cheryl, "Burns manor"); this.game.Clues.Add(this.cc); this.suggest(cheryl, "Barneys Bowl o rama", "Scarlet", "Plutonium rod"); this.cannot_disprove(jeff); this.game.Clues.Add(this.cc); this.game.Analyze(); foreach (Card card in this.game.Cards) { switch (card.Name) { case "Barneys Bowl o rama": case "Mrs. White": case "Plutonium rod": Assert.IsTrue(node(this.game.CaseFile, card).Value); break; default: Assert.IsFalse(node(this.game.CaseFile, card).Value); break; } } GameTest.TestSerialize(this.TestContext, this.game); }