Exemple #1
0
 static void DrawBox(int x, int y, int width, int height)
 {
     using (new ConsoleColour(Next()))
     {
         ConsoleDrawing.DrawBoxSingle(x, y, width, height);
     }
 }
Exemple #2
0
        private string Query(string prompt, ConsoleColor promptColour = ConsoleColor.Yellow)
        {
            SetPrompt(prompt, promptColour);
            ConsoleDrawing.BlankRegion(2, Console.WindowHeight - 2, Console.WindowWidth - 3, 1);
            Console.SetCursorPosition(2, Console.WindowHeight - 2);
            Console.Write(">");
            var result = Console.ReadLine();

            return(result);
        }
Exemple #3
0
        private string QueryBox(string prompt)
        {
            var width   = prompt.Length + 4;
            var height  = 4;
            var offsetX = (Console.WindowWidth - width) / 2;
            var offSetY = (Console.WindowHeight - height) / 2;

            ConsoleDrawing.DrawBoxDouble(offsetX, offSetY, width, height);
            Console.SetCursorPosition(offsetX + 2, offSetY + 1);
            Console.Write(prompt);
            Console.SetCursorPosition(offsetX + 2, offSetY + 2);
            return(Console.ReadLine());
        }
Exemple #4
0
        private void ClearAndDrawFrame()
        {
            Console.Clear();
            var width  = Console.WindowWidth;
            var height = Console.WindowHeight;

            ConsoleDrawing.DrawBoxDouble(0, 0, width, height);
            ConsoleDrawing.WriteAt('╠', 0, height - 3);
            ConsoleDrawing.WriteAt('╠', 0, height - 5);
            ConsoleDrawing.WriteAt('╣', width - 1, height - 3);
            ConsoleDrawing.WriteAt('╣', width - 1, height - 5);
            ConsoleDrawing.DrawLineX('═', 1, height - 3, width - 2);
            ConsoleDrawing.DrawLineX('═', 1, height - 5, width - 2);
        }
Exemple #5
0
        private void PrintPlayerTerse(Player p)
        {
            var noblesTerse = string.Join(", ", p.Nobles.Select(n => n.Name).ToArray());
            var s           = p.Nobles.Count == 1 ? "" : "s";

            if (noblesTerse != string.Empty)
            {
                noblesTerse = $", noble{s} {noblesTerse}";
            }
            ConsoleDrawing.WriteAt($"{p.Name} ({p.VictoryPoints}){noblesTerse}", 2, Console.CursorTop);
            Console.WriteLine();
            Console.SetCursorPosition(2, Console.CursorTop);

            PrintTokenPoolShortWithColours(p.Bonuses, ""); Console.WriteLine();
            Console.SetCursorPosition(2, Console.CursorTop);
            PrintTokenPoolShortWithColoursAsNumers(p.Purse, ""); Console.WriteLine();
        }
Exemple #6
0
 private static void SetPrompt(string prompt, ConsoleColor promptColour = ConsoleColor.Yellow)
 {
     ConsoleDrawing.BlankRegion(2, Console.WindowHeight - 4, Console.WindowWidth - 3, 1);
     Console.SetCursorPosition(2, Console.WindowHeight - 4);
     using (new ConsoleColour(promptColour)) Console.Write(prompt);
 }
Exemple #7
0
        private IAction GetActionFromInput(string input, GameState state)
        {
            var i = input.ToLowerInvariant().Trim();

            if (i.StartsWith("h"))
            {
                var messages = new string[]
                { "Commands: refer to cards buy their tier and index, e.g. '1-2' for tier 1, 2nd card."
                  , "    t: take tokens, e.g. 't ugb' for take blUe, Green, Black."
                  , "    b: buy card. e.g. 'b 1-2', or 'b res' to buy a reserved card (choice made for you if you have more than one)."
                  , "    r: reserve card. e.g. 'r 1-2', or just 'r 1' to reserve a random face down card from tier 1."
                  , "Instruments:"
                  , "    *: you can afford this card."
                  , "    ·: you can almost afford this card." };

                ConsoleDrawing.MessageBox(messages);
                Console.ReadKey();
                return(null);
            }

            if (i.StartsWith("t"))
            {
                var   codes          = i.Substring(1);
                var   tokens         = TokenPoolFromInput(codes);
                IPool tokensToReturn = new Pool();
                var   commaIndex     = codes.IndexOf(',');
                if (commaIndex != -1)
                {
                    tokensToReturn = TokenPoolFromInput(codes.Substring(commaIndex + 1));
                }
                return(new TakeTokens(tokens, tokensToReturn));
            }
            ;

            if (i.StartsWith("b"))
            {
                var args = i.Substring(1).Trim();
                if (args.StartsWith("res"))
                {
                    var resCard = state.CurrentPlayer.ReservedCards.OrderByDescending(c => c.VictoryPoints).FirstOrDefault(c => BuyCard.CanAffordCard(state.CurrentPlayer, c));
                    if (resCard == null)
                    {
                        throw new ArgumentException("You can't afford any of your reserved cards.");
                    }
                    var resPayment = BuyCard.CreateDefaultPaymentOrNull(state.CurrentPlayer, resCard);
                    if (resPayment == null)
                    {
                        throw new ArgumentException("You cannot afford this card or did not specify sufficient payment.");
                    }
                    return(new BuyCard(resCard, resPayment));
                }
                if (args[1] != '-')
                {
                    throw new ArgumentException($"Syntax error. Usage: 'b 1-2' for buying the second card in tier one.");
                }
                var tier      = int.Parse(args[0].ToString());
                var cardIndex = int.Parse(args[2].ToString());
                var card      = state.Tiers.Single(t => t.Tier == tier).ColumnSlots[cardIndex];
                if (card == null)
                {
                    throw new ArgumentException("There's no card in that slot. The tier {tier} deck has been exhasted.");
                }
                var payment = args.Length > 3 ? TokenPoolFromInput(args.Substring(3)) : BuyCard.CreateDefaultPaymentOrNull(state.CurrentPlayer, card);
                if (payment == null)
                {
                    throw new ArgumentException("You cannot afford this card or did not specify sufficient payment.");
                }
                return(new BuyCard(card, payment));
            }

            if (i.StartsWith("r"))
            {
                var   args           = i.Substring(1).Trim();
                var   tier           = int.Parse(args[0].ToString());
                IPool tokensToReturn = new Pool();
                var   commaIndex     = args.IndexOf(',');
                if (commaIndex != -1)
                {
                    tokensToReturn = TokenPoolFromInput(args.Substring(commaIndex + 1));
                }
                var colourToReturn = tokensToReturn.Colours().Cast <TokenColour?>().SingleOrDefault();
                if (args.Length == 1)
                {
                    return(new ReserveFaceDownCard(tier, colourToReturn));
                }
                if (args[1] != '-')
                {
                    throw new ArgumentException($"Syntax error. Usage: 'r 1-2' for reserving the second card in tier one.");
                }
                var cardIndex = int.Parse(args[2].ToString());
                var card      = state.Tiers.Single(t => t.Tier == tier).ColumnSlots[cardIndex];
                return(new ReserveCard(card, colourToReturn));
            }

            throw new NotImplementedException("Don't know that one.");
        }