public IActionResult GetCards(string gameId, string playerId) { IGame game = GetGame(gameId); var player = game.Players.OfType <IHumanPlayer>().Single(p => p.Id == Guid.Parse(playerId)); return(Json(player.Cards.Select(c => new { filename = CardUtil.GetPictureFilename(c), cardAbbr = CardUtil.GetAbbreviation(c) }))); }
public void Add(IPlayer player, SheepCard card) { TrickPlays.Add(new TrickPlay() { Trick = this, Participant = player.Participant, Card = CardUtil.GetAbbreviation(card), SortOrder = TrickPlays.Count() + 1 }); player.RemoveCard(card); if (IHand.PartnerCardEnum == card) { IHand.SetPartner(player, this); } }
public void Trick_IsLegal_MustMatchStartingCard() { var firstPlayer = new Participant() { Cards = CardUtil.GetAbbreviation(SheepCard.N9_HEARTS) }.Player; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var player = new Participant() { Cards = "K♥;7♥;Q♦;8♣" }.Player; var handMock = new Mock <IHand>(); handMock.Setup(m => m.ITricks).Returns(new List <ITrick>()); handMock.Setup(m => m.Players).Returns(new List <IPlayer>() { firstPlayer, player }); handMock.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.JackOfDiamonds); handMock.Setup(m => m.PartnerCardEnum).Returns(SheepCard.JACK_DIAMONDS); var trick = new Trick(handMock.Object, startingPlayerCalcMock.Object) { TrickPlays = new List <TrickPlay>() { new TrickPlay() { Participant = new Participant(), Card = CardUtil.GetAbbreviation(SheepCard.N9_CLUBS), SortOrder = 2 }, new TrickPlay() { Participant = firstPlayer.Participant, Card = CardUtil.GetAbbreviation(SheepCard.N9_HEARTS), SortOrder = 1 } } }; Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_HEARTS, player), "A hearts is part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N8_CLUBS, player), "A clubs is not part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.QUEEN_DIAMONDS, player), "A trump is not part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_CLUBS, player), "A card outside of the hand is not legal."); }
public void Trick_IsLegal_LastCardLeft() { var partner = new Participant() { Cards = CardUtil.GetAbbreviation(SheepCard.ACE_SPADES) }.Player; var otherTrick = new Mock <ITrick>().Object; var hand = new Mock <IHand>(); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { otherTrick, otherTrick, otherTrick, otherTrick }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_SPADES); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_SPADES, partner), "Cannt normally lead with the partner card, but can do so for last trick."); }
public void Card_ToAbbr() { Assert.AreEqual("J♦", CardUtil.GetAbbreviation(SheepCard.JACK_DIAMONDS)); Assert.AreEqual("7♥", CardUtil.GetAbbreviation(SheepCard.N7_HEARTS)); }