示例#1
0
文件: Program.cs 项目: paulbatum/18xx
        private static IGameAction PromptUser(PendingAction pendingAction)
        {
            int optionIndex = -1;

            while (true)
            {
                Console.WriteLine();
                Console.Write($"{pendingAction.ActivePlayer.Name}>");

                var input = Console.ReadLine();

                if(pendingAction.Choices.OfType<PassChoice>().Any() && input.ToLower() == "pass")
                    return new PlayerPassAction(LastAction, pendingAction.ActivePlayer);

                if (input.ToLower() == "undo" && LastAction != null)
                    return LastAction.Parent;

                if (int.TryParse(input, out optionIndex) && optionIndex >= 0 && optionIndex < pendingAction.Choices.Count)
                {
                    var choice = pendingAction.Choices[optionIndex];
                    Console.WriteLine("You picked: " + choice.Description);
                    return GetActionForChoice(pendingAction.ActivePlayer, choice);
                }
                else
                {
                    Console.WriteLine("Unexpected input!");
                }
            }
        }
示例#2
0
文件: Program.cs 项目: paulbatum/18xx
        private static void PrintState(GameState state, PendingAction pendingAction)
        {
            Console.Clear();

            Console.WriteLine($"Current Round: {state.Round.Description}");

            Console.WriteLine();
            Console.WriteLine("Players:");
            foreach (var p in state.Game.Players)
            {
                if (p == pendingAction.ActivePlayer)
                    Console.ForegroundColor = ConsoleColor.Yellow;

                var playerState = state.GetPlayerState(p);
                var privates = string.Join(", ", playerState.PrivateCompanies.Select(x => x.Name));
                var biddingPower = playerState.PrivateCompanies.Sum(x => x.Value) + playerState.Money;
                Console.WriteLine($"{p.Name.PadRight(10, ' ')} Cash: {playerState.Money}\t Bidding Power: {biddingPower}\t Privates: {privates} ");

                Console.ResetColor();
            }

            var privateAuctionRound = state.Round as PrivateAuctionRound;

            if(privateAuctionRound != null)
            {
                Console.WriteLine();
                Console.WriteLine($"Seed money: {privateAuctionRound.SeedMoney}");

                var currentAuction = (state.Round as PrivateAuctionRound)?.CurrentAuction;
                if (currentAuction != null)
                {
                    Console.WriteLine($"Current Auction: {currentAuction.Selection.Name}");
                    Console.WriteLine($"High bid: {currentAuction.HighBid} ({currentAuction.HighBidder.Name})");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Select an action - pass, undo, or pick a number:");
            foreach (var c in pendingAction.Choices)
            {
                Console.WriteLine($"{pendingAction.Choices.IndexOf(c)}. {c.Description}");
            }
        }