Ejemplo n.º 1
0
        public void Rank()
        {
            var gameOver = false;

            while (!gameOver)
            {
                var handP1 = new List <string>();
                var handP2 = new List <string>();

                var deck = _deckService.InitDeck();
                while (handP1.Count != 5 && handP2.Count != 5)
                {
                    _deckService.DrawCard(handP1, deck);
                    _deckService.DrawCard(handP2, deck);
                }
                var rankHandP1 = _handRankerService.RankHand(handP1);
                var rankHandP2 = _handRankerService.RankHand(handP2);

                _handPrinterService.PrintHand(1, handP1, rankHandP1);
                _handPrinterService.PrintHand(2, handP2, rankHandP2);

                var winner = _handRankerService.RankHands(handP1, handP2);

                Console.WriteLine(winner != 0 ? $"Player {winner} won this round !" : "It's a tie !");
                Console.WriteLine("Play another hand ? Or press 'q' to quit...");
                if (Console.ReadKey().KeyChar.Equals('q'))
                {
                    gameOver = true;
                }
                Console.Clear();
            }
        }
        public void Should_Draw_A_Card_From_Deck_And_Place_It_In_Hand()
        {
            var deck = _deckService.InitDeck();
            var hand = new List <string>();

            _deckService.DrawCard(hand, deck);
            _deckService.DrawCard(hand, deck);
            _deckService.DrawCard(hand, deck);
            _deckService.DrawCard(hand, deck);
            _deckService.DrawCard(hand, deck);

            Check.That(deck.Count).IsEqualTo(47);
            Check.That(hand.Count).IsEqualTo(5);
            Check.That(hand).ContainsNoDuplicateItem();
        }
Ejemplo n.º 3
0
        public ActionResult GetCard(string deckId)
        {
            var deck = DeckContext.Find(deckId);
            var card = DeckService.DrawCard(deck);

            DeckContext.Commit();

            if (card != null)
            {
                HttpCookie cookie = Request.Cookies[DeckSessionName];

                if (cookie == null)
                {
                    cookie = new HttpCookie(DeckSessionName);
                }

                cookie.Values[$"{deck.Id}/CardValue"] = card.Value;
                cookie.Values[$"{deck.Id}/CardSuit"]  = card.Suit;
                cookie.Expires = DateTime.Now.AddDays(7);
                Response.Cookies.Add(cookie);
            }

            return(RedirectToAction("Details", new { id = deckId }));
        }