示例#1
0
        public void Score_of_deck_should_be_120()
        {
            var deck = new Deck(new[] { "A", "B", "C", "D" }, new Range(1, 10));

            var res = BriscolaUtils.Totalize(deck);

            res.Should().Be(120);
        }
示例#2
0
        public Tuple <int, int> Play()
        {
            _game.Start();
            var totalTurns = 40 / _game.State.Players.Count;

            for (var i = 0; i < totalTurns; i++)
            {
                _ui.Custom(ConsoleColor.Yellow, string.Format("\n===== {0}° Mano ===== (Briscola: {1} di {2})",
                                                              i + 1, _game.State.Briscola.Value, _game.State.Briscola.Seed));
                _game.PlayHand();

                _game.Refill();
            }

            _ui.Send("\nPARTITA TERMINATA!");
            foreach (var player in _game.State.Players)
            {
                _ui.Send(player.Name + " => " + BriscolaUtils.Totalize(player.Stack));
            }


            var pl = _game.State.Players.ToArray();
            int yourScore;
            int opponentScore;

            if (pl.Length == 4)
            {
                yourScore     = BriscolaUtils.Totalize(pl[0].Stack) + BriscolaUtils.Totalize(pl[2].Stack);
                opponentScore = BriscolaUtils.Totalize(pl[1].Stack) + BriscolaUtils.Totalize(pl[3].Stack);

                _ui.Send(string.Empty);
                _ui.Send(pl[0].Name + " e " + pl[2].Name + " => " + yourScore);
                _ui.Send(pl[1].Name + " e " + pl[3].Name + " => " + opponentScore);
            }
            else
            {
                yourScore     = BriscolaUtils.Totalize(pl[0].Stack);
                opponentScore = pl.Where(x => x != pl[0])
                                .Select(p => BriscolaUtils.Totalize(p.Stack)).Max();
            }


            var pron = _game.State.Players.Count == 4 ? "AVETE" : "HAI";

            if (yourScore == opponentScore)
            {
                _ui.Custom(ConsoleColor.Yellow, "\n >>> PAREGGIO <<<");
            }
            else
            {
                if (yourScore > opponentScore)
                {
                    _ui.Custom(ConsoleColor.Green, "\n >>> " + pron + " VINTO! <<<");
                }
                else
                {
                    _ui.Custom(ConsoleColor.Red, "\n >>> PECCATO! " + pron + " PERSO <<<");
                }
            }

            return(new Tuple <int, int>(yourScore, opponentScore));
        }