Esempio n. 1
0
        private static void RunBridgeGame()
        {
            var set = new BridgeSet();

            var game = new BridgeGame(PlayerPosition.East);

            var players = Enumerable.Range(0, 4).Select(n =>
            {
                var position = (PlayerPosition)n;
                return new Player(position, set.Cards[position]);
            }).ToArray();

            var table = new ConsoleBridgeTable();

            table.ShowTable(set);
            Console.WriteLine();
            Console.WriteLine("Game Started:");
            Console.WriteLine(string.Empty.PadLeft(Console.BufferWidth, '*'));
            while (!game.Finished)
            {
                Console.Write(game.TurnStarter.ToString()[0] + ": ");
                for (int i = 0; i < 4; i++)
                {
                    var player = players.First(p => p.Position == game.Next);
                    var card = player.Play(game);
                    game.RecordOutCard(card);

                    table.ShowCard(card);
                }
                Console.WriteLine();
                Console.ReadLine();
            }
        }
Esempio n. 2
0
        private void WriteCardsInPlayerSuit(BridgeSet set,PlayerPosition position, int typeValue)
        {
            var type = (CardType)typeValue;
            Write(type);
            Console.Write(' ');
            var cardsInType = set.Cards[position].Where(c => c.Type == type).OrderBy(c => ~c.Value);

            if (cardsInType.Count() < 1) Console.Write("-");
            foreach (var card in cardsInType)
            {
                Console.Write(card.Name);
                Console.Write(' ');
            }
        }
Esempio n. 3
0
        public void ShowTable(BridgeSet set)
        {
            currentSpace = SpaceMiddle;
            for (int i = 0; i < 4; i++)
            {
                WriteCardsInPlayerSuit(set, PlayerPosition.North, i);
                Console.WriteLine();
            }
            WriteLine(2);

            for (int i = 0; i < 4; i++)
            {
                currentSpace = 0;
                WriteCardsInPlayerSuit(set, PlayerPosition.West, i);
                currentSpace = SpaceRight - Console.CursorLeft;
                WriteCardsInPlayerSuit(set, PlayerPosition.East, i);
                Console.WriteLine();
            }
            WriteLine(1);

            currentSpace = SpaceMiddle;
            for (int i = 0; i < 4; i++)
            {
                WriteCardsInPlayerSuit(set, PlayerPosition.South, i);
                Console.WriteLine();
            }

            int squareLeft = SpaceMiddle, squareTop = 5, squareHeight = 4, squareWidth = 9;
            Console.SetCursorPosition(squareLeft, squareTop);
            Console.Write('┌' + string.Empty.PadLeft(squareWidth, '─') + '┐');

            Console.SetCursorPosition(squareLeft, squareTop + squareHeight);
            Console.Write('└' + string.Empty.PadLeft(squareWidth, '─') + '┘');

            for (int i = 0; i < squareHeight - 1; i++)
            {
                Console.SetCursorPosition(squareLeft, squareTop + 1 + i);
                Console.Write('│');
                Console.SetCursorPosition(squareLeft + squareWidth + 1, squareTop + 1 + i);
                Console.Write('│');
            }

            Console.SetCursorPosition(squareLeft + 1 + squareWidth / 2, squareTop + 1);
            Console.Write('N');
            Console.SetCursorPosition(squareLeft + 1 + squareWidth / 2, squareTop + squareHeight - 1);
            Console.Write('S');
            Console.SetCursorPosition(squareLeft + 1, squareTop + squareHeight/2);
            Console.Write('W');
            Console.SetCursorPosition(squareLeft + squareWidth, squareTop + squareHeight / 2);
            Console.Write('E');
            Console.SetCursorPosition(0, 15);
            currentSpace = 0;
        }